From 12a040eb8424c9745f14bd9c28775cba4ce82b9d Mon Sep 17 00:00:00 2001 From: zhaocheng <578322713@qq.com> Date: Fri, 6 Dec 2019 16:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9F=AD=E4=BF=A1=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E6=8E=A5=E5=8F=A3=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=B7=A8=E5=9F=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/controllers/ApiController.php | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/frontend/controllers/ApiController.php b/frontend/controllers/ApiController.php index 910f20f..c101e18 100644 --- a/frontend/controllers/ApiController.php +++ b/frontend/controllers/ApiController.php @@ -835,11 +835,47 @@ class ApiController extends \yii\web\Controller return $result; } + /** + * 短信验证码 + * @return array + */ + public function actionSmsVerifyCode(){ + header("Access-Control-Allow-Origin: *"); + header("Access-Control-Allow-Methods: POST"); + header("Access-Control-Allow-Headers: Content-Type, X-Requested-With, Cache-Control,Authorization,Beeba-Sign,Beeba-Timestamp"); + Yii::$app->response->format = Response::FORMAT_JSON; + $params = Yii::$app->request->post(); + if (!isset($params['mobile']) || $params['mobile'] == '') { + $result['success'] = false; + $result['msg'] = '手机号无效'; + return $result; + } + $code = MyLib::randomStr(6,true); + $url = 'http://user.banmacar.com/api/sms/single-send'; + $params['token'] = 'b0909511a91119876a0957ab95fe8c7c'; + $params['content'] = "【汇盈帮手】验证码是{$code}。如非本人操作,请忽略本短信"; + $ret = MyLib::Post(http_build_query($params), $url); + $ret = json_decode($ret, true); + if (isset($ret['code']) && $ret['code'] == 200) { + $result['code'] = -1; + $result['msg'] = '短信发送成功'; + $session = Yii::$app->session; + $session->set('hy_vcode_'.$params['mobile'], $code); + } else { + $result['success'] = false; + $result['msg'] = $ret['msg']; + } + return $result; + } + /** * 游客注册接口 * @return array */ public function actionRegister(){ + header("Access-Control-Allow-Origin: *"); + header("Access-Control-Allow-Methods: POST"); + header("Access-Control-Allow-Headers: Content-Type, X-Requested-With, Cache-Control,Authorization,Beeba-Sign,Beeba-Timestamp"); Yii::$app->response->format = Response::FORMAT_JSON; $request = Yii::$app->request; $result = array( @@ -847,6 +883,7 @@ class ApiController extends \yii\web\Controller 'msg' => '请求成功', ); $name = trim($request->post('name','')); + $code = trim($request->post('code','')); $mobile = trim($request->post('mobile','')); $user = UserT::findOne(['name' => $name, 'phone' => $mobile]); if($name == '' || !preg_match('/^1[345789]\d{9}$/', $mobile)){ @@ -854,6 +891,11 @@ class ApiController extends \yii\web\Controller $result['msg'] = '参数错误'; return $result; } + if($code == '' || Yii::$app->session->get('hy_vcode_'.$mobile) != $code){ + $result['code'] = -1; + $result['msg'] = '验证码错误'; + return $result; + } if($user) { $user->password = MyLib::hashPwd('123456',$user->salt); if(!$user->save()){ @@ -913,6 +955,7 @@ class ApiController extends \yii\web\Controller $result['code'] = -1; $result['msg'] = $e->getMessage(); } + Yii::$app->session->remove('hy_vcode_'.$mobile); } return $result; }