Home  >  Article  >  php教程  >  QQ联合登录代码片段

QQ联合登录代码片段

PHP中文网
PHP中文网Original
2016-05-25 16:58:171209browse

QQ联合登录代码片段,需下载SDK(下载地址:http://sznk.fcloud.store.qq.com/store_raw_download?buid=16821&uuid=8a0b8bcb43291bf901432e18ccd10015&fsname=qqConnect_Server_SDK-php_v2.1.zip)

//加载QQ登陆页面
public function getqicqAction()
{
$qc = new lib_login_qqlogin();//原本是 new QC() 为自动加载修改过的类名
$qc->qq_login();
}

//获取QQ信息并保存
public function qqloginAction()
{
//QQ用户信息
$qc = new lib_login_qqlogin();
$token = $qc->qq_callback();//获取token
$openid = $qc->get_openid();//获取open_id
$qc->set_keys_arr(array("access_token"=> $token,"openid"=> $openid));//使用token和open_id
$qq_info = $qc->get_user_info();//获取QQ用户信息

//使用QQ信息登录本网站
if(loadModel('member')->connectLogin($qq_info, $openid, 'qq_openid'))//网站自身QQ联合登录逻辑处理
{
echo &#39;<script stype="text/javascript">window.opener.location.reload();window.close();</script>&#39;;
}
else
{
echo &#39;<script stype="text/javascript">alert("登录失败");window.opener.location.reload();window.close();</script>&#39;;
}
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn