diff --git a/Application/Base/Tool/TaskClient.class.php b/Application/Base/Tool/TaskClient.class.php new file mode 100644 index 000000000..b60fc4f45 --- /dev/null +++ b/Application/Base/Tool/TaskClient.class.php @@ -0,0 +1,38 @@ +client = new Client([ + 'base_uri' => C('TASK_URL'), + 'timeout' => 10.0, + ]); + } + + protected function post($uri, $data) + { + $response = $this->client->post($uri, [ + 'verify' => false, + 'form_params' => $data + ]); + $result = (string)$response->getBody(); + return json_decode($result, true); + } + + public function sendSms($mobile, $type = 'common') + { + $result = $this->post('/message/sms-send', ['mobile' => $mobile, 'type' => $type]); + } + + public function checkSms($mobile, $code) + { + $result = $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]); + } +} \ No newline at end of file diff --git a/Application/Common/Controller/SmsController.class.php b/Application/Common/Controller/SmsController.class.php index 79f544a24..65fc2ca03 100644 --- a/Application/Common/Controller/SmsController.class.php +++ b/Application/Common/Controller/SmsController.class.php @@ -1,5 +1,6 @@ setData($result['data'])->respondSuccess('发送成功'); + $phone = I('phone'); + $taskClient = new TaskClient(); + $result = $taskClient->sendSms($phone); + $data = []; + if ($result['code'] == TaskClient::SUCCESS) { + $this->respondSuccess('发送成功'); } else { $this->respondError('发送失败'); } } - public function smsVerify($phone="" , $code="", $type=2){ - - $result = R('Common/Sms/verify_sms_code', [$phone, $code, false]); - if($result['code'] == 200) { - if($type==1){ + public function smsVerify($phone = '' , $code = '', $type = 2){ + $taskClient = new TaskClient(); + $result = $taskClient->checkSms($phone, $code); + $data = []; + if ($result['code'] == TaskClient::SUCCESS) { + if($type == 1){ $this->respondSuccess('正确'); - }else{ + } else { return true; } } else { - switch ($result['code']) { - case 1021:{ - $this->respondError('验证码已失效,请重新获取'); - };break; - case 1022:{ - $this->respondError('验证码不正确,请重新输入'); - };break; - default: - $this->respondError($result['msg']); + if($type == 1){ + $this->respondError($result['message']); + } else { + return false; } } } diff --git a/Application/Mobile/Controller/SsgController.class.php b/Application/Mobile/Controller/SsgController.class.php index 73731885a..d1c80bccb 100644 --- a/Application/Mobile/Controller/SsgController.class.php +++ b/Application/Mobile/Controller/SsgController.class.php @@ -3,6 +3,7 @@ namespace Mobile\Controller; use Org\Ipa365SDK\Ipa365; use Org\WeixinSDK\Weixin; use User\Api\MemberApi; +use Base\Tool\TaskClient; use Think\Log; class SsgController extends BaseController { @@ -398,24 +399,24 @@ class SsgController extends BaseController { session("user_auth",null); redirect(U("ssg/login")); } + //发送验证码 public function sendPhoneCode() { - $phone = I("phone"); - $result = R('Common/Sms/send_sms_code', array($phone, 10, false)); - - if ($result['code'] == 200) { + $phone = I('phone'); + $taskClient = new TaskClient(); + $result = $taskClient->sendSms($phone); + $data = []; + if ($result['code'] == TaskClient::SUCCESS) { $data['status'] = 1; - $data['data'] = $result['data']; } else { $data['status'] = 0; } - - $data['msg'] = $result['msg']; - + $data['msg'] = $result['message']; echo json_encode($data); exit; } + public function timediffs($begin_time, $end_time) { if ($begin_time < $end_time) { $starttime = $begin_time; @@ -439,29 +440,23 @@ class SsgController extends BaseController { $res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs); return $res; } - public function sms_verify($phone="" ,$code="",$type=2){ - $result = R('Common/Sms/verify_sms_code',array($phone,$code,false)); + public function sms_verify($phone = '' ,$code = '', $type = 2){ - if($result['code']==200) { - if($type==1){ - $this->set_message(200,"success","正确"); - }else{ + $taskClient = new TaskClient(); + $result = $taskClient->checkSms($phone, $vcode); + $data = []; + if ($result['code'] == TaskClient::SUCCESS) { + if ($type == 2) { return true; } + $this->set_message(200, "success", "验证成功"); } else { - switch ($result['code']) { - case 1021:{ - $this->set_message(1010,"fail","验证码已失效,请重新获取"); - };break; - case 1022:{ - $this->set_message(1022,"fail","验证码不正确,请重新输入"); - };break; - default: - $this->set_message($result['code'],"fail",$result['msg']); + if ($type == 2) { + return false; } + $this->set_message(1000, "fail", $result['message']); } - } /** diff --git a/Application/Mobile/Controller/UserController.class.php b/Application/Mobile/Controller/UserController.class.php index dd57e2159..a1f2fec42 100644 --- a/Application/Mobile/Controller/UserController.class.php +++ b/Application/Mobile/Controller/UserController.class.php @@ -8,6 +8,7 @@ use Org\UcenterSDK\Ucservice; use User\Api\MemberApi; use Admin\Model\PointTypeModel; use Think\Log; +use Base\Tool\TaskClient; class UserController extends BaseController { @@ -577,17 +578,15 @@ class UserController extends BaseController */ public function telsafecode($phone = '', $delay = 10, $flag = true) { - $result = R('Common/Sms/send_sms_code', array($phone, $delay, false)); - - if ($result['code'] == 200) { + $taskClient = new TaskClient(); + $result = $taskClient->sendSms($phone); + $data = []; + if ($result['code'] == TaskClient::SUCCESS) { $data['status'] = 1; - $data['data'] = $result['data']; } else { $data['status'] = 0; } - - $data['msg'] = $result['msg']; - + $data['msg'] = $result['message']; echo json_encode($data); exit; } @@ -619,20 +618,17 @@ class UserController extends BaseController */ public function checksafecode($phone, $vcode, $flag = true) { - $result = R('Common/Sms/verify_sms_code', array($phone, $vcode, false)); - - if ($result['code'] == 200) { + $taskClient = new TaskClient(); + $result = $taskClient->checkSms($phone, $vcode); + $data = []; + if ($result['code'] == TaskClient::SUCCESS) { $data['status'] = 1; - if ($flag) { - echo json_encode($data); - exit; - } } else { $data['status'] = 0; - $data['msg'] = $result['msg']; - echo json_encode($data); - exit; } + $data['msg'] = $result['message']; + echo json_encode($data); + exit; } /**