本文整理汇总了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: 登录异常
}
}