本文整理匯總了PHP中OAuth::openid方法的典型用法代碼示例。如果您正苦於以下問題:PHP OAuth::openid方法的具體用法?PHP OAuth::openid怎麽用?PHP OAuth::openid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類OAuth
的用法示例。
在下文中一共展示了OAuth::openid方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: tplSuccessCallback
/**
* 第三方登錄回調處理方法
*
* @param OAuth $client OAuth客戶端對象
*/
public function tplSuccessCallback($client)
{
$mTplogin = new UserThirdPartyLogin();
$id = $client->getId();
$key = $client->openid();
$result = '';
$session = Yii::$app->getSession();
$userAttrs = $client->getUserAttributes();
$userProfile = $client->getUserInfo();
$openid = $userAttrs[$key];
$data = ['type' => $id, 'open_id' => $openid, 'profile_info' => json_encode($userProfile)];
if (isset($userAttr['expire_in'])) {
$data['expire_time'] = $userAttr['expire_in'];
}
if ($session->has(UserBaseInfo::SESSION_KEY_USER)) {
$userOperateLog = new UserOperateLog();
$res = $this->thirdBind($client);
$logOperate = '第三方綁定標識';
$operateType = '第三方' . $id . '綁定';
if ($res) {
$userOperateLog->store($operateType, $logOperate, $openid);
echo $res;
die;
}
$userOperateLog->store($operateType, $logOperate, $openid, true);
return $this->redirect(Url::toRoute('user/third-bind'));
}
try {
$result = $mTplogin->checkBindByOpenid($openid, UserThirdPartyLogin::BIND_WEB_CHANNEL);
if (!$result) {
$this->setTplSessionToUser(['type' => $id, 'open_id' => $openid, 'profile' => $userProfile]);
/*
if ($userAr = $mTplogin->bind($data)) {
$userAr['profile'] = $userProfile;
$this->setTplSessionToUser($userAr);
} else {
// TODO: 綁定失敗
}
*/
} else {
if ($result === TRUE) {
$this->setTplSessionToUser(['type' => $id, 'open_id' => $openid, 'profile' => $userProfile]);
} else {
if (is_array($result)) {
$this->setTplSessionToUser(['type' => $id, 'open_id' => $openid, 'profile' => $userProfile]);
return;
}
//登錄狀態
$mUser = new UserBaseInfo();
if ($mUser->autoLoginById($result, true)) {
$this->redirect(Url::toRoute('ucenter/index'));
} else {
// XXX: key後麵可以去除“硬編碼”
if (isset($session['tpl_user'])) {
unset($session['tpl_user']);
}
$this->redirect(Url::toRoute('user/login'));
}
}
}
} catch (Exception $e) {
// TODO: 登錄異常
}
}