當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Connect::getToken方法代碼示例

本文整理匯總了PHP中Connect::getToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connect::getToken方法的具體用法?PHP Connect::getToken怎麽用?PHP Connect::getToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Connect的用法示例。


在下文中一共展示了Connect::getToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: callback

 /**
  * 處理callback
  */
 protected function callback()
 {
     //不在開啟的登陸方式內直接返回
     if (!$this->allowConnect($this->auth['type'])) {
         $this->response->redirect(Typecho_Common::url('/login', $this->options->index));
     }
     if (empty($this->auth['code'])) {
         $this->response->redirect($this->options->index);
     }
     $callback_url = Typecho_Common::url('/user/oauth?type=' . $this->auth['type'], $this->options->index);
     $this->auth['openid'] = '';
     require_once 'Connect.php';
     //換取access_token
     $this->auth['token'] = Connect::getToken($this->auth['type'], $callback_url, $this->auth['code']);
     if (empty($this->auth['token'])) {
         $this->response->redirect($this->options->index);
     }
     //獲取openid
     $this->auth['openid'] = Connect::getOpenId($this->auth['type']);
     if (empty($this->auth['openid'])) {
         $this->response->redirect($this->options->index);
     }
     //使用openid登錄
     $this->autoLogin($this->auth['openid'], $this->auth['type']);
     //獲取用戶昵稱
     $this->auth['nickname'] = Connect::getNickName($this->auth['type'], $this->auth['openid']);
     if (empty($this->auth['nickname'])) {
         $this->auth['nickname'] = '關注者' . substr(str_shuffle($this->auth['openid']), 0, 4);
     }
     Typecho_Cookie::set('__user_auth', serialize($this->auth));
     $this->response->redirect($this->___bindUrl());
 }
開發者ID:dccecc,項目名稱:typecho,代碼行數:35,代碼來源:Oauth.php

示例2: callback

 public function callback()
 {
     if (!isset($_SESSION)) {
         session_start();
         if (isset($_SESSION['__typecho_auth'])) {
             $this->auth = $_SESSION['__typecho_auth'];
         }
     }
     if ($this->request->isPost()) {
         $do = $this->request->get('do');
         if (!in_array($do, array('bind', 'reg'))) {
             $this->widget('Widget_Notice')->set(array('錯誤數據!'), 'error');
             $this->response->goBack();
         }
         if (!isset($this->auth['openid']) || !isset($this->auth['type'])) {
             $this->response->redirect($this->options->index);
         }
         $func = 'doCallback' . ucfirst($do);
         $this->{$func}();
         unset($_SESSION['__typecho_auth']);
         $this->response->redirect($this->options->index);
     }
     $options = TeConnect_Plugin::options();
     if (empty($this->auth)) {
         $this->auth['type'] = $this->request->get('type', '');
         $this->auth['code'] = $this->request->get('code', '');
         //不在開啟的登陸方式內直接返回
         if (!isset($options[$this->auth['type']])) {
             $this->response->redirect($this->options->index);
         }
         if (empty($this->auth['code'])) {
             $this->response->redirect($this->options->index);
         }
         $callback_url = Typecho_Common::url('/oauth_callback?type=' . $this->auth['type'], $this->options->index);
         $this->auth['openid'] = '';
         require_once 'Connect.php';
         //換取access_token
         $this->auth['token'] = Connect::getToken($this->auth['type'], $callback_url, $this->auth['code']);
         if (empty($this->auth['token'])) {
             $this->response->redirect($this->options->index);
         }
         //獲取openid
         $this->auth['openid'] = Connect::getOpenId($this->auth['type']);
         if (empty($this->auth['openid'])) {
             $this->response->redirect($this->options->index);
         }
         $this->auth['nickname'] = Connect::getNickName($this->auth['type'], $this->auth['openid']);
     }
     //已經登錄,重新綁定
     if ($this->user->hasLogin()) {
         /** 綁定用戶 */
         $this->bindUser($this->user->uid, $this->auth['openid'], $this->auth['type']);
         //提示綁定成功,並跳轉
         // add 跳轉提示
         $this->widget('Widget_Notice')->set(array('成功綁定賬號!'));
         $this->response->redirect($this->options->index);
     }
     //已經綁定,直接登錄
     $isConnect = $this->findConnectUser($this->auth['openid'], $this->auth['type']);
     if ($isConnect) {
         $this->useUidLogin($isConnect['uid']);
         // add 跳轉提示
         $this->widget('Widget_Notice')->set(array('已成功登陸!'));
         $this->response->redirect($this->options->index);
     }
     $custom = $this->options->plugin('TeConnect')->custom;
     if (!$custom && !empty($this->auth['nickname'])) {
         $dataStruct = array('screenName' => $this->auth['nickname'], 'created' => $this->options->gmtTime, 'group' => 'subscriber');
         $uid = $this->regConnectUser($dataStruct);
         if ($uid) {
             $this->widget('Widget_Notice')->set(array('已成功注冊並登陸!'));
         } else {
             $this->widget('Widget_Notice')->set(array('注冊用戶失敗!'), 'error');
         }
         $this->response->redirect($this->options->index);
     } else {
         if (!isset($_SESSION['__typecho_auth'])) {
             $_SESSION['__typecho_auth'] = $this->auth;
         }
         //未綁定,顯示界麵
         $this->render('callback.php');
     }
 }
開發者ID:jiangmuzi,項目名稱:TeConnect,代碼行數:83,代碼來源:Widget.php


注:本文中的Connect::getToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。