コード例 #1
0
ファイル: RegisterAction.php プロジェクト: caidongyun/CS
 private function _register($res, $username, $password, $email, $mobile, $code, $isValidation)
 {
     if ($isValidation) {
         // 是否开启注册手机验证
         $isRegisterValidation = WebUtils::getDzPluginAppbymeAppConfig('mobcent_register_validation');
         if ($isRegisterValidation) {
             $checkInfo = UserUtils::checkMobileCode($res, $mobile, $code);
             if ($checkInfo['rs'] == 0) {
                 return $this->makeErrorInfo($res, $checkInfo['errcode']);
             }
         }
     }
     $regInfo = UserUtils::register($username, $password, $email);
     if ($regInfo['errcode']) {
         return $this->makeErrorInfo($res, $regInfo['message']);
     }
     if ($isValidation) {
         if ($isRegisterValidation) {
             // 注册完毕之后更新手机验证信息
             $updataArr = array('uid' => $regInfo['info']['uid']);
             AppbymeSendsms::updateMobile($mobile, $updataArr);
         }
     }
     $userInfo = AppbymeUserAccess::registerProcess($regInfo['info']['uid'], $password);
     $res['token'] = (string) $userInfo['token'];
     $res['secret'] = (string) $userInfo['secret'];
     $res['uid'] = (int) $regInfo['info']['uid'];
     return $res;
 }
コード例 #2
0
ファイル: LoginAction.php プロジェクト: caidongyun/CS
 private function _login($res, $username, $password, $mobile, $code, $isValidation)
 {
     global $_G;
     $username = rawurldecode($username);
     $password = rawurldecode($password);
     if ($username == MOBCENT_HACKER_USER && $password == MOBCENT_HACKER_PASSWORD) {
         $token = isset($_GET['accessToken']) ? $_GET['accessToken'] : '';
         $secret = isset($_GET['accessSecret']) ? $_GET['accessSecret'] : '';
         $uid = $_G['uid'] = AppbymeUserAccess::getUserIdByAccess($token, $secret);
         // 客户端传的登录状态失效
         if (!$uid) {
             return $this->makeErrorInfo($res, 'mobcent_login_status');
         }
         $result['member'] = getuserbyuid($uid);
         $_G['username'] = $result['member']['username'];
         // 把登录信息写入cookie中,并且更新登录的状态
         UserUtils::updateCookie($result['member'], $uid);
         // 需要整理token和secret再返回给客户端
         $userInfo = array('token' => $token, 'secret' => $secret);
     } else {
         $username = WebUtils::t($username);
         $logInfo = UserUtils::login($username, $password);
         if ($logInfo['errcode']) {
             UserUtils::delUserAccessByUsername($username);
             return $this->makeErrorInfo($res, $logInfo['message']);
         }
         if ($isValidation == 1) {
             // 是否开启了登录手机验证
             $isLoginValidation = WebUtils::getDzPluginAppbymeAppConfig('mobcent_login_validation');
             if ($isLoginValidation) {
                 $userMobileBind = AppbymeSendsms::getBindInfoByUid($_G['uid']);
                 if (!$userMobileBind) {
                     // 当前登录的用户没有绑定手机号码
                     if ($mobile == '' && $code == '') {
                         $res['isValidation'] = 1;
                         return $this->makeErrorInfo($res, '', array('noError' => 0, 'alert' => 0));
                     }
                     $checkInfo = UserUtils::checkMobileCode($res, $mobile, $code);
                     if ($checkInfo['rs'] == 0) {
                         return $this->makeErrorInfo($res, $checkInfo['errcode']);
                     }
                     $updataArr = array('uid' => $_G['uid']);
                     AppbymeSendsms::updateMobile($mobile, $updataArr);
                 }
             }
         }
         $userInfo = AppbymeUserAccess::loginProcess($_G['uid'], $password);
     }
     $userAvatar = UserUtils::getUserAvatar($_G['uid']);
     $res['isValidation'] = 0;
     $res['token'] = (string) $userInfo['token'];
     $res['secret'] = (string) $userInfo['secret'];
     $res['uid'] = (int) $_G['uid'];
     $res['avatar'] = (string) $userAvatar;
     $res['userName'] = (string) $_G['username'];
     return $res;
 }
