PHPOauth授權(quán)和本地加密的實現(xiàn)方法-創(chuàng)新互聯(lián)

本篇內(nèi)容主要講解“PHP Oauth授權(quán)和本地加密的實現(xiàn)方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“PHP Oauth授權(quán)和本地加密的實現(xiàn)方法”吧!

專注于為中小企業(yè)提供網(wǎng)站制作、成都網(wǎng)站制作服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)無為免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千多家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。

1.Oauth(開放授權(quán))是一個開放標準,允許用戶讓第三方應(yīng)用訪問該用戶在某一網(wǎng)站上存儲的私密資源(如照片,視頻,聯(lián)系人列表),而無需將用戶名和密碼提供給第三方

關(guān)鍵字:appKey appSecret token(令牌)

2.SSO授權(quán)

如果本地手機裝有微博客戶端,則直接跳轉(zhuǎn)到微博客戶端,只需點擊授權(quán)按鈕,就可以登陸了


qq第三方登陸使用Oauth3.0實現(xiàn),測試代碼

點擊下面的連接

/tupian/20230522/authorize><?php // qq登陸類 class Sso{   const APP_ID="101334262";   const APP_KEY="xxxxxxxxxxxxxxx";   //初始化   public static function init(){     header("content-type:text/html;charset=utf-8");   }     //主函數(shù)   public static function main(){     //請求控制     $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::postUrlContents("/tupian/20230522/token",$par);     if(strpos($rec, 'access_token') !== false) {       parse_str($rec, $accessToken);       $openidJson=Sso::getUrlContents("/tupian/20230522/me       $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']}");     }   }   //獲取用戶信息   public static function getQQinfo(){     Sso::init();     $openid=$_GET['openid'];     $access_token=$_GET['access_token'];     $userJson=Sso::getUrlContents("/tupian/20230522/get_user_info     $user=json_decode($userJson,true);     print_r($user);   }   //get方式請求數(shù)據(jù)   public static function getUrlContents($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請求數(shù)據(jù)   public static function postUrlContents($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授權(quán)和本地加密的實現(xiàn)方法”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!

本文標題:PHPOauth授權(quán)和本地加密的實現(xiàn)方法-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://www.muchs.cn/article46/shchg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、服務(wù)器托管、動態(tài)網(wǎng)站、網(wǎng)站制作靜態(tài)網(wǎng)站、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司