<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ~~~ <?php /** * Created by PhpStorm. * Power by Mikkle * QQ:776329498 * Date: 2017/3/22 * Time: 13:25 */ namespace app\member\controller; use app\base\model\Member; use think\Loader; use think\Cache; class Login extends Base { protected $config = [ 'debug' => true,//是否是在開發中調試模式 'debug_app_key' => '************', //融云開發環境下的key 僅供測試使用 'debug_app_secret' => 'D5Y4lpfcl6', //融云開發環境下的SECRET 僅供測試使用 'app_key' => '', //融云生產環境下的key 'app_secret' => '', //融云生產環境下的SECRET ]; protected $app_key; protected $app_secret; public function _initialize() { parent::_initialize(); // TODO: Change the autogenerated stub if ($this->config['debug'] == true){ $this->app_key =$this->config['debug_app_key']; $this->app_secret=$this->config['debug_app_secret']; }else{ $this->app_key =$this->config['app_key']; $this->app_secret=$this->config['app_secret']; } } /** * 通過用戶名密碼獲取用戶信息及融云Token * Power by Mikkle * QQ:776329498 * @return \think\response\Json */ public function getToken(){ // 獲取用戶id $user=$this->getUid(); if ($user['code']!=1001){ return json($user); } $user = $user['data']; $user_info = $user->toArray(); // 獲取融云token $token=json_decode($this->getRongCloudToken($user['id'],$user['userid'])); if (isset($token->code)){ if ($token->code == 200){ if ($user_info['r_token'] != $token->token){ $user_info['r_token'] =$token->token; $user->update(['r_token'=>$token->token],['id'=>$user_info['id']]); } }else{ return json(self::showReturnCodeWithOutData(1031,'網絡錯誤')); } } return json(self::showReturnCode(1001,$user_info,'獲取成功')); } private function getUid(){ //數據庫字段 網頁字段轉換 $param = [ 'userid' => 'userid', 'userpwd' => 'userpwd', 'mobile' => 'mobile', ]; $param_data = $this->buildParam($param); if (empty($param_data['userid'])&&empty($param_data['mobile'])) return self::showReturnCodeWithOutData(1003); $check_login = $this->doModelAction($param_data, 'base/Member.login', 'base/Member', 'checkLogin'); if (!isset($check_login['code'])) $this->showReturnCodeWithSaveLog(1111); if ($check_login['code'] == 1001) { } return $check_login; } /** * 獲取融云Token * Power by Mikkle * QQ:776329498 * @param $user_id * @param $username * @param string $logo * @return mixed */ private function getRongCloudToken($user_id,$username,$logo=''){ $logo = empty($logo) ? 'http://www.rongcloud.cn/images/logo.png' : $logo; include_once( EXTEND_PATH.'/rongcloud/RongCloud.php'); $rong_cloud = new \RongCloud($this->app_key,$this->app_secret); $result = $rong_cloud->user()->getToken($user_id, $username ,$logo); return $result; } /** * 發送手機短信驗證碼 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @param bool|false $mobile * @return 出錯返回1003錯誤碼和錯誤詳情|返回錯誤碼 */ public function sendRegSms($mobile=false){ // if (!$this->request->isAjax() ) return $this->showReturnCodeWithOutData(1002); if(!$mobile) $mobile=$this->request->param('mobile'); if (empty($mobile)||!is_numeric($mobile)||strlen($mobile)!=11) return $this->showReturnCodeWithOutData(1003); //驗證手機號碼是否存在并且是唯一 if ($this->checkMobileExist($mobile)) return $this->showReturnCodeWithOutData(1004,'此手機已存在,請更換號碼或聯系管理員'); $data_mobile['mobile']=$mobile; if ( isset($result_mobile['code']) ) return $result_mobile; if(!$this->checkRegSms($mobile)) return $this->showReturnCodeWithOutData(1003,'請勿一分鐘內重復申請驗證碼'); $req=$this->sendSmsCode($mobile); if ($req===true){ return $this->showReturnCodeWithOutData(1001); }else{ return $this->showReturnCodeWithOutData(1003,$req); } } /** * 檢測手機驗證碼并獲取融云Token * Power by Mikkle * QQ:776329498 * @param bool|false $mobile * @param bool|false $code * @return 出錯返回1003錯誤碼和錯誤詳情|array */ public function regAction($mobile=false,$code=false,$userpwd = false){ // if (!$this->request->isAjax() ) return $this->showReturnCodeWithOutData(1002); //驗證手機號碼是否存在并且是唯一 if (empty($mobile)) $mobile=$this->request->param('mobile'); if (empty($code)) $code=$this->request->param('code'); if (empty($userpwd)) $userpwd=$this->request->param('userpwd'); $data_mobile=['mobile'=>$mobile,'code'=>$code,'userpwd'=>$userpwd]; $result_mobile=$this->validate($data_mobile,'base/Member.reg'); if ( true!==$result_mobile ) return $this->showReturnCodeWithOutData(1003,$result_mobile); if ($this->checkMobileExist($mobile)) return $this->showReturnCodeWithOutData(1004,'此手機已存在,請更換號碼或聯系管理員'); if (!$this->checkRegSms($mobile,$code)){ return $this->showReturnCodeWithOutData(1010,'請求的驗證碼錯誤!'); }else{ $reg_data = [ 'mobile'=>$mobile, 'userpwd'=>$userpwd, 'r_token'=>null, ]; $model_user = new Member(); $new_user = $model_user ->reg($reg_data); $user_info = $model_user->toArray(); // 獲取token $token=json_decode($this->getRongCloudToken($user_info['id'],$user_info['userid'])); if (isset($token->code)){ if ($token->code == 200){ if ($user_info['r_token'] != $token->token){ $user_info['r_token'] =$token->token; $new_user->update(['r_token'=>$token->token],['id'=>$user_info['id']]); } }else{ return json(self::showReturnCodeWithOutData(1031,'網絡錯誤')); } } return json(self::showReturnCode(1001,$user_info,'注冊成功')); } } /** * 判斷手機是否存在 * Power by Mikkle * QQ:776329498 * @param string $mobile * @return bool */ private function checkMobileExist($mobile=''){ $model = new Member(); $return = $model->checkMobileExist($mobile); return $return; } /** * Ucpaas短信接口 * Power by Mikkle * QQ:776329498 * @param bool|false $mobile * @return bool */ protected function sendSmsCode($mobile = false) { if (!$mobile) return false; $code = rand(10000, 99999); $templateId ='38484';//驗證碼模版 $req = controller('base/Ucpaas')->sendSms($mobile,$templateId,$code); if ($req === true) { $data_cache = [ 'mobile' => $mobile, 'code' => (string)$code, 'times' => time() + 60, ]; $this->setRegSmsCache($data_cache); return true; } else { return $req; } } /** * 檢測手機短信驗證碼 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @param $mobile * @param bool|false $code * @return bool */ protected function checkRegSms($mobile, $code = false) { if (!$mobile) return false; if ($code === false) { //判斷60秒以內是否重復發送 if (!Cache::has('sms_' . $mobile)) return true; if (Cache::get('sms_' . $mobile)['times'] > time()) { return false; } else { return true; } } else { //判斷驗證碼是否輸入正確 if (!Cache::has('sms_' . $mobile)) return false; if (Cache::get('sms_' . $mobile)['code'] == $code) { return true; } else { return false; } } } /** * 設置手機短息驗證碼緩存 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @param $data_cache */ protected function setRegSmsCache($data_cache) { Cache::set('sms_' . $data_cache['mobile'], $data_cache, 300); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看