1.Oauth(Open License) is an open standard that allows a third-party app to access private resources (such as photos, videos, contact lists) stored by the user on a site without having to provide a user name and password to a third party
Keyword:appKey appsecret token ( token )
2.SSO Licensing
If the local phone has a microblogging client, then jump directly to the Weibo client, just click the authorization button, you can log in
QQ Third party login using Oauth2.0 implementation, test code
Click on the link below
https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101334262&redirect_uri=http:// www.qingguow.cn/sso.php
Specific code sso.php file:
<?PHP//QQ Landing Classclasssso{ConstApp_id= "101334262"; Constapp_key= "Xxxxxxxxxxxxxxx"; //Initialize Public Static functioninit () {Header("Content-type:text/html;charset=utf-8"); } //Main function Public Static functionMain () {//Request Control $action=$_get[' Action ']; if(!Empty($action) ) {Sso::$action(); return; } $par= ' Grant_type=authorization_code '. ' &client_id= '. Sso::app_id. ' &client_secret= '. Sso::App_key. ' &code= '.$_request[' Code '] . ' &redirect_uri= '.UrlEncode(' http://www.qingguow.cn/sso.php '); $rec=sso::p osturlcontents ("Https://graph.qq.com/oauth2.0/token",$par); if(Strpos($rec, ' Access_token ')!==false) { Parse_str($rec,$accessToken); $openidJson=sso::geturlcontents ("https://graph.qq.com/oauth2.0/me?callback=callback&access_token={$accessToken[' Access_token ']} "); $openidJson=Str_replace("Callback (", "",$openidJson); $openidJson=Str_replace(");", "",$openidJson); $openidJson=json_decode ($openidJson,true); Header("location:sso.php?action=getqqinfo&openid={$openidJson[' OpenID ']} &access_token={$accessToken[' Access_token ']} "); } } //Get user Information Public Static functionGetqqinfo () {Sso::init (); $openid=$_get[' OpenID ']; $access _token=$_get[' Access_token ']; $userJson=sso::geturlcontents ("https://graph.qq.com/user/get_user_info?openid={$openid}&access_token={$access _token}&oauth_consumer_key= ". Sso::app_id); $user=json_decode ($userJson,true); Print_r($user); } //Get method Request data Public Static functionGeturlcontents ($url){ $ch=Curl_init (); curl_setopt ($ch, Curlopt_ssl_verifypeer,FALSE); curl_setopt ($ch, Curlopt_header,false); curl_setopt ($ch, Curlopt_followlocation,true); curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_referer,$url); curl_setopt ($ch, Curlopt_returntransfer,TRUE); $result= Curl_exec ($ch); Curl_close ($ch); return $result; } //POST request Data Public Static functionPosturlcontents ($url,$data=NULL){ $curl=Curl_init (); curl_setopt ($curl, Curlopt_url,$url); curl_setopt ($curl, Curlopt_ssl_verifypeer,FALSE); curl_setopt ($curl, Curlopt_ssl_verifyhost,FALSE); if(!Empty($data) {curl_setopt ($curl, Curlopt_post, 1); curl_setopt ($curl, Curlopt_postfields,$data); } curl_setopt ($curl, Curlopt_returntransfer, 1); $output= Curl_exec ($curl); Curl_close ($curl); return $output; }}sso:: Main ();
[PHP] OAuth Authorization and local encryption