<p align="justify">1.Oauth<span style="font-family: 宋体;">(开放授权)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方
<p align="justify">
<p align="justify">关键字:<span style="font-family: Calibri;">appKey appSecret token(<span style="font-family: 宋体;">令牌<span style="font-family: Calibri;">)
<p align="justify">
<p align="justify">2.SSO<span style="font-family: 宋体;">授权
<p align="justify">如果本地手机装有微博客户端,则直接跳转到微博客户端,只需点击授权按钮,就可以登陆了
<p align="justify">
<p align="justify">qq第三方登陆使用Oauth2.0实现,测试代码
<p align="justify">点击下面的连接
<p align="justify"><a href="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101334262&redirect_uri=http://www.qingguow.cn/sso.php" target="_blank">https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101334262&redirect_uri=http://www.qingguow.cn/sso.php
<p align="justify">
<p align="justify">具体代码sso.php文件:
<div class="cnblogs_code">
APP_ID="101334262" APP_KEY="xxxxxxxxxxxxxxx"
("content-type:text/html;charset=utf-8"
=['action'(!(:: </span><span style="color: #800080;">$par</span> = 'grant_type=authorization_code'
. '&client_id='.Sso::<span style="color: #000000;">APP_ID
</span>. '&client_secret='.Sso::<span style="color: #000000;">APP_KEY
</span>. '&code='.<span style="color: #800080;">$_REQUEST</span>['code'<span style="color: #000000;">]
</span>. '&redirect_uri='.<span style="color: #008080;">urlencode</span>('http://www.qingguow.cn/sso.php'<span style="color: #000000;">);
</span><span style="color: #800080;">$rec</span>=Sso::postUrlContents("https://graph.qq.com/oauth2.0/token",<span style="color: #800080;">$par</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">strpos</span>(<span style="color: #800080;">$rec</span>,'access_token') !== <span style="color: #0000ff;">false</span><span style="color: #000000;">) {
</span><span style="color: #008080;">parse_str</span>(<span style="color: #800080;">$rec</span>,<span style="color: #800080;">$accessToken</span><span style="color: #000000;">);
</span><span style="color: #800080;">$openidJson</span>=Sso::getUrlContents("https://graph.qq.com/oauth2.0/me?callback=callback&access_token={<span style="color: #800080;">$accessToken</span>['access_token']}"<span style="color: #000000;">);
</span><span style="color: #800080;">$openidJson</span>=<span style="color: #008080;">str_replace</span>("callback( ","",<span style="color: #800080;">$openidJson</span><span style="color: #000000;">);
</span><span style="color: #800080;">$openidJson</span>=<span style="color: #008080;">str_replace</span>(");",<span style="color: #800080;">$openidJson</span><span style="color: #000000;">);
</span><span style="color: #800080;">$openidJson</span>=json_decode(<span style="color: #800080;">$openidJson</span>,<span style="color: #0000ff;">true</span><span style="color: #000000;">);
</span><span style="color: #008080;">header</span>("location:sso.php?action=getQQinfo&openid={<span style="color: #800080;">$openidJson</span>['openid']}&access_token={<span style="color: #800080;">$accessToken</span>['access_token']}"<span style="color: #000000;">);
}
}
</span><span style="color: #008000;">//</span><span style="color: #008000;">获取用户信息</span>
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> getQQinfo(){
Sso</span>::<span style="color: #000000;">init();
</span><span style="color: #800080;">$openid</span>=<span style="color: #800080;">$_GET</span>['openid'<span style="color: #000000;">];
</span><span style="color: #800080;">$access_token</span>=<span style="color: #800080;">$_GET</span>['access_token'<span style="color: #000000;">];
</span><span style="color: #800080;">$userJson</span>=Sso::getUrlContents("https://graph.qq.com/user/get_user_info?openid={<span style="color: #800080;">$openid</span>}&access_token={<span style="color: #800080;">$access_token</span>}&oauth_consumer_key=".Sso::<span style="color: #000000;">APP_ID);
</span><span style="color: #800080;">$user</span>=json_decode(<span style="color: #800080;">$userJson</span>,<span style="color: #0000ff;">true</span><span style="color: #000000;">);
</span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$user</span><span style="color: #000000;">);
}
</span><span style="color: #008000;">//</span><span style="color: #008000;">get方式请求数据</span>
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">function</span> getUrlContents(<span style="color: #800080;">$url</span><span style="color: #000000;">){
</span><span style="color: #800080;">$ch</span> =<span style="color: #000000;"> curl_init();
curl_setopt(</span><span style="color: #800080;">$ch</span>,CURLOPT_SSL_VERIFYPEER,<span style="color: #0000ff;">FALSE</span><span style="color: #000000;">);
curl_setopt(</span><span style="color: #800080;">$ch</span>,CURLOPT_HEADER,<span style="color: #0000ff;">false</span><span style="color: #000000;">);
curl_setopt(</span><span style="color: #800080;">$ch</span>,CURLOPT_FOLLOWLOCATION,<span style="color: #0000ff;">true</span><span style="color: #000000;">);
curl_setopt(</span><span style="color: #800080;">$ch</span>,CURLOPT_URL,<span style="color: #800080;">$url</span><span style="color: #000000;">);
curl_setopt(</span><span style="color: #800080;">$ch</span>,CURLOPT_REFERER,CURLOPT_RETURNTRANSFER,<span style="color: #0000ff;">TRUE</span><span style="color: #000000;">);
</span><span style="color: #800080;">$result</span> = curl_exec(<span style="color: #800080;">$ch</span><span style="color: #000000;">);
curl_close(</span><span style="color: #800080;">$ch</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;
}
</span><span style="color: #008000;">//</span><span style="color: #008000;">post请求数据</span>
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">function</span> postUrlContents(<span style="color: #800080;">$url</span>,<span style="color: #800080;">$data</span> = <span style="color: #0000ff;">null</span><span style="color: #000000;">){
</span><span style="color: #800080;">$curl</span> =<span style="color: #000000;"> curl_init();
curl_setopt(</span><span style="color: #800080;">$curl</span>,<span style="color: #800080;">$url</span><span style="color: #000000;">);
curl_setopt(</span><span style="color: #800080;">$curl</span>,<span style="color: #0000ff;">FALSE</span><span style="color: #000000;">);
curl_setopt(</span><span style="color: #800080;">$curl</span>,CURLOPT_SSL_VERIFYHOST,<span style="color: #0000ff;">FALSE</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$data</span><span style="color: #000000;">)){
curl_setopt(</span><span style="color: #800080;">$curl</span>,CURLOPT_POST,1<span style="color: #000000;">);
curl_setopt(</span><span style="color: #800080;">$curl</span>,CURLOPT_POSTFIELDS,<span style="color: #800080;">$data</span><span style="color: #000000;">);
}
curl_setopt(</span><span style="color: #800080;">$curl</span>,1<span style="color: #000000;">);
</span><span style="color: #800080;">$output</span> = curl_exec(<span style="color: #800080;">$curl</span><span style="color: #000000;">);
curl_close(</span><span style="color: #800080;">$curl</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$output</span><span style="color: #000000;">;
}
}
Sso::main(); (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|