From e4daff1be8fbc92f5e0bdbeaeb19f721a5a13d02 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 14 Jan 2020 09:52:37 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Base/Tool/TaskClient.class.php | 38 ++++++++++++++++ .../Common/Controller/SmsController.class.php | 1 + .../Controller/CommonController.class.php | 38 ++++++++-------- .../Mobile/Controller/SsgController.class.php | 43 ++++++++----------- .../Controller/UserController.class.php | 30 ++++++------- 5 files changed, 89 insertions(+), 61 deletions(-) create mode 100644 Application/Base/Tool/TaskClient.class.php 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; } /** From f6eb5d80080cdb7ac429f326586716d82298a40f Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 14 Jan 2020 16:29:36 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Base/Tool/TaskClient.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Application/Base/Tool/TaskClient.class.php b/Application/Base/Tool/TaskClient.class.php index b60fc4f45..59659a739 100644 --- a/Application/Base/Tool/TaskClient.class.php +++ b/Application/Base/Tool/TaskClient.class.php @@ -2,6 +2,8 @@ namespace Base\Tool; +use GuzzleHttp\Client; + class TaskClient { const SUCCESS = '0000'; From afa7aa8988fd24d017a9362a64cb99d943c22145 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 14 Jan 2020 16:32:56 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Base/Tool/TaskClient.class.php | 4 ++-- Application/Mobile/Controller/UserController.class.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Application/Base/Tool/TaskClient.class.php b/Application/Base/Tool/TaskClient.class.php index 59659a739..711593418 100644 --- a/Application/Base/Tool/TaskClient.class.php +++ b/Application/Base/Tool/TaskClient.class.php @@ -30,11 +30,11 @@ class TaskClient public function sendSms($mobile, $type = 'common') { - $result = $this->post('/message/sms-send', ['mobile' => $mobile, 'type' => $type]); + return $this->post('/message/sms-send', ['mobile' => $mobile, 'type' => $type]); } public function checkSms($mobile, $code) { - $result = $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]); + return $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]); } } \ No newline at end of file diff --git a/Application/Mobile/Controller/UserController.class.php b/Application/Mobile/Controller/UserController.class.php index a1f2fec42..4e9498243 100644 --- a/Application/Mobile/Controller/UserController.class.php +++ b/Application/Mobile/Controller/UserController.class.php @@ -696,7 +696,6 @@ class UserController extends BaseController exit; } $result = $this->telsafecode($account); - } /** From 828252cee9bee5a071ce604a53d0aeb3bf4b728a Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 14 Jan 2020 17:21:35 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E9=80=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/CommonController.class.php | 23 ++++++------- .../Mobile/Controller/SsgController.class.php | 22 ++++++------ .../Controller/UserController.class.php | 34 +++++++++++-------- Application/Mobile/View/User/forget.html | 2 +- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Application/Mobile/Controller/CommonController.class.php b/Application/Mobile/Controller/CommonController.class.php index bbece6e95..2422f594c 100644 --- a/Application/Mobile/Controller/CommonController.class.php +++ b/Application/Mobile/Controller/CommonController.class.php @@ -106,7 +106,9 @@ class CommonController extends BaseController { $gameId = $params['game_id'] ?? 0; #验证短信验证码 - $this->smsVerify($params['account'], $params['verify_code']); + if (!$this->smsVerify($params['account'], $params['verify_code'])) { + $this->respondError('验证失败'); + } $res = $this->doRegister($params['account'], $params['password'], $params['account'], $promoteId, 4, 2, $gameId); if(empty($res)){ @@ -127,7 +129,9 @@ class CommonController extends BaseController { if (empty($params)) { $this->respondError('基础信息不能为空'); } - $this->smsVerify($params['account'], $params['verify_code']); + if (!$this->smsVerify($params['account'], $params['verify_code'])) { + $this->respondError('验证失败'); + } //更新密码 $userApi = new MemberApi(); $userInfo = M("user", "tab_")->where("account = '".$params['account']."'")->find(); @@ -225,22 +229,15 @@ class CommonController extends BaseController { } } - public function smsVerify($phone = '' , $code = '', $type = 2){ + public function smsVerify($phone = '' , $code = '') + { $taskClient = new TaskClient(); $result = $taskClient->checkSms($phone, $code); $data = []; if ($result['code'] == TaskClient::SUCCESS) { - if($type == 1){ - $this->respondSuccess('正确'); - } else { - return true; - } + return true; } else { - if($type == 1){ - $this->respondError($result['message']); - } else { - return false; - } + return false; } } } diff --git a/Application/Mobile/Controller/SsgController.class.php b/Application/Mobile/Controller/SsgController.class.php index d1c80bccb..3f83552de 100644 --- a/Application/Mobile/Controller/SsgController.class.php +++ b/Application/Mobile/Controller/SsgController.class.php @@ -181,7 +181,9 @@ class SsgController extends BaseController { $this -> set_message(1001, "fail", "注册数据不能为空"); } #验证短信验证码 - $this -> sms_verify($user['account'], $user['code']); + if (!$this->sms_verify($user['account'], $user['code'])) { + $this->set_message(1000, "fail", '验证失败'); + } $res = $this -> doRegister($user['account'],$user['password'],$user['account'],$promoteId,4,2, $game_id); if(empty($res)){ @@ -201,7 +203,9 @@ class SsgController extends BaseController { if (empty($user)) { $this -> set_message(1001, "fail", "基础信息不能为空"); } - $this -> sms_verify($user['account'], $user['code']); + if (!$this->sms_verify($user['account'], $user['code'])) { + $this->set_message(1000, "fail", '验证失败'); + } //更新密码 $userApi = new MemberApi(); $userInfo = M("user","tab_")->where("account = '".$user['account']."'")->find(); @@ -441,21 +445,15 @@ class SsgController extends BaseController { return $res; } - public function sms_verify($phone = '' ,$code = '', $type = 2){ - + public function sms_verify($phone , $code) + { $taskClient = new TaskClient(); $result = $taskClient->checkSms($phone, $vcode); $data = []; if ($result['code'] == TaskClient::SUCCESS) { - if ($type == 2) { - return true; - } - $this->set_message(200, "success", "验证成功"); + return true; } else { - if ($type == 2) { - return false; - } - $this->set_message(1000, "fail", $result['message']); + return false; } } diff --git a/Application/Mobile/Controller/UserController.class.php b/Application/Mobile/Controller/UserController.class.php index 4e9498243..2a3a42acf 100644 --- a/Application/Mobile/Controller/UserController.class.php +++ b/Application/Mobile/Controller/UserController.class.php @@ -338,7 +338,9 @@ class UserController extends BaseController $password = $safeinfo['password']; $sex = $safeinfo['sex']; - $this->checksafecode($phone, $safecode, false); + if (!$this->checksafecode($phone, $safecode)) { + return $this->ajaxReturn(array('status' => 0, 'msg' => '验证失败')); + } /**是否开启ucenter**/ @@ -613,22 +615,17 @@ class UserController extends BaseController /** * 手机安全码验证 - * @param bool $flag true 用于直接异步请求 false 用于方法调用 - * @param [type] $vcode [description] */ - public function checksafecode($phone, $vcode, $flag = true) + public function checksafecode($phone, $code) { $taskClient = new TaskClient(); - $result = $taskClient->checkSms($phone, $vcode); + $result = $taskClient->checkSms($phone, $code); $data = []; - if ($result['code'] == TaskClient::SUCCESS) { - $data['status'] = 1; + if ($result && $result['code'] == TaskClient::SUCCESS) { + return true; } else { - $data['status'] = 0; + return false; } - $data['msg'] = $result['message']; - echo json_encode($data); - exit; } /** @@ -641,8 +638,11 @@ class UserController extends BaseController if (IS_POST) { $phone = $_POST['phone']; + $code = $_REQUEST['code']; - $this->checksafecode($phone, $_REQUEST['code'], false); + if (!$this->checksafecode($phone, $code)) { + return $this->ajaxReturn(array('status' => 0, 'msg' => '验证失败')); + } $this->success('验证成功', U('User/forget1', array('phone' => $phone))); @@ -658,8 +658,11 @@ class UserController extends BaseController if (IS_POST) { $new_pwd = $_REQUEST['new_pwd']; $u_uid['phone'] = $_REQUEST['phone']; + $code = $_REQUEST['code']; //验证短信验证码 - $this->checksafecode($u_uid['phone'], $_REQUEST['code'], false); + if (!$this->checksafecode($u_uid['phone'], $code)) { + $this->error("验证失败"); + } $result = M('user', 'tab_')->where($u_uid)->setField('password', think_ucenter_md5($new_pwd, UC_AUTH_KEY)); if ($result != false) { $this->success("修改成功", U('User/login')); @@ -875,7 +878,10 @@ class UserController extends BaseController if (IS_POST) { $code = I("post.scode"); $phone = I("post.phone"); - $this->checksafecode($phone, $code, false); + if (!$this->checksafecode($phone, $code)) { + echo json_encode(array('status' => 0, 'msg' => '验证失败')); + exit(); + } if (!$user['phone']) { $where['account'] = $phone; $where['phone'] = $phone; diff --git a/Application/Mobile/View/User/forget.html b/Application/Mobile/View/User/forget.html index 96be5cbae..401171c11 100644 --- a/Application/Mobile/View/User/forget.html +++ b/Application/Mobile/View/User/forget.html @@ -124,7 +124,7 @@ code:$("#code").val(), new_pwd:new_pwd }, - success:function(result){ + success:function(result) { if(result.status == 1){ pmsg.msg("修改成功"); setTimeout(function () { From 14e65c8314ebdb04368c04ee425573918435007b Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 14 Jan 2020 17:31:47 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E9=80=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Mobile/Controller/UserController.class.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Application/Mobile/Controller/UserController.class.php b/Application/Mobile/Controller/UserController.class.php index 2a3a42acf..bb06322fa 100644 --- a/Application/Mobile/Controller/UserController.class.php +++ b/Application/Mobile/Controller/UserController.class.php @@ -663,6 +663,11 @@ class UserController extends BaseController if (!$this->checksafecode($u_uid['phone'], $code)) { $this->error("验证失败"); } + $user = M('user', 'tab_')->where($u_uid)->find(); + if (!$user) { + $this->error("账号不存在"); + } + $result = M('user', 'tab_')->where($u_uid)->setField('password', think_ucenter_md5($new_pwd, UC_AUTH_KEY)); if ($result != false) { $this->success("修改成功", U('User/login')); From 9b3f105e5a4696695aad170c0bc67ad119c7a1d4 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 14 Jan 2020 18:04:54 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Mobile/Controller/SsgController.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Application/Mobile/Controller/SsgController.class.php b/Application/Mobile/Controller/SsgController.class.php index 3f83552de..b870df024 100644 --- a/Application/Mobile/Controller/SsgController.class.php +++ b/Application/Mobile/Controller/SsgController.class.php @@ -448,7 +448,7 @@ class SsgController extends BaseController { public function sms_verify($phone , $code) { $taskClient = new TaskClient(); - $result = $taskClient->checkSms($phone, $vcode); + $result = $taskClient->checkSms($phone, $code); $data = []; if ($result['code'] == TaskClient::SUCCESS) { return true;