Ejemplo n.º 1
0
 /**
  * 修改用户手机号新手机验证码.
  *
  * @access public
  * @return void
  * @author Liuping <*****@*****.**>
  */
 public function changeInfoPhonePhoneCode()
 {
     // 当前语系
     $lang = LANG_SET;
     $username = session('username');
     $prefix = I('mobilePrefix', '');
     $phone = I('phone', '');
     $newphone = $this->processMobile($prefix, $phone);
     // 处理后的手机号
     $model = new UserModel();
     $userInfo = $model->checkExistTel($prefix, $phone);
     if (empty($phone)) {
         $result['status'] = 0;
         $result['msg'] = L('CONTROLLER_MSG1');
     } elseif (!preg_match($this->_patternMobile, $newphone)) {
         $result['status'] = 0;
         $result['msg'] = L('CONTROLLER_MSG9');
     } elseif ($userInfo && $username != $userInfo['username']) {
         $result['status'] = 0;
         $result['msg'] = L('CONTROLLER_MSG10');
     } else {
         // 获取验证码
         $code = $this->getRandCode();
         $model = new UserCaptchaModel();
         $res = $model->checkSended($newphone, 1);
         if ($res) {
             // 重复发送
             $result['status'] = 8;
             $result['msg'] = '您的验证码已发送, 请不要重复发送';
             $this->ajaxReturn($result, 'json');
         }
         // 表中没有验证码, 手机验证码发送成功 commit, 失败 rollback
         $model->startTrans();
         $model->id = NULL;
         $model->type = 1;
         // 1 为手机, 2 为邮箱
         $model->account = $newphone;
         $model->code = $code;
         $model->createtime = time();
         $res1 = $model->add();
         $conf = C('USER_CAPTCHA_INFO');
         // 验证码配置项
         $timeout = $conf['expire'] / 60;
         // 短信内容
         $tpl = ['zh-cn' => 'ApplicationUK:[%CODE%] is your verification code. This code will expire in %TIMEOUT% minutes. Please do not reply to this message', 'en-us' => 'ApplicationUK:[%CODE%] is your verification code. This code will expire in %TIMEOUT% minutes. Please do not reply to this message'];
         $_searches = ['%CODE%', '%TIMEOUT%'];
         $_replaces = [$code, $timeout];
         $content = isset($tpl[$lang]) ? $tpl[$lang] : $tpl['en-us'];
         // $content = str_replace('%CODE%', $code, $content);
         $content = str_replace($_searches, $_replaces, $content);
         $res = $this->sendSms($newphone, $content);
         $result = [];
         // 成功发送将验证码信息写入 user_captcha
         if ($res && $res1) {
             $model->commit();
             $result['status'] = 9;
             $result['msg'] = L('CONTROLLER_MSG100');
         } else {
             $model->rollback();
             $result['status'] = 8;
             $result['msg'] = L('CONTROLLER_MSG24');
         }
     }
     if (IS_AJAX) {
         $this->ajaxReturn($result, 'json');
     }
 }