コード例 #3
0
ファイル: UserUtils.php プロジェクト: caidongyun/CS
 public static function checkMobile($mobile)
 {
     return AppbymeSendsms::checkMobile($mobile);
 }
コード例 #4
0
ファイル: GetCodeAction.php プロジェクト: caidongyun/CS
 /**
  * 发送模板短信
  * @param to 手机号码集合,用英文逗号分开
  * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
  * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID
  *
  */
 private function sendTemplateSMS($res, $to, $datas, $tempId, $params)
 {
     extract($params);
     // 初始化REST SDK
     // global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion,$db;
     $rest = new RestSmsSDK($serverIP, $serverPort, $softVersion);
     $rest->setAccount($accountSid, $accountToken);
     $rest->setAppId($appId);
     if ($type == 'mobile') {
         //手机注册
         // 发送模板短信
         //echo "Sending TemplateSMS to $to <br/>";
         if (!$to) {
             // $res = WebUtils::makeErrorInfo_oldVersion($res, 'mobile_empty');
             return $this->makeErrorInfo($res, 'mobcent_mobile_empty');
         }
         if (!preg_match('/^1(3|5|8|7)\\d{9}$/', $to)) {
             //^(((d{2,3}))|(d{3}-))?13d{9}$
             // $res = WebUtils::makeErrorInfo_oldVersion($res,'mobile_error');
             return $this->makeErrorInfo($res, 'mobcent_mobile_error');
         }
         if ($action == 'register') {
             //注册验证手机号是否唯一
             // $mobileInfo = $db->get_one("SELECT * FROM pw_appbyme_sendsms WHERE mobile = " . S::sqlEscape($to) ." AND uid > 0");
             $bindInfo = UserUtils::checkMobile($to);
             if ($bindInfo) {
                 // $res = WebUtils::makeErrorInfo_oldVersion($res,'mobile_repeat');
                 return $this->makeErrorInfo($res, 'mobcent_mobile_repeat');
             }
         }
         $result = $rest->sendTemplateSMS($to, $datas, $tempId);
         if ($result == NULL) {
             // $res = WebUtils::makeErrorInfo_oldVersion($res,'result_error');
             return $this->makeErrorInfo($res, 'mobcent_result_error');
             //echo "result error!";
             //break;
         }
         if ($result->statusCode != 0) {
             $res['rs'] = 0;
             $res['head']['alert'] = 1;
             $res['errcode'] = $res['head']['errCode'] = $result->statusCode;
             $res['head']['errInfo'] = $result->statusMsg;
             //echo "error code :" . $result->statusCode . "<br>";
             //echo "error msg :" . $result->statusMsg . "<br>";
             //TODO 添加错误处理逻辑
             // return $this->makeErrorInfo($res, 'mobcent_result_error');
         } else {
             // echo "Sendind TemplateSMS success!<br/>";
             // 获取返回信息
             $smsmessage = $result->TemplateSMS;
             $time = strtotime($smsmessage->dateCreated);
             $inserArray = array('id' => '', 'mobile' => $to, 'code' => $datas[0], 'time' => $time, 'uid' => 0);
             $mobileInfo = AppbymeSendsms::getMobileUidInfo($to);
             if ($mobileInfo) {
                 $updataArr = array('time' => $time, 'code' => $datas[0]);
                 AppbymeSendsms::updateMobile($to, $updataArr);
             } else {
                 AppbymeSendsms::insertMobile($inserArray);
             }
         }
         return $res;
     } else {
         //pc注册
     }
 }