Пример #1
0
 public function checkCode($attribute)
 {
     $code = EasyHelpers::getVerifyCode($this->userMobile);
     if ($code != $this->code) {
         $this->addError($attribute, '验证码不正确');
         return false;
     }
 }
Пример #2
0
 public function actionCheckcode()
 {
     $clientCode = \Yii::$app->request->post('code', '');
     if (!$clientCode) {
         return ['code' => 2, 'msg' => '验证码不能为空', 'data' => []];
     }
     $mobile = \Yii::$app->request->_get('mobile', NULL);
     if (!EasyHelpers::checkMobile($mobile)) {
         return ['code' => 2, 'msg' => '手机号码格式不正确', 'data' => []];
     }
     $code = EasyHelpers::getVerifyCode($mobile);
     if ($code != $clientCode) {
         return ['code' => 2, 'msg' => '验证码错误', 'data' => ['code' => $code]];
     }
     return ['code' => 0, 'msg' => '验证码正确', 'data' => ['code' => $code]];
 }
Пример #3
0
 /**
  * bind mobile api
  * @return type
  */
 public function actionBindmobile()
 {
     $request = \Yii::$app->request;
     $data['oldmobile'] = $request->_get('oldmobile', '');
     $data['oldcode'] = $request->_get('oldcode', '');
     $data['newmobile'] = $request->_get('newmobile', '');
     $data['newcode'] = $request->_get('newcode', '');
     $data['userId'] = $request->_get('userId', '');
     $data['usign'] = $request->_get('usign', '');
     if ($data['usign'] != EasyHelpers::encrypty($data['userId'], \Yii::$app->params['key'])) {
         return ['code' => 5, 'msg' => '非法数据'];
     }
     $Iduser = \common\models\User::findOne(['userId' => $data['userId']]);
     if ($Iduser && $data['oldmobile'] != $Iduser['userMobile']) {
         return ['code' => 6, 'msg' => '非法数据'];
     }
     $oldcode = EasyHelpers::getVerifyCode($data['oldmobile']);
     $newcode = EasyHelpers::getVerifyCode($data['newmobile']);
     if ($data['oldcode'] != $oldcode) {
         return ['code' => 1, 'msg' => '已绑定手机号验证码不正确'];
     }
     if ($data['newcode'] != $newcode) {
         return ['code' => 1, 'msg' => '新手机号验证码不正确'];
     }
     $user = \common\models\User::findByMobile($data['oldmobile']);
     $newuser = \common\models\User::findByMobile($data['newmobile']);
     if ($newuser) {
         ['code' => 1, 'msg' => '新手机号已经注册'];
     }
     if ($user) {
         $user->userMobile = $data['newmobile'];
         if ($user->save()) {
             return ['code' => 0, 'msg' => '手机绑定成功,请重新登录'];
         }
     }
     return ['code' => 1, 'msg' => '用户信息拉取失败'];
 }