| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | 
							- <?php
 
- /**
 
-  * 手机短信类
 
-  */
 
- namespace chuanglan;
 
- use app\common\model\SettingModel;
 
- use think\facade\Log;
 
- class Chuanglan
 
- {
 
-     /**
 
-      * 创蓝短信
 
-      * @param $mobile
 
-      * @param $smslog_param
 
-      * @return array
 
-      */
 
-     public function send($mobile, $smslog_param)
 
-     {
 
-         $config = SettingModel::getConfigValue(['sms_chuanglan_appkey', 'sms_chuanglan_secret']);
 
-         if (empty($config['sms_chuanglan_appkey']) || empty($config['sms_chuanglan_secret'])) {
 
-             return ['code' => 1, 'msg' => '请绑定模板参数'];
 
-         }
 
-         $url = 'http://smssh1.253.com/msg/send/json';
 
-         //创蓝接口参数
 
-         $postArr = [
 
-             'account'  => $config['sms_chuanglan_appkey'],
 
-             'password' => $config['sms_chuanglan_secret'],
 
-             'msg'      => $smslog_param['message'],
 
-             'phone'    => $mobile,
 
-             'report'   => 'true',
 
-         ];
 
-         //发送短信
 
-         $postFields = json_encode($postArr);
 
-         $ch         = curl_init();
 
-         curl_setopt($ch, CURLOPT_URL, $url);
 
-         curl_setopt($ch, CURLOPT_HTTPHEADER, [
 
-                 'Content-Type: application/json; charset=utf-8',   //json版本需要填写  Content-Type: application/json;
 
-             ]
 
-         );
 
-         curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
 
-         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
-         curl_setopt($ch, CURLOPT_POST, 1);
 
-         curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
 
-         curl_setopt($ch, CURLOPT_TIMEOUT, 60);
 
-         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 
-         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
-         $ret = curl_exec($ch);
 
-         curl_close($ch);
 
-         $rsp = json_decode($ret, true);
 
-         if ($rsp['code'] != 0) {
 
-             Log::error('短信发送失败:' . json_encode($rsp) . "。原始参数:" . json_encode($postArr));
 
-             return ['code' => 1, 'msg' => $rsp['errorMsg']];
 
-         } else {
 
-             return ['code' => 0];
 
-         }
 
-     }
 
- }
 
 
  |