bianjunhui 1 vuosi sitten
vanhempi
commit
14245b8ff5
2 muutettua tiedostoa jossa 40 lisäystä ja 45 poistoa
  1. 35 41
      application/common/model/Assms.php
  2. 5 4
      application/job/Sendsms.php

+ 35 - 41
application/common/model/Assms.php

@@ -3,54 +3,48 @@
 namespace app\common\model;
 
 use think\Model;
-
-
 class Assms Extends Model
 {
 
     public function sendSms($data){
-        $url =$data['url'].'/app-api/raffle/getMessageAddCoupon';
-        $re = $this->httpPost($url,$data);
-        return json_decode($re,true);
+        $this->sendSmsClick($data['mobile'],$data['template_body']);
     }
-
-
-    public function httpPost($url,$data){
-        $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_POST, true); // 发送一个常规的Post请求
-        curl_setopt($curl, CURLOPT_POSTFIELDS,  $data); // Post提交的数据包
-        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
-        curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
-        $result = curl_exec($curl); // 执行操作
-        if (curl_errno($curl)) {
-            return 'Error POST'.curl_error($curl);
-        }
-        curl_close($curl); // 关键CURL会话
-        return $result; // 返回数据
-    }
-
-    public static function httpGet($url)
+    function sendSmsClick($phone,$template_body)
     {
-        // 初始化cURL会话
-        $ch = curl_init();
-// 设置cURL选项
-        curl_setopt($ch, CURLOPT_URL, $url); // 你要访问的URL
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 将curl_exec()获取的信息以字符串返回,而不是直接输出
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//curl 取消 ssl 检查
-// 执行cURL会话
-        $response = curl_exec($ch);
-// 检查是否有错误发生
-        if(curl_errno($ch)){
-            echo 'cURL error: ' . curl_error($ch);
+        $accessKeyId =Mage::getStoreConfig('smsbjh/ident_custom2/clickappid');
+        $accessKeySecret =  Mage::getStoreConfig('smsbjh/ident_custom2/clickAppSecret');
+        // Configure HTTP basic authorization: BasicAuth
+        $config = \ClickSend\Configuration::getDefaultConfiguration()
+            ->setUsername($accessKeyId)
+            ->setPassword($accessKeySecret);
+
+        $apiInstance = new \ClickSend\Api\SMSApi(new GuzzleHttp\Client(),$config);
+        $msg = new \ClickSend\Model\SmsMessage();
+        $msg->setBody($template_body);
+        $msg->setTo($phone);
+        $msg->setSource("sdk");
+
+        $sms_messages = new \ClickSend\Model\SmsMessageCollection();
+        $sms_messages->setMessages([$msg]);
+        // print_r(json_decode($var,true));
+        $result=false;
+        try {
+            $result = $apiInstance->smsSendPost($sms_messages);
+
+            $result=json_decode($result,true);
+
+            if($result['http_code']==200){
+                $result=$result['data']['messages'][0];
+                if($result['status']!='SUCCESS'){
+                    $result=false;
+                }
+            }else{
+                $result=false;
+            }
+        } catch (Exception $e) {
+            echo 'Exception when calling SMSApi->smsSendPost: ', $e->getMessage(), PHP_EOL;
         }
-// 关闭cURL会话
-        curl_close($ch);
-// 打印响应内容
-        return $response;
+        return $result;
     }
 
 }

+ 5 - 4
application/job/Sendsms.php

@@ -7,7 +7,7 @@
 
 namespace app\job;
 use think\queue\Job;
-use app\common\model\Coupon;
+use app\common\model\Assms;
 use think\Db;
 class Sendsms
 {
@@ -20,11 +20,12 @@ class Sendsms
         }else{
             $isJobDone = false;
         }
-        $data['addtime']=date('Y-m-d H:i:s',time());
+        $new['uptime']=time();
+        $new['status']=3;
         if ($isJobDone) {
             //如果任务执行成功, 删除任务
-            $data['code']=$result['code'];
-            Db::name('send_coupon_log')->insertGetId($data);
+            $log_id =$data['log_id'];
+            Db::name('sms_log')->where($log_id)->update($new);
             $job->delete(); // 删除任务
         }else{
             if ($job->attempts() > 3) {