Browse Source

2.1.2 短信接口更新

laiguoran 7 years ago
parent
commit
7bc0eb767f

+ 13 - 30
protected/class/sms.php

@@ -2,14 +2,12 @@
 
 class Sms
 {
-    private $api_url, $account, $password, $extno, $errorMsg;
+    private $api_url, $auth_key, $errorMsg;
 
-    function __construct($api_url, $account,$password,$extno)
+    function __construct($api_url, $auth_key)
     {
         $this->api_url = $api_url;
-        $this->account = $account;
-        $this->password = $password;
-        $this->extno = $extno;
+        $this->auth_key = $auth_key;
     }
 
     /**
@@ -19,38 +17,20 @@ class Sms
     public function sendSms($mobile, $code)
     {
         $send = array(
-            'action' => 'send',
-            'account' => $this->account,
-            'password' => $this->password,
+            'apikey' => $this->auth_key,
             'mobile' => $mobile,
-            'content' => $code,
-            'extno' => $this->extno
+            'text' => $code
         );
         $data = http_build_query($send);
-        $res = simplexml_load_string($this->_httpClient($this->api_url,$data));
+        $res = json_decode($this->_httpClient($this->api_url,$data));
         $resArr = $this->objectToArray($res);
-        $resultcode = !empty($resArr) ? explode('#@#',$resArr['resplist']['resp'])[2] : '';
-        if ($resultcode == '0') return true;
+        if (!empty($resArr) && $resArr["code"] == 0) return true;
         else {
-            if (empty($this->errorMsg)) $this->errorMsg = !empty($resultcode) ? $this->getErrorMsg($resultcode) : '未知错误';
+            if (empty($this->errorMsg)) $this->errorMsg = !empty($resArr["msg"]) ? $resArr["msg"] : '未知错误';
             return false;
         }
     }
 
-    function getErrorMsg($code){
-        $msg = '';
-        switch($code){
-            case 6: $msg = '错误代码:6,请联系我们客服';break;
-            case 10: $msg = '错误代码:10,请联系我们客服';break;
-            case 12: $msg = '检查接收短信手机号码格式是否正确';break;
-            case 15: $msg = '错误代码:15,请联系我们客服';break;
-            case 16: $msg = '一天时间内同一个手机号码不能太频繁接收短信';break;
-            case 17: $msg = '错误代码:17,请联系我们客服';break;
-            default : $msg = '错误代码:400,请联系我们客服';break;
-        }
-        return $msg;
-    }
-
     //对象转数组,使用get_object_vars返回对象属性组成的数组
     function objectToArray($array)
     {
@@ -74,10 +54,13 @@ class Sms
     {
         try {
             $ch = curl_init();
-            curl_setopt($ch, CURLOPT_URL,$api_url.$data);
+            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
+            curl_setopt($ch, CURLOPT_URL, $api_url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-            curl_setopt($ch, CURLOPT_HEADER, 0);
+            curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             $res = curl_exec($ch);
             curl_close($ch);
             return $res;

File diff suppressed because it is too large
+ 1 - 5
protected/config/sms.conf.php


+ 1 - 1
protected/controller/AppController.php

@@ -51,7 +51,7 @@ class AppController extends DooController {
         $this->modelconfig = new AConfig();
         $this->itemMeasureNum = new ItemMeasureNumpofper();
         $this->aconfig = new AConfig();
-        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_ACCOUNT, DOO::conf()->SMS_PASSWORD, DOO::conf()->SMS_EXTNO);
+        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
         $this->__hashids = new Hashids\Hashids('jlzfuserid', 8);
     }
 

+ 1 - 1
protected/controller/ClientController.php

@@ -89,7 +89,7 @@ class ClientController extends DooController
         $this->sign = new signn();
         $this->concern = new MeasureConcerner();
         $this->change = new Changes();
-        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_ACCOUNT, DOO::conf()->SMS_PASSWORD, DOO::conf()->SMS_EXTNO);
+        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
     }
 
     public function ClientSignin()

+ 1 - 1
protected/controller/RProjectController.php

@@ -45,7 +45,7 @@ class RProjectController extends DooController
         $this->att = new attachment();
         $this->sign = new Signn();
         $this->change = new Changes();
-        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_ACCOUNT, DOO::conf()->SMS_PASSWORD, DOO::conf()->SMS_EXTNO);
+        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->data['currChannle'] = 'r';
         $this->data['user'] = $this->profile->getProWithUid($this->auth->getUid());

+ 1 - 1
protected/controller/SignController.php

@@ -52,7 +52,7 @@ class SignController extends DooController
         $this->measureauditact = new MeasureauditAct();
         $this->sign = new Signn();
         $this->change = new Changes();
-        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_ACCOUNT, DOO::conf()->SMS_PASSWORD, DOO::conf()->SMS_EXTNO);
+        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->data['currChannle'] = 'sign';
         $this->data['user'] = $this->profile->getProWithUid($this->auth->getUid());

+ 1 - 1
protected/controller/UserController.php

@@ -56,7 +56,7 @@ class UserController extends DooController
         $this->numofperact = new NumofperAct();
         $this->user = new User();
         $this->ph = new PasswordHash(8, FALSE);
-        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_ACCOUNT, DOO::conf()->SMS_PASSWORD, DOO::conf()->SMS_EXTNO);
+        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
         $this->aconfig = new AConfig();
         $this->measureauditact = new MeasureauditAct();
         $this->sign = new signn();