1. Oauth (개방형 인증)는 사용자가 사용자 이름과 이름을 입력하지 않고도 웹사이트에 저장된 사용자의 개인 리소스(예: 사진, 동영상, 연락처 목록)에 타사 애플리케이션에 액세스할 수 있도록 허용하는 개방형 표준입니다. 제3자에게 제공된 비밀번호
키워드: appKey appSecret 토큰(토큰)
2.SSO인증
현지 휴대폰에 Weibo 클라이언트가 탑재되어 있는 경우 Weibo 클라이언트로 바로 이동하고 승인 버튼을 클릭하여 로그인하세요.
qq 타사 로그인은 Oauth2.0, 테스트 코드를 사용하여 구현됩니다.
아래 링크를 클릭하세요
https: //graph.qq. com/oauth2.0/authorize?resp//www.qingguow.cn/sso.php
특정 코드 sso.php 파일:
<?<span>php </span><span>//</span><span> qq登陆类</span><span>class</span><span> Sso{ </span><span>const</span> APP_ID="101334262"<span>; </span><span>const</span> APP_KEY="xxxxxxxxxxxxxxx"<span>; </span><span>//</span><span>初始化</span><span>public</span><span>static</span><span>function</span><span> init(){ </span><span>header</span>("content-type:text/html;charset=utf-8"<span>); } </span><span>//</span><span>主函数</span><span>public</span><span>static</span><span>function</span><span> main(){ </span><span>//</span><span>请求控制</span><span>$action</span>=<span>$_GET</span>['action'<span>]; </span><span>if</span>(!<span>empty</span>(<span>$action</span><span>)){ Sso</span>::<span>$action</span><span>(); </span><span>return</span><span>; } </span><span>$par</span> = 'grant_type=authorization_code' . '&client_id='.Sso::<span>APP_ID </span>. '&client_secret='.Sso::<span>APP_KEY </span>. '&code='.<span>$_REQUEST</span>['code'<span>] </span>. '&redirect_uri='.<span>urlencode</span>('http://www.qingguow.cn/sso.php'<span>); </span><span>$rec</span>=Sso::postUrlContents("https://graph.qq.com/oauth2.0/token",<span>$par</span><span>); </span><span>if</span>(<span>strpos</span>(<span>$rec</span>, 'access_token') !== <span>false</span><span>) { </span><span>parse_str</span>(<span>$rec</span>, <span>$accessToken</span><span>); </span><span>$openidJson</span>=Sso::getUrlContents("https://graph.qq.com/oauth2.0/me?callback=callback&access_token={<span>$accessToken</span>['access_token']}"<span>); </span><span>$openidJson</span>=<span>str_replace</span>("callback( ", "", <span>$openidJson</span><span>); </span><span>$openidJson</span>=<span>str_replace</span>(");", "", <span>$openidJson</span><span>); </span><span>$openidJson</span>=json_decode(<span>$openidJson</span>,<span>true</span><span>); </span><span>header</span>("location:sso.php?action=getQQinfo&openid={<span>$openidJson</span>['openid']}&access_token={<span>$accessToken</span>['access_token']}"<span>); } } </span><span>//</span><span>获取用户信息</span><span>public</span><span>static</span><span>function</span><span> getQQinfo(){ Sso</span>::<span>init(); </span><span>$openid</span>=<span>$_GET</span>['openid'<span>]; </span><span>$access_token</span>=<span>$_GET</span>['access_token'<span>]; </span><span>$userJson</span>=Sso::getUrlContents("https://graph.qq.com/user/get_user_info?openid={<span>$openid</span>}&access_token={<span>$access_token</span>}&oauth_c>APP_ID); <span>$user</span>=json_decode(<span>$userJson</span>,<span>true</span><span>); </span><span>print_r</span>(<span>$user</span><span>); } </span><span>//</span><span>get方式请求数据</span><span>public</span><span>static</span><span>function</span> getUrlContents(<span>$url</span><span>){ </span><span>$ch</span> =<span> curl_init(); curl_setopt(</span><span>$ch</span>, CURLOPT_SSL_VERIFYPEER, <span>FALSE</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_HEADER, <span>false</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_FOLLOWLOCATION, <span>true</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_URL, <span>$url</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_REFERER, <span>$url</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_RETURNTRANSFER, <span>TRUE</span><span>); </span><span>$result</span> = curl_exec(<span>$ch</span><span>); curl_close(</span><span>$ch</span><span>); </span><span>return</span><span>$result</span><span>; } </span><span>//</span><span>post请求数据</span><span>public</span><span>static</span><span>function</span> postUrlContents(<span>$url</span>,<span>$data</span> = <span>null</span><span>){ </span><span>$curl</span> =<span> curl_init(); curl_setopt(</span><span>$curl</span>, CURLOPT_URL, <span>$url</span><span>); curl_setopt(</span><span>$curl</span>, CURLOPT_SSL_VERIFYPEER, <span>FALSE</span><span>); curl_setopt(</span><span>$curl</span>, CURLOPT_SSL_VERIFYHOST, <span>FALSE</span><span>); </span><span>if</span> (!<span>empty</span>(<span>$data</span><span>)){ curl_setopt(</span><span>$curl</span>, CURLOPT_POST, 1<span>); curl_setopt(</span><span>$curl</span>, CURLOPT_POSTFIELDS, <span>$data</span><span>); } curl_setopt(</span><span>$curl</span>, CURLOPT_RETURNTRANSFER, 1<span>); </span><span>$output</span> = curl_exec(<span>$curl</span><span>); curl_close(</span><span>$curl</span><span>); </span><span>return</span><span>$output</span><span>; } } Sso</span>::main();
위에서는 oauth [PHP] oauth 콘텐츠를 포함한 Oauth 인증과 로컬 암호화에 대해 소개하고 있는데, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되길 바랍니다.