来自 电脑系统 2019-12-18 20:48 的文章
当前位置: 金沙澳门官网网址 > 电脑系统 > 正文

PHP版QQ互联OAuth示例代码分享_php才干_脚本之家,

是因为本国QQ客户的普及性,所以今后各大网址都用尽全力的提供QQ登入口,上面大家来探视php版,给大家参照他事他说加以考察下

腾讯娱乐频道官方Wechat已联系所有获获奖项游戏发烧友,请大家必得关切Tencent娱乐频道Wechat!!

/** * QQ互联 oauth * @author dyllen * */class Oauth{ //取Authorization Code Url const PC_CODE_URL = 'https://graph.qq.com/oauth2.0/authorize'; //取Access Token Url const PC_ACCESS_TOKEN_URL = 'https://graph.qq.com/oauth2.0/token'; //取用户 Open Id Url const OPEN_ID_URL = 'https://graph.qq.com/oauth2.0/me'; //用户授权之后的回调地址 public $redirectUri = null; // App Id public $appid = null; //App Key public $appKey = null; //授权列表 //字符串,多个用逗号隔开 public $scope = null; //授权code public $code = null; //续期access token的凭证 public $refreshToken = null; //access token public $accessToken = null; //access token 有效期,单位秒 public $expiresIn = null; //state public $state = null; public $openid = null; //construct public function __construct { foreach($config as $key => $value) { $this->$key = $value; } } /** * 得到获取Code的url * @throws InvalidArgumentException * @return string */ public function codeUrl() { if  { throw new Exception('parameter $redirectUri must be set.'); } $query = [ 'response_type' => 'code', 'client_id' => $this->appid, 'redirect_uri' => $this->redirectUri, 'state' => $this->getState(), 'scope' => $this->scope, ]; return self::PC_CODE_URL . '?' . http_build_query; } /** * 取access token * @throws Exception * @return boolean */ public function getAccessToken() { $params = [ 'grant_type' => 'authorization_code', 'client_id' => $this->appid, 'client_secret' => $this->appKey, 'code' => $this->code, 'redirect_uri' => $this->redirectUri, ]; $url = self::PC_ACCESS_TOKEN_URL . '?' . http_build_query; $content = $this->getUrl; parse_str; if ( !isset ) { $this->thrwoError; } $this->accessToken = $res['access_token']; $this->expiresIn = $res['expires_in']; $this->refreshToken = $res['refresh_token']; return true; } /** * 刷新access token * @throws Exception * @return boolean */ public function refreshToken() { $params = [ 'grant_type' => 'refresh_token', 'client_id' => $this->appid, 'client_secret' => $this->appKey, 'refresh_token' => $this->refreshToken, ]; $url = self::PC_ACCESS_TOKEN_URL . '?' . http_build_query; $content = $this->getUrl; parse_str; if ( !isset ) { $this->thrwoError; } $this->accessToken = $res['access_token']; $this->expiresIn = $res['expires_in']; $this->refreshToken = $res['refresh_token']; return true; } /** * 取用户open id * @return string */ public function getOpenid() { $params = [ 'access_token' => $this->accessToken, ]; $url = self::OPEN_ID_URL . '?' . http_build_query; $this->openid = $this->parseOpenid ); return $this->openid; } /** * get方式取url内容 * @param string $url * @return mixed */ public function getUrl { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_URL, $url); $response = curl_exec; return $response; } /** * post方式取url内容 * @param string $url * @param array $keysArr * @param number $flag * @return mixed */ public function postUrl($url, $keysArr, $flag = 0) { $ch = curl_init curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $keysArr); curl_setopt($ch, CURLOPT_URL, $url); $ret = curl_exec; return $ret; } /** * 取state * @return string */ protected function getState() { $this->state = md5; //state暂存在缓存里面 //自己定义 //。。。。。。。。。 return $this->state; } /** * 验证state * @return boolean */ protected function verifyState() { //。。。。。。。 } /** * 抛出异常 * @param string $error * @throws Exception */ protected function thrwoError { $subError = substr($error, strpos; $subError = strstr . "}"; $error = json_decode; throw new Exception($error['error_description'], ; } /** * 从获取openid接口的返回数据中解析出openid * @param string $str * @return string */ protected function parseOpenid { $subStr = substr($str, strpos; $subStr = strstr . "}"; $strArr = json_decode; if(!isset { $this->thrwoError; } return $strArr['openid']; }}

QQ 1*****792

如上所述正是本文的全体内容了,希望大家能够赏识。

QQ 2*****613

QQ 2*****15

QQ 3*****92

QQ 1*****19

QQ 3*****01

QQ 2*****47

QQ 5*****477

QQ 8*****81

微信 7*****211

微信 l*****binlwb

QQ 3*****267

QQ 8*****18

QQ 1*****15

QQ 8*****66

QQ 1*****6

QQ 4*****776

QQ 3*****65

QQ 1*****8

微信 2*****48

本文由金沙澳门官网网址发布于电脑系统,转载请注明出处:PHP版QQ互联OAuth示例代码分享_php才干_脚本之家,

关键词: