作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

短信

... ... @@ -50,18 +50,32 @@ class Sms extends Api
// $ret = Smslib::send($mobile, null, $event);
$ret = $this->getCode($mobile, null, $event);
if ($ret) {
$this->success(__('发送成功'),['code'=>$ret]);
$this->success(__('发送成功'));
} else {
$this->error(__('发送失败,请检查短信配置是否正确'));
$this->error($ret['msg']);
}
}
public function getCode($mobile, $code = null, $event = 'default'){
$code = is_null($code) ? mt_rand(1000, 9999) : $code;
$time = time();
$ip = request()->ip();
$sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]);
return $code;
$sms = \app\common\model\Sms::create([
'event' => $event,
'mobile' => $mobile,
'code' => $code,
'ip' => request()->ip(),
'createtime' => $time
]);
$ret = send_sms2([
'content' => "【帛芮定制】您的验证码是:" . $code . ",请尽快返回完成验证,请勿转载或泄露,谨防被骗。",//短信内容
'mobile' => $mobile,//手机号码
'tKey' => time(),
]);
$ret = json_decode($ret,true);
if($ret['code'] == 200){
return true;
}
$this->error($ret['msg']);
}
/**
... ... @@ -92,4 +106,30 @@ class Sms extends Api
return false;
}
}
/**
* post提交数据
*/
protected function httpPost($url, $date) { // 模拟提交数据函数
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($date)); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
curl_setopt($curl, CURLOPT_HEADER, true); //开启header
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8'
)); //类型为json
$result = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Error POST' . curl_error($curl);
}
curl_close($curl); // 关键CURL会话
return $result; // 返回数据
}
}
... ...
... ... @@ -425,3 +425,17 @@ if (!function_exists('guidv4')) {
return $guidv4;
}
}
if(!function_exists('send_sms2')) {
function send_sms2($data){
//todo 短信账号密码
require_once EXTEND_PATH . 'nsms/nsms2.php';
$url = "https://api.mix2.zthysms.com/v2/sendSms";
$username = config('site.sms_username');
$password = config('site.sms_password');
$sendAPI = new \sendAPI($url, $username, $password);
$sendAPI->data = $data;/*初始化数据包*/
$return = $sendAPI->sendSMS('POST');
return $return;
}
}
... ...
... ... @@ -255,7 +255,7 @@ class Cart extends Model
}
}else{
if(count($coupon['list']) > 0 && $coupon['list'][0]['isusable'] == '1'){
$coupon['user_coupon_id'] = $coupon['list'][0]['coupon']['id'];
$coupon['user_coupon_id'] = $coupon['list'][0]['id'];
$coupon['coupon_name'] = $coupon['list'][0]['coupon']['coupon_name'];
$coupon['coupon_price'] = $coupon['list'][0]['coupon']['coupon_price'];
}
... ...
... ... @@ -6,6 +6,12 @@ use think\Model;
class UserCoupon extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
/**
* 优惠券
*/
... ...
... ... @@ -24,7 +24,7 @@ return array (
'dictionary' => 'Dictionary',
'wechat' => '小程序配置',
'silk' => '织帛配置',
'example' => 'Example',
'sms' => '短信配置',
),
'mail_type' => '1',
'mail_smtp_host' => 'smtp.qq.com',
... ... @@ -57,4 +57,6 @@ return array (
'member_intro' => '<h1 class="firstTitle" style="padding: 0px; margin-top: 0.24rem; margin-bottom: 0.16rem; list-style: none; font-family: 微软雅黑, Arial; font-weight: 600; font-size: 0.22rem; color: rgb(0, 0, 0); line-height: 0.22rem; text-align: justify;"><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;会员级别共分四个等级,具体为:普通会员、铜牌会员、银牌会员、金牌会员,级别升降由动品网客服操作来实现。</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;"><br>一、 普通会员</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;"><img src="http://www.dpin100.com/images/upload/Image/rank_0(1).gif" width="58" height="58" align="middle" alt="" style="margin: 0px; padding: 0px; border-width: initial; border-style: none; list-style-type: none;">&nbsp;&nbsp;申请条件:任何人都可以免费注册成为动品网的普通会员 。</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">二、铜牌会员</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;"><img src="http://www.dpin100.com/images/upload/Image/rank_12(1).gif" width="60" height="60" align="middle" alt="" style="margin: 0px; padding: 0px; border-width: initial; border-style: none; list-style-type: none;">&nbsp; &nbsp;申请条件:一年内 一次性购买超过1000元或一年内累计购物超过2000元</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">特权:不定期为铜牌会员推出的特价活动</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;"><br>三、 银牌会员&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;"><img src="http://www.dpin100.com/images/upload/Image/rank_13.gif" width="60" height="60" align="middle" alt="" style="margin: 0px; padding: 0px; border-width: initial; border-style: none; list-style-type: none;">&nbsp;&nbsp;申请条件:一年内一次性购买超过2000元或一年内累计购物超过3000元</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;"><br>特权:<br>1、成为银牌会员&nbsp;一年内提供2次免邮费活动(限普通快递,顺丰和货到付款,特价商品等除外)<br>2、不定期为银牌会员推出的特价活动</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">四、 金牌会员</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;<img src="http://www.dpin100.com/images/upload/Image/rank_14(1).gif" width="60" height="60" align="middle" alt="" style="margin: 0px; padding: 0px; border-width: initial; border-style: none; list-style-type: none;">申请条件: 一年内一次性购买超过3000元或一年内累计购物超过5000元&nbsp;<br>&nbsp;<br>特权:<br>1、成为金牌会员一年内提供5次免邮费活动&nbsp;(限普通快递,顺丰和货到付款,特价商品等除外)<br>2、不定期为金牌会员推出的特价活动</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">&nbsp;</p><p style="margin-bottom: 0px; padding: 0px; border: none; list-style-type: none; line-height: 25px; color: rgb(64, 64, 64); font-family: ΢ź, Verdana, Arial; font-size: 15px; font-weight: 400; text-align: left;">注:<br>1、订单完成后需要一周时间完成会员升级或直接联系客服进行升级。<br>2、动品网可以在没有特殊通知的情况下自行变更本条款,并以网站公示为准。</p></h1>',
'return_goods_reason' => '收到商品损坏了
商品与描述不符',
'sms_username' => 'zhibo123',
'sms_password' => 'cxz307311',
);
\ No newline at end of file
... ...
<?php
date_default_timezone_set('PRC');//设置时区
/**
* 发送API
* demo仅供参考,demo最低运行环境PHP5.3
* 请确认开启PHP CURL 扩展
*/
class sendAPI {
public $data; //发送数据
public $timeout = 30; //超时
private $apiUrl; //发送地址
private $username; //用户名
private $password; //密码
function __construct($url, $username, $password) {
$this->apiUrl = $url;
$this->username = $username;
$this->password = $password;
}
private function httpGet() {
$url = $this->apiUrl . '?' . http_build_query($this->data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Error GET '.curl_error($curl);
}
curl_close($curl);
return $res;
}
private function httpPost(){ // 模拟提交数据函数
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $this->apiUrl); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($this->data)); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
curl_setopt($curl, CURLOPT_HEADER, false); //开启header
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8')); //类型为json
$result = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Error POST' . curl_error($curl);
}
curl_close($curl); // 关键CURL会话
return $result; // 返回数据
}
/**
* @param $type|提交类型 POST/GET
* @param $isTranscoding|是否需要转 $isTranscoding 是否需要转utf-8 默认 false
* @return mixed
*/
public function sendSMS($type, $isTranscoding = false) {
$this->data['content'] = $isTranscoding === true ? mb_convert_encoding($this->data['content'], "UTF-8") : $this->data['content'];
$this->data['username'] = $this->username;
$this->data['tKey'] = time();
$this->data['password'] = md5(md5($this->password) . $this->data['tKey']);
// dump($this->data);exit;
return $type == "POST" ? $this->httpPost() : $this->httpGet();
}
}
\ No newline at end of file
... ...