mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
PSR规范调整
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
|
||||
namespace think\oauth;
|
||||
|
||||
abstract class Driver {
|
||||
abstract class Driver
|
||||
{
|
||||
|
||||
/**
|
||||
* oauth版本
|
||||
@@ -39,7 +40,7 @@ abstract class Driver {
|
||||
|
||||
/**
|
||||
* grant_type 目前只能为 authorization_code
|
||||
* @var string
|
||||
* @var string
|
||||
*/
|
||||
protected $grantType = 'authorization_code';
|
||||
|
||||
@@ -75,18 +76,20 @@ abstract class Driver {
|
||||
|
||||
/**
|
||||
* 构造方法,配置应用信息
|
||||
* @param array $config
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct($config = []){
|
||||
public function __construct($config = [])
|
||||
{
|
||||
$this->appKey = $config['app_key'];
|
||||
$this->appSecret = $config['app_secret'];
|
||||
$this->authorize = isset($config['authorize']) ? $config['authorize'] : '';
|
||||
$this->callback = isset($config['callback']) ? $config['callback'] : '';
|
||||
$this->callback = isset($config['callback']) ? $config['callback'] : '';
|
||||
}
|
||||
|
||||
// 跳转到授权登录页面
|
||||
public function login($callback = ''){
|
||||
if($callback) {
|
||||
public function login($callback = '')
|
||||
{
|
||||
if ($callback) {
|
||||
$this->callback = $callback;
|
||||
}
|
||||
//跳转到授权页面
|
||||
@@ -95,20 +98,21 @@ abstract class Driver {
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求code
|
||||
* 请求code
|
||||
*/
|
||||
public function getRequestCodeURL(){
|
||||
public function getRequestCodeURL()
|
||||
{
|
||||
//Oauth 标准参数
|
||||
$params = array(
|
||||
'client_id' => $this->appKey,
|
||||
'redirect_uri' => $this->callback,
|
||||
'response_type' => $this->responseType,
|
||||
);
|
||||
|
||||
|
||||
//获取额外参数
|
||||
if($this->authorize){
|
||||
if ($this->authorize) {
|
||||
parse_str($this->authorize, $_param);
|
||||
if(is_array($_param)){
|
||||
if (is_array($_param)) {
|
||||
$params = array_merge($params, $_param);
|
||||
} else {
|
||||
throw new \Exception('AUTHORIZE配置不正确!');
|
||||
@@ -116,18 +120,19 @@ abstract class Driver {
|
||||
}
|
||||
return $this->getRequestCodeURL . '?' . http_build_query($params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @param string $code 授权登录成功后得到的code信息
|
||||
*/
|
||||
public function getAccessToken($code){
|
||||
public function getAccessToken($code)
|
||||
{
|
||||
$params = array(
|
||||
'client_id' => $this->appKey,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => $this->grantType,
|
||||
'redirect_uri' => $this->callback,
|
||||
'code' => $code,
|
||||
'client_id' => $this->appKey,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => $this->grantType,
|
||||
'redirect_uri' => $this->callback,
|
||||
'code' => $code,
|
||||
);
|
||||
// 获取token信息
|
||||
$data = $this->http($this->getAccessTokenURL, $params, 'POST');
|
||||
@@ -140,8 +145,9 @@ abstract class Driver {
|
||||
* 设置access_token
|
||||
* @param string $token
|
||||
*/
|
||||
public function setToken($token){
|
||||
$this->token = $token;
|
||||
public function setToken($token)
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,9 +156,12 @@ abstract class Driver {
|
||||
* @param array/string $param 额外参数
|
||||
* @return array:
|
||||
*/
|
||||
protected function param($params, $param){
|
||||
if(is_string($param))
|
||||
protected function param($params, $param)
|
||||
{
|
||||
if (is_string($param)) {
|
||||
parse_str($param, $param);
|
||||
}
|
||||
|
||||
return array_merge($params, $param);
|
||||
}
|
||||
|
||||
@@ -162,7 +171,8 @@ abstract class Driver {
|
||||
* @param string $fix api后缀
|
||||
* @return string 请求的完整URL
|
||||
*/
|
||||
protected function url($api, $fix = ''){
|
||||
protected function url($api, $fix = '')
|
||||
{
|
||||
return $this->apiBase . $api . $fix;
|
||||
}
|
||||
|
||||
@@ -173,39 +183,43 @@ abstract class Driver {
|
||||
* @param string $method 请求方法GET/POST
|
||||
* @return array $data 响应数据
|
||||
*/
|
||||
protected function http($url, $params, $method = 'GET', $header = [], $multi = false){
|
||||
protected function http($url, $params, $method = 'GET', $header = [], $multi = false)
|
||||
{
|
||||
$opts = array(
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_RETURNTRANSFER => 1,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_HTTPHEADER => $header
|
||||
CURLOPT_HTTPHEADER => $header,
|
||||
);
|
||||
|
||||
/* 根据请求类型设置特定参数 */
|
||||
switch(strtoupper($method)){
|
||||
switch (strtoupper($method)) {
|
||||
case 'GET':
|
||||
$opts[CURLOPT_URL] = $url . '?' . http_build_query($params);
|
||||
break;
|
||||
case 'POST':
|
||||
//判断是否传输文件
|
||||
$params = $multi ? $params : http_build_query($params);
|
||||
$opts[CURLOPT_URL] = $url;
|
||||
$opts[CURLOPT_POST] = 1;
|
||||
$params = $multi ? $params : http_build_query($params);
|
||||
$opts[CURLOPT_URL] = $url;
|
||||
$opts[CURLOPT_POST] = 1;
|
||||
$opts[CURLOPT_POSTFIELDS] = $params;
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('不支持的请求方式!');
|
||||
}
|
||||
|
||||
|
||||
/* 初始化并执行curl请求 */
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $opts);
|
||||
$data = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if($error) throw new \Exception('请求发生错误:' . $error);
|
||||
return $data;
|
||||
if ($error) {
|
||||
throw new \Exception('请求发生错误:' . $error);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +238,7 @@ abstract class Driver {
|
||||
* 抽象方法,在SNSSDK中实现
|
||||
* 获取当前授权用户的SNS标识
|
||||
*/
|
||||
abstract public function getOpenId();
|
||||
abstract public function getOpenId();
|
||||
|
||||
/**
|
||||
* 抽象方法
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Baidu extends Driver{
|
||||
class Baidu extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,12 +40,13 @@ class Baidu extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 百度调用公共参数 */
|
||||
$params = array(
|
||||
'access_token' => $this->token['access_token'],
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
@@ -52,38 +55,45 @@ class Baidu extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['refresh_token']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
|
||||
$data['openid'] = $this->openid();
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取百度ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('passport/users/getLoggedInUser');
|
||||
return !empty($data['uid'])?$data['uid']:null;
|
||||
return !empty($data['uid']) ? $data['uid'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('passport/users/getLoggedInUser');
|
||||
|
||||
if(!empty($data['uid'])){
|
||||
$userInfo['type'] = 'BAIDU';
|
||||
$userInfo['name'] = $data['uid'];
|
||||
$userInfo['nick'] = $data['uname'];
|
||||
$userInfo['avatar'] = "http://tb.himg.baidu.com/sys/portrait/item/{$data['portrait']}";
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('passport/users/getLoggedInUser');
|
||||
|
||||
if (!empty($data['uid'])) {
|
||||
$userInfo['type'] = 'BAIDU';
|
||||
$userInfo['name'] = $data['uid'];
|
||||
$userInfo['nick'] = $data['uname'];
|
||||
$userInfo['avatar'] = "http://tb.himg.baidu.com/sys/portrait/item/{$data['portrait']}";
|
||||
return $userInfo;
|
||||
} else {
|
||||
throw new \Exception("获取百度用户信息失败:{$data['error_msg']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Diandian extends Driver{
|
||||
class Diandian extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,12 +40,13 @@ class Diandian extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 点点网调用公共参数 */
|
||||
$params = array(
|
||||
'access_token' => $this->token['access_token'],
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
@@ -52,23 +55,29 @@ class Diandian extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['token_type'] && $data['uid']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['token_type'] && $data['uid']) {
|
||||
$data['openid'] = $data['uid'];
|
||||
unset($data['uid']);
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取点点网ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,14 +85,15 @@ class Diandian extends Driver{
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('user/info');
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user/info');
|
||||
|
||||
if(!empty($data['meta']['status']) && $data['meta']['status'] == 200){
|
||||
$userInfo['type'] = 'DIANDIAN';
|
||||
$userInfo['name'] = $data['response']['name'];
|
||||
$userInfo['nick'] = $data['response']['name'];
|
||||
$userInfo['avatar'] = "https://api.diandian.com/v1/blog/{$data['response']['blogs'][0]['blogUuid']}/avatar/144";
|
||||
if (!empty($data['meta']['status']) && 200 == $data['meta']['status']) {
|
||||
$userInfo['type'] = 'DIANDIAN';
|
||||
$userInfo['name'] = $data['response']['name'];
|
||||
$userInfo['nick'] = $data['response']['name'];
|
||||
$userInfo['avatar'] = "https://api.diandian.com/v1/blog/{$data['response']['blogs'][0]['blogUuid']}/avatar/144";
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取点点用户信息失败:{$data}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Douban extends Driver{
|
||||
class Douban extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,7 +40,8 @@ class Douban extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 豆瓣调用公共参数 */
|
||||
$params = [];
|
||||
$header = array("Authorization: Bearer {$this->token['access_token']}");
|
||||
@@ -50,38 +53,45 @@ class Douban extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['refresh_token'] && $data['douban_user_id']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token'] && $data['douban_user_id']) {
|
||||
$data['openid'] = $data['douban_user_id'];
|
||||
unset($data['douban_user_id']);
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取豆瓣ACCESS_TOKEN出错:{$data['msg']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string|null
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('user/~me');
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user/~me');
|
||||
|
||||
if(empty($data['code'])){
|
||||
$userInfo['type'] = 'DOUBAN';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['avatar'];
|
||||
if (empty($data['code'])) {
|
||||
$userInfo['type'] = 'DOUBAN';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['avatar'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取豆瓣用户信息失败:{$data['msg']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Github extends Driver{
|
||||
class Github extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,7 +40,8 @@ class Github extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* Github 调用公共参数 */
|
||||
$params = [];
|
||||
$header = array("Authorization: bearer {$this->token['access_token']}");
|
||||
@@ -51,39 +54,45 @@ class Github extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
parse_str($result, $data);
|
||||
if($data['access_token'] && $data['token_type']){
|
||||
if ($data['access_token'] && $data['token_type']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取 Github ACCESS_TOKEN出错:未知错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('user');
|
||||
return !empty($data['id'])?$data['id']:null;
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('user');
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user');
|
||||
|
||||
if(empty($data['code'])){
|
||||
$userInfo['type'] = 'GITHUB';
|
||||
$userInfo['name'] = $data['login'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['avatar_url'];
|
||||
if (empty($data['code'])) {
|
||||
$userInfo['type'] = 'GITHUB';
|
||||
$userInfo['name'] = $data['login'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['avatar_url'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取Github用户信息失败:{$data}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Google extends Driver{
|
||||
class Google extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -44,7 +46,8 @@ class Google extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* Google 调用公共参数 */
|
||||
$params = [];
|
||||
$header = array("Authorization: Bearer {$this->token['access_token']}");
|
||||
@@ -57,39 +60,45 @@ class Google extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['token_type'] && $data['expires_in']){
|
||||
if ($data['access_token'] && $data['token_type'] && $data['expires_in']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取 Google ACCESS_TOKEN出错:未知错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
|
||||
}
|
||||
|
||||
$data = $this->call('userinfo');
|
||||
return !empty($data['id'])?$data['id']:null;
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('userinfo');
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('userinfo');
|
||||
|
||||
if(!empty($data['id'])){
|
||||
$userInfo['type'] = 'GOOGLE';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['picture'];
|
||||
if (!empty($data['id'])) {
|
||||
$userInfo['type'] = 'GOOGLE';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['picture'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取Google用户信息失败:{$data}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Kaixin extends Driver{
|
||||
class Kaixin extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,12 +40,13 @@ class Kaixin extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 开心网调用公共参数 */
|
||||
$params = array(
|
||||
'access_token' => $this->token['access_token'],
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
@@ -52,39 +55,45 @@ class Kaixin extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['refresh_token']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取开心网ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
|
||||
}
|
||||
|
||||
$data = $this->call('users/me');
|
||||
return !empty($data['uid'])?$data['uid']:null;
|
||||
return !empty($data['uid']) ? $data['uid'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('users/me');
|
||||
|
||||
if(!empty($data['uid'])){
|
||||
$userInfo['type'] = 'KAIXIN';
|
||||
$userInfo['name'] = $data['uid'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['logo50'];
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('users/me');
|
||||
|
||||
if (!empty($data['uid'])) {
|
||||
$userInfo['type'] = 'KAIXIN';
|
||||
$userInfo['name'] = $data['uid'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['logo50'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取开心网用户信息失败:{$data['error']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Msn extends Driver{
|
||||
class Msn extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -44,7 +46,8 @@ class Msn extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* MSN 调用公共参数 */
|
||||
$params = array(
|
||||
'access_token' => $this->token['access_token'],
|
||||
@@ -58,39 +61,45 @@ class Msn extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['token_type'] && $data['expires_in']){
|
||||
if ($data['access_token'] && $data['token_type'] && $data['expires_in']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取 MSN ACCESS_TOKEN出错:未知错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('me');
|
||||
return !empty($data['id'])?$data['id']:null;
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('me');
|
||||
|
||||
if(!empty($data['id'])){
|
||||
$userInfo['type'] = 'MSN';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = '微软暂未提供头像URL,请通过 me/picture 接口下载';
|
||||
if (!empty($data['id'])) {
|
||||
$userInfo['type'] = 'MSN';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = '微软暂未提供头像URL,请通过 me/picture 接口下载';
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取msn用户信息失败:{$data}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Qq extends Driver{
|
||||
class Qq extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -44,56 +46,66 @@ class Qq extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 腾讯QQ调用公共参数 */
|
||||
$params = array(
|
||||
'oauth_consumer_key' => $this->AppKey,
|
||||
'access_token' => $this->token['access_token'],
|
||||
'openid' => $this->openid(),
|
||||
'format' => 'json'
|
||||
'format' => 'json',
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
parse_str($result, $data);
|
||||
if($data['access_token'] && $data['expires_in']){
|
||||
if ($data['access_token'] && $data['expires_in']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:{$result}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
if($data['access_token']){
|
||||
}
|
||||
|
||||
if ($data['access_token']) {
|
||||
$data = $this->http($this->url('oauth2.0/me'), array('access_token' => $data['access_token']));
|
||||
$data = json_decode(trim(substr($data, 9), " );\n"), true);
|
||||
if(isset($data['openid']))
|
||||
if (isset($data['openid'])) {
|
||||
return $data['openid'];
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getOauthInfo(){
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user/get_user_info');
|
||||
|
||||
if($data['ret'] == 0){
|
||||
$userInfo['type'] = 'QQ';
|
||||
$userInfo['name'] = $data['nickname'];
|
||||
$userInfo['nick'] = $data['nickname'];
|
||||
$userInfo['avatar'] = $data['figureurl_2'];
|
||||
if (0 == $data['ret']) {
|
||||
$userInfo['type'] = 'QQ';
|
||||
$userInfo['name'] = $data['nickname'];
|
||||
$userInfo['nick'] = $data['nickname'];
|
||||
$userInfo['avatar'] = $data['figureurl_2'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取腾讯QQ用户信息失败:{$data['msg']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Renren extends Driver{
|
||||
class Renren extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,7 +40,8 @@ class Renren extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'POST'){
|
||||
public function call($api, $param = '', $method = 'POST')
|
||||
{
|
||||
/* 人人网调用公共参数 */
|
||||
$params = array(
|
||||
'method' => $api,
|
||||
@@ -46,7 +49,7 @@ class Renren extends Driver{
|
||||
'v' => '1.0',
|
||||
'format' => 'json',
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url(''), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
@@ -57,16 +60,17 @@ class Renren extends Driver{
|
||||
* @param array/string $param 额外参数
|
||||
* @return array:
|
||||
*/
|
||||
protected function param($params, $param){
|
||||
protected function param($params, $param)
|
||||
{
|
||||
$params = parent::param($params, $param);
|
||||
|
||||
|
||||
/* 签名 */
|
||||
ksort($params);
|
||||
$param = [];
|
||||
foreach ($params as $key => $value){
|
||||
foreach ($params as $key => $value) {
|
||||
$param[] = "{$key}={$value}";
|
||||
}
|
||||
$sign = implode('', $param).$this->AppSecret;
|
||||
$sign = implode('', $param) . $this->AppSecret;
|
||||
$params['sig'] = md5($sign);
|
||||
|
||||
return $params;
|
||||
@@ -76,23 +80,29 @@ class Renren extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['refresh_token'] && $data['user']['id']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token'] && $data['user']['id']) {
|
||||
$data['openid'] = $data['user']['id'];
|
||||
unset($data['user']);
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取人人网ACCESS_TOKEN出错:{$data['error_description']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -100,14 +110,15 @@ class Renren extends Driver{
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('users.getInfo');
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('users.getInfo');
|
||||
|
||||
if(!isset($data['error_code'])){
|
||||
$userInfo['type'] = 'RENREN';
|
||||
$userInfo['name'] = $data[0]['name'];
|
||||
$userInfo['nick'] = $data[0]['name'];
|
||||
$userInfo['avatar'] = $data[0]['headurl'];
|
||||
if (!isset($data['error_code'])) {
|
||||
$userInfo['type'] = 'RENREN';
|
||||
$userInfo['name'] = $data[0]['name'];
|
||||
$userInfo['nick'] = $data[0]['name'];
|
||||
$userInfo['avatar'] = $data[0]['headurl'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取人人网用户信息失败:{$data['error_msg']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Sina extends Driver{
|
||||
class Sina extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,12 +40,13 @@ class Sina extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET', $multi = false){
|
||||
public function call($api, $param = '', $method = 'GET', $multi = false)
|
||||
{
|
||||
/* 新浪微博调用公共参数 */
|
||||
$params = array(
|
||||
'access_token' => $this->token['access_token'],
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method, $multi);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
@@ -52,23 +55,29 @@ class Sina extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['remind_in'] && $data['uid']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['remind_in'] && $data['uid']) {
|
||||
$data['openid'] = $data['uid'];
|
||||
unset($data['uid']);
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取新浪微博ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,14 +85,15 @@ class Sina extends Driver{
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('users.getInfo');
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('users.getInfo');
|
||||
|
||||
if(!isset($data['error_code'])){
|
||||
$userInfo['type'] = 'RENREN';
|
||||
$userInfo['name'] = $data[0]['name'];
|
||||
$userInfo['nick'] = $data[0]['name'];
|
||||
$userInfo['avatar'] = $data[0]['headurl'];
|
||||
if (!isset($data['error_code'])) {
|
||||
$userInfo['type'] = 'RENREN';
|
||||
$userInfo['name'] = $data[0]['name'];
|
||||
$userInfo['nick'] = $data[0]['name'];
|
||||
$userInfo['avatar'] = $data[0]['headurl'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取人人网用户信息失败:{$data['error_msg']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Sohu extends Driver{
|
||||
class Sohu extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,7 +40,8 @@ class Sohu extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 搜狐调用公共参数 */
|
||||
$params = array(
|
||||
'access_token' => $this->token['access_token'],
|
||||
@@ -52,23 +55,29 @@ class Sohu extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['refresh_token'] && $data['open_id']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token'] && $data['open_id']) {
|
||||
$data['openid'] = $data['open_id'];
|
||||
unset($data['open_id']);
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取搜狐ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,14 +85,15 @@ class Sohu extends Driver{
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('i/prv/1/user/get-basic-info');
|
||||
|
||||
if('success' == $data['message'] && !empty($data['data'])){
|
||||
$userInfo['type'] = 'SOHU';
|
||||
$userInfo['name'] = $data['data']['open_id'];
|
||||
$userInfo['nick'] = $data['data']['nick'];
|
||||
$userInfo['avatar'] = $data['data']['icon'];
|
||||
|
||||
if ('success' == $data['message'] && !empty($data['data'])) {
|
||||
$userInfo['type'] = 'SOHU';
|
||||
$userInfo['name'] = $data['data']['open_id'];
|
||||
$userInfo['nick'] = $data['data']['nick'];
|
||||
$userInfo['avatar'] = $data['data']['icon'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取搜狐用户信息失败:{$data['message']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class T163 extends Driver{
|
||||
class T163 extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,12 +40,13 @@ class T163 extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 新浪微博调用公共参数 */
|
||||
$params = array(
|
||||
'oauth_token' => $this->token['access_token'],
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
@@ -52,40 +55,46 @@ class T163 extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['uid'] && $data['access_token'] && $data['expires_in'] && $data['refresh_token']){
|
||||
if ($data['uid'] && $data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
|
||||
$data['openid'] = $data['uid'];
|
||||
unset($data['uid']);
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取网易微博ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('users/show');
|
||||
return !empty($data['id'])?$data['id']:null;
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('users/show');
|
||||
|
||||
if($data['error_code'] == 0){
|
||||
$userInfo['type'] = 'T163';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['screen_name'];
|
||||
$userInfo['avatar'] = str_replace('w=48&h=48', 'w=180&h=180', $data['profile_image_url']);
|
||||
if (0 == $data['error_code']) {
|
||||
$userInfo['type'] = 'T163';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['screen_name'];
|
||||
$userInfo['avatar'] = str_replace('w=48&h=48', 'w=180&h=180', $data['profile_image_url']);
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取网易微博用户信息失败:{$data['error']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Taobao extends Driver{
|
||||
class Taobao extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,7 +40,8 @@ class Taobao extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 淘宝网调用公共参数 */
|
||||
$params = array(
|
||||
'method' => $api,
|
||||
@@ -54,23 +57,29 @@ class Taobao extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['taobao_user_id']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['taobao_user_id']) {
|
||||
$data['openid'] = $data['taobao_user_id'];
|
||||
unset($data['taobao_user_id']);
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取淘宝网ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -78,20 +87,21 @@ class Taobao extends Driver{
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$fields = 'user_id,nick,sex,buyer_credit,avatar,has_shop,vip_info';
|
||||
$data = $this->call('taobao.user.buyer.get', "fields={$fields}");
|
||||
|
||||
if(!empty($data['user_buyer_get_response']['user'])){
|
||||
$user = $data['user_buyer_get_response']['user'];
|
||||
$userInfo['type'] = 'TAOBAO';
|
||||
$userInfo['name'] = $user['user_id'];
|
||||
$userInfo['nick'] = $user['nick'];
|
||||
$userInfo['avatar'] = $user['avatar'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取淘宝网用户信息失败:{$data['error_response']['msg']}");
|
||||
}
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$fields = 'user_id,nick,sex,buyer_credit,avatar,has_shop,vip_info';
|
||||
$data = $this->call('taobao.user.buyer.get', "fields={$fields}");
|
||||
|
||||
if (!empty($data['user_buyer_get_response']['user'])) {
|
||||
$user = $data['user_buyer_get_response']['user'];
|
||||
$userInfo['type'] = 'TAOBAO';
|
||||
$userInfo['name'] = $user['user_id'];
|
||||
$userInfo['nick'] = $user['nick'];
|
||||
$userInfo['avatar'] = $user['avatar'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取淘宝网用户信息失败:{$data['error_response']['msg']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class Tencent extends Driver{
|
||||
class Tencent extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,7 +40,8 @@ class Tencent extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET', $multi = false){
|
||||
public function call($api, $param = '', $method = 'GET', $multi = false)
|
||||
{
|
||||
/* 腾讯微博调用公共参数 */
|
||||
$params = array(
|
||||
'oauth_consumer_key' => $this->AppKey,
|
||||
@@ -47,7 +50,7 @@ class Tencent extends Driver{
|
||||
'clientip' => get_client_ip(),
|
||||
'oauth_version' => '2.a',
|
||||
'scope' => 'all',
|
||||
'format' => 'json'
|
||||
'format' => 'json',
|
||||
);
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method, $multi);
|
||||
@@ -55,25 +58,31 @@ class Tencent extends Driver{
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
parse_str($result, $data);
|
||||
$data = array_merge($data, ['openid' => $_GET['openid'], 'openkey' => $_GET['openkey']]);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['openid'])
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['openid']) {
|
||||
return $data;
|
||||
else
|
||||
} else {
|
||||
throw new \Exception("获取腾讯微博 ACCESS_TOKEN 出错:{$result}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -81,14 +90,15 @@ class Tencent extends Driver{
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
$data = $this->call('users.getInfo');
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('users.getInfo');
|
||||
|
||||
if(!isset($data['error_code'])){
|
||||
$userInfo['type'] = 'RENREN';
|
||||
$userInfo['name'] = $data[0]['name'];
|
||||
$userInfo['nick'] = $data[0]['name'];
|
||||
$userInfo['avatar'] = $data[0]['headurl'];
|
||||
if (!isset($data['error_code'])) {
|
||||
$userInfo['type'] = 'RENREN';
|
||||
$userInfo['name'] = $data[0]['name'];
|
||||
$userInfo['nick'] = $data[0]['name'];
|
||||
$userInfo['avatar'] = $data[0]['headurl'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取人人网用户信息失败:{$data['error_msg']}");
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\oauth\driver;
|
||||
|
||||
use think\oauth\Driver;
|
||||
|
||||
class X360 extends Driver{
|
||||
class X360 extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
@@ -38,12 +40,13 @@ class X360 extends Driver{
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET'){
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 360开放平台调用公共参数 */
|
||||
$params = array(
|
||||
'access_token' => $this->token['access_token'],
|
||||
);
|
||||
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
@@ -52,38 +55,45 @@ class X360 extends Driver{
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result){
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if($data['access_token'] && $data['expires_in'] && $data['refresh_token']){
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else
|
||||
} else {
|
||||
throw new \Exception("获取360开放平台ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId(){
|
||||
if(!empty($this->token['openid']))
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('user/me');
|
||||
return !empty($data['id'])?$data['id']:null;
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo(){
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user/me');
|
||||
|
||||
if($data['error_code'] == 0){
|
||||
$userInfo['type'] = 'X360';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['avatar'];
|
||||
if (0 == $data['error_code']) {
|
||||
$userInfo['type'] = 'X360';
|
||||
$userInfo['name'] = $data['name'];
|
||||
$userInfo['nick'] = $data['name'];
|
||||
$userInfo['avatar'] = $data['avatar'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取360用户信息失败:{$data['error']}");
|
||||
|
||||
Reference in New Issue
Block a user