<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. * User: Mikkle * Email:776329498@qq.com * Date: 2016/12/28 * Time: 14:08 */ namespace app\api\controller; use com\Wechat; use think\Cache; use think\Model; use think\Session; class Auth extends Base { protected $isWechatBrowser = false; protected $scope = 'snsapi_base'; protected $uuid; protected $open_id; protected $member_info; protected $options; protected $isReg = false; protected $no_login = false; public function _initialize() { parent::_initialize(); // TODO: Change the autogenerated stub $user_agent = $this->request->server('HTTP_USER_AGENT'); if (! strpos($user_agent, 'MicroMessenger') === false ) $this->isWechatBrowser = true; //判斷提交方式和是否微信瀏覽器 if ($this->request->method() == 'GET' && $this->isWechatBrowser === true){ //未登錄 重新登錄 if (!$this->checkAuth()&& !$this->no_login ) $this->wxoauth(); $this->isLogin=true; //設置全局登錄 $this->loginGlobal(); if($this->isReg){ // if(!$this->checkUuidMobile()) $this->redirect('/index/WC_html_1/mainContainer.html#user/user_blind.html'); } } } /** * 設置全局登錄 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @return bool */ public function loginGlobal(){ if (!$this->open_id) return false; $member=model('base/user'); $member_info=$member->infoByOpenId($this->open_id); if (!$member_info){ $data=[ 'nickname'=>$this->member_info['nickname'], 'headimgurl'=>$this->member_info['headimgurl'], 'wechat_openid'=>$this->open_id, ]; $member->editData($data); $member_info=$member->infoByOpenId($this->open_id); $this->isReg = true; } $fans=model('base/WeFans'); $fans_info=$fans->infoByOpenId($this->open_id); $this->member_info['appid']=$this->getOptions(); if (!$fans_info){ $fans->allowField(true)->save($this->member_info); }else{ $fans->allowField(true)->save($this->member_info,['id' => $fans_info['id']]); } //設置全局登錄 微信瀏覽器登錄 if (!$this->checkLoginGlobal()) $this->setLoginGlobal($member_info,2); $this->uuid = $member_info['uuid']; } /** * 微信內頁登錄 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @return bool */ public function wxoauth() { if ($this->checkAuth()) return false; $code = $this->request->param('code'); if (Session::has('code','html5') && $code == Session::get('code','html5') && $code) return false; if (!$this->options) $this->getOptions(); $options = [ 'token'=>$this->options["token"], //填寫你設定的key 'appid'=>$this->options["appid"], //填寫高級調用功能的app id 'appsecret'=>$this->options["appsecret"] //填寫高級調用功能的密鑰 ]; Session::set('appid',$this->options["appid"],'html5'); $we_obj = new Wechat($options); if ($code) { $json = $we_obj->getOauthAccessToken(); if (!$json) { $this->redirect($this->request->baseUrl()); // die('獲取用戶授權失敗,請重新確認<a href="'.$this->request->baseUrl().'" >點擊重試</a>'); } $this->open_id = $json["openid"]; $access_token = $json['access_token']; Session::set('open_id',$this->open_id,'html5'); Session::set('code',$code,'html5'); $user_info = $we_obj->getUserInfo($this->open_id); $user_info['appid']=Session::get('appid','html5'); if ($user_info && !empty($user_info['nickname'])) { $this->member_info = $user_info; } elseif (strstr($json['scope'],'snsapi_userinfo')!==false) { $user_info = $we_obj->getOauthUserinfo($access_token,$this->open_id); $user_info['appid']=Session::get('appid','html5'); if ($user_info && !empty($user_info['nickname'])) { $this->member_info = $user_info; } else { return $this->open_id; } } if ($this->member_info) { Session::set('member_info',$this->member_info,'html5'); Session::set('open_id',$this->open_id,'html5'); Session::delete('wx_redirect','html5'); return $this->open_id; } $this->scope = 'snsapi_userinfo'; } if ($this->scope=='snsapi_base') { $url = $this->request->url(true); Session::set('wx_redirect',$url,'html5'); } else { $url =Session::get('wx_redirect','html5'); } if (!$url) { Session::delete('wx_redirect','html5'); die('獲取用戶授權失敗'); } $oauth_url = $we_obj->getOauthRedirect($url,"wxbase",$this->scope); header('Location:'.$oauth_url); die; } /** * 獲取微信Options 使用緩存 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @param int $appid * @return mixed */ public function getOptions( $appid = 1){ if(Cache::has('weOptions')){ $weOptions=Cache::get('weOptions'); }else{ $weOptions=model('we/We')->info($appid)->toarray(); Cache::set('weOptions',$weOptions,3600); } $this->options=$weOptions; $this->appid=$weOptions["appid"]; return $weOptions["appid"]; } /** * 判斷登錄是否成功 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @return bool */ public function checkAuth() { if (!Session::has('member_info','html5')&&!Session::has('open_id','html5')){ return false; }else{ $this->member_info = Session::get('member_info','html5'); $this->open_id = Session::get('open_id','html5'); $this->appid = Session::get('appid','html5'); if (!$this->options) $this->getOptions(); return true; } } } ~~~
                  <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>

                              哎呀哎呀视频在线观看