本文整理匯總了PHP中Connect::getOpenId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connect::getOpenId方法的具體用法?PHP Connect::getOpenId怎麽用?PHP Connect::getOpenId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Connect
的用法示例。
在下文中一共展示了Connect::getOpenId方法的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());
}
示例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');
}
}