wesmiler 2 vuotta sitten
vanhempi
commit
800df5f1d5

+ 4 - 2
app/Helpers/common.php

@@ -2218,7 +2218,7 @@ if (!function_exists('httpRequest')) {
      * @return mixed
      * @return mixed
      * @author wesmiler
      * @author wesmiler
      */
      */
-    function httpRequest($url, $data = '', $type = 'post', $cookie = '', $timeout = 60, $header=[])
+    function httpRequest($url, $data = '', $type = 'post', $cookie = '', $timeout = 60, $header=[],$dataType='array')
     {
     {
         try {
         try {
             set_time_limit($timeout);
             set_time_limit($timeout);
@@ -2250,7 +2250,9 @@ if (!function_exists('httpRequest')) {
             $ret = curl_exec($ch);
             $ret = curl_exec($ch);
             $ret = trim($ret);
             $ret = trim($ret);
             curl_close($ch);
             curl_close($ch);
-//            var_dump($ret);
+            if($dataType != 'array'){
+                return $ret;
+            }
             if (!preg_match("/^{/", $ret)) {
             if (!preg_match("/^{/", $ret)) {
                 return ['code' => 'err', 'msg' => $ret];
                 return ['code' => 'err', 'msg' => $ret];
             }
             }

+ 13 - 18
app/Services/SmsService.php

@@ -51,7 +51,7 @@ class SmsService extends BaseService
     {
     {
         $cacheKey = "caches:sms:cx_{$mobile}:{$type}";
         $cacheKey = "caches:sms:cx_{$mobile}:{$type}";
         if(RedisService::get($cacheKey.'_lock')){
         if(RedisService::get($cacheKey.'_lock')){
-            $this->error = '2011';
+            $this->error = '1060';
             return false;
             return false;
         }
         }
 
 
@@ -71,25 +71,20 @@ class SmsService extends BaseService
         $content="【{$signName}】您的验证码是:{$code},请在10分钟内使用,请不要将验证码泄漏个他人。";//短信内容
         $content="【{$signName}】您的验证码是:{$code},请在10分钟内使用,请不要将验证码泄漏个他人。";//短信内容
         $content = iconv("UTF-8", "GBK", $content);
         $content = iconv("UTF-8", "GBK", $content);
         $url="{$apiUrl}/sms?action=send&password={$password}&extno={$extno}&mobile={$mobile}&account={$account}&content={$content}";
         $url="{$apiUrl}/sms?action=send&password={$password}&extno={$extno}&mobile={$mobile}&account={$account}&content={$content}";
-        $html = file_get_contents($url);
-
-        $runtime = new RuntimeOptions();
-        $runtime->maxIdleConns = 5;
-        $runtime->connectTimeout = 10000;
-        $runtime->readTimeout = 10000;
         try {
         try {
             // 复制代码运行请自行打印 API 的返回值
             // 复制代码运行请自行打印 API 的返回值
-            $response = httpRequest($url,'','get','',5);
+            $response = httpRequest($url,'','get','',5,[],'text');
              var_dump($response);
              var_dump($response);
-            $resultCode = $response->body->code;
-            if($resultCode == 'OK'){
-                $this->error = 2020;
-                RedisService::set($cacheKey,['code'=> $code,'mobile'=>$mobile,'bizId'=>$response->body->bizId,'date'=> date('Y-m-d H:i:s')], 600);
+            $response = simplexml_load_string($response);
+            $returnStatus = isset($response['returnstatus'])? $response['returnstatus'] : '';
+            var_dump($response);
+            if($returnStatus != 'Failed'){
+                $this->error = 1063;
+                RedisService::set($cacheKey,['code'=> $code,'mobile'=>$mobile,'result'=>$response,'date'=> date('Y-m-d H:i:s')], 600);
                 return true;
                 return true;
             }else{
             }else{
-                $error = isset($this->errors[$response->body->code])? $this->errors[$response->body->code] : '';
-                $this->error = $error? $error : '获取失败';
-                RedisService::set($cacheKey.'_fail', ['mobile'=> $mobile,'config'=>$config,'response'=>$response->body,'error'=>$this->error], 6 * 3600);
+                $this->error = 1059;
+                RedisService::set($cacheKey.'_fail', ['mobile'=> $mobile,'config'=>$config,'response'=>$response,'error'=>$this->error], 6 * 3600);
                 return false;
                 return false;
             }
             }
         } catch (TeaUnableRetryError  $e){
         } catch (TeaUnableRetryError  $e){
@@ -98,7 +93,7 @@ class SmsService extends BaseService
             RedisService::set($cacheKey.'_error', ['mobile'=> $mobile,'config'=>$config,'error'=>$e->getMessage()], 6 * 3600);
             RedisService::set($cacheKey.'_error', ['mobile'=> $mobile,'config'=>$config,'error'=>$e->getMessage()], 6 * 3600);
         }
         }
 
 
-        $this->error = 2021;
+        $this->error = 1059;
         return false;
         return false;
     }
     }
 
 
@@ -119,12 +114,12 @@ class SmsService extends BaseService
         $data = RedisService::get($cacheKey);
         $data = RedisService::get($cacheKey);
         $smsCode = isset($data['code'])? $data['code'] : '';
         $smsCode = isset($data['code'])? $data['code'] : '';
         if(empty($data) || empty($smsCode)){
         if(empty($data) || empty($smsCode)){
-            $this->error = '2012';
+            $this->error = '1061';
             return false;
             return false;
         }
         }
 
 
         if($smsCode != $code){
         if($smsCode != $code){
-            $this->error = '2013';
+            $this->error = '1062';
             return false;
             return false;
         }
         }
 
 

+ 7 - 0
resources/lang/en/api.php

@@ -56,6 +56,13 @@ return [
     '1053' => 'Please do not place duplicate orders',
     '1053' => 'Please do not place duplicate orders',
     '1054' => 'Please fill in your email address',
     '1054' => 'Please fill in your email address',
     '1055' => 'Please fill in your phone number',
     '1055' => 'Please fill in your phone number',
+    '1056' => 'The Chuangxin SMS interface is not configured',
+    '1058' => 'The phone number has been used',
+    '1059' => 'Mobile verification code sending failed',
+    '1060' => 'Mobile verification code sent frequently, please try again in 60 seconds',
+    '1061' => 'Mobile verification code has expired or is incorrect',
+    '1062' => 'Mobile verification code error',
+    '1063' => 'Mobile verification code sent successfully',
 
 
     // 登录注册
     // 登录注册
     '2001'=> 'Illegal or nonexistent account',
     '2001'=> 'Illegal or nonexistent account',

+ 6 - 0
resources/lang/zh-cn/api.php

@@ -57,6 +57,12 @@ return [
     '1055' => '请填写手机号码',
     '1055' => '请填写手机号码',
     '1056' => '创信短信接口未配置',
     '1056' => '创信短信接口未配置',
     '1057' => '请填写手机号码',
     '1057' => '请填写手机号码',
+    '1058' => '手机号码已被使用',
+    '1059' => '手机验证码发送失败',
+    '1060' => '手机验证码发送频繁,请60秒后重试',
+    '1061' => '手机验证码已失效或错误',
+    '1062' => '手机验证码错误',
+    '1063' => '手机验证码发送成功',
 
 
     // 登录注册
     // 登录注册
     '2001'=> '账号非法或未注册',
     '2001'=> '账号非法或未注册',