php中qq第三方登录演示,实现腾讯qq第三方登录
參考文檔鏈接:
文件名為:teng.htmlhtml?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
php文件名:<?php
header('Content-Type:text/html;charset=utf-8');
//getToken
$url?=?'https://graph.qq.com/oauth2.0/token?client_id=101218540'
.'&client_secret=034ab318017483c1c2c90cee1fa2dee9'
.'&redirect_uri=http://zhangsixia.bwphp.cn/tengxun.php'
.'&grant_type=authorization_code'
.'&code='.$_REQUEST['code'];
$info?=?file_get_contents($url);
$params?=?array();
//parse_str()?函數把查詢字符串解析到變量中
parse_str($info,?$params);
//print_r($params);die;
//獲取openid
$url1?=?"https://graph.qq.com/oauth2.0/me?access_token=".$params['access_token']."";
$info1?=?file_get_contents($url1);
//print_r($info1);die;
$str?=?substr($info1,9,-3);
//print_r($str);die;
$arr?=?json_decode($str,true);
//print_r($arr['openid']);die;
//獲取用戶信息
$url2?=?"https://graph.qq.com/user/get_user_info?access_token=".$params['access_token']."&oauth_consumer_key=101218540&openid=".$arr['openid']."";
$info2?=?file_get_contents($url2);
$data?=?json_decode($info2,true);
//print_r($data);
//判斷數據庫是否存在
@$aa?=?mysql_connect('','','');
$db?=?mysql_select_db('');
@$selSql?=?"select?userid,?token,?openid,?type?from?user_oauth?where?token=?'".$params['access_token']?."'?and?type?=?'qq'";
$selRe?=?mysql_query($selSql);
$num?=?mysql_num_rows($selRe);?//mysql_num_rows()?函數返回結果集中行的數目
if($num>0)
{
echo?"歡迎再次登陸!";exit;
}
$addSql?=?"insert?into?user_oauth?(token,openid,type)?values?('".$params['access_token']."','".$arr['openid']."','qq')";
//echo?$addSql;die;
$addRe=?mysql_query($addSql);
if($addRe)
{
echo?"登陸成功!";
print_r($data);
exit;
}
echo?"登陸失敗!";exit;
?>
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的php中qq第三方登录演示,实现腾讯qq第三方登录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java垃圾回收到老年代次数,Java垃
- 下一篇: php要掌握的内容,入门PHPer需要掌