Rumah >pembangunan bahagian belakang >tutorial php >QQ第三方登录PHP
1.授权登录
http://openapi.qzone.qq.com/oauth/show?which=ConfirmPage&display=pc&response_type=code&client_id=101223150&redirect_uri=http://t.zy62.com/qqlogin.php
得到code
2.获取access_token
https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=101223150&redirect_uri=http://t.zy62.com/qqlogin.php&client_secret='换成你自己的'&code=7A94789A36833731F7DED5C170BDA4FC
返回结果:
access_token=72103010DD08905F8B171E4EF378B5CC&expires_in=7776000&refresh_token=53303C0A75719EED9E3CDF01C3476955
3.获取openid
https://graph.qq.com/oauth2.0/me?access_token=72103010DD08905F8B171E4EF378B5CC
返回结果:标准jsonp格式
callback( {"client_id":"101223150","openid":"9ECFD84190F7D5D40E013CF84D0979FF"} );
4.获取用户资料
https://graph.qq.com/user/get_user_info?access_token=72103010DD08905F8B171E4EF378B5CC&oauth_consumer_key=101223150&openid=9ECFD84190F7D5D40E013CF84D0979FF&format=json
参数: access_token,appid,openid
返回结果:
{ "ret": 0, "msg": "", "is_lost":0, "nickname": "yi.", "gender": "女", "province": "湖北", "city": "武汉", "year": "1994", "figureurl": "http:\/\/qzapp.qlogo.cn\/qzapp\/101223150\/9ECFD84190F7D5D40E013CF84D0979FF\/30", "figureurl_1": "http:\/\/qzapp.qlogo.cn\/qzapp\/101223150\/9ECFD84190F7D5D40E013CF84D0979FF\/50", "figureurl_2": "http:\/\/qzapp.qlogo.cn\/qzapp\/101223150\/9ECFD84190F7D5D40E013CF84D0979FF\/100", "figureurl_qq_1": "http:\/\/q.qlogo.cn\/qqapp\/101223150\/9ECFD84190F7D5D40E013CF84D0979FF\/40", "figureurl_qq_2": "http:\/\/q.qlogo.cn\/qqapp\/101223150\/9ECFD84190F7D5D40E013CF84D0979FF\/100", "is_yellow_vip": "0", "vip": "0", "yellow_vip_level": "0", "level": "0", "is_yellow_year_vip": "0" }
<?php//print_r($_GET);//exit('qqlogin');//1.获取code$code=$_GET['code'];//2.获取access_token$url='https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=101223150&redirect_uri=http://t.zy62.com/qqlogin.php&client_secret='换成你自己的'&code='.$code;$rs=file_get_contents($url);$arr=explode('&',$rs);//print_r($arr);//3获取openid$url='https://graph.qq.com/oauth2.0/me?'.$arr[0];$rs=file_get_contents($url);echo $rs;