首頁 >後端開發 >php教程 >QQ第三方登录PHP

QQ第三方登录PHP

WBOY
WBOY原創
2016-06-20 12:54:551190瀏覽

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;


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn