目录调整
bug修复
This commit is contained in:
103
core/extend/org/oauth/driver/Diandian.php
Normal file
103
core/extend/org/oauth/driver/Diandian.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 杨维杰 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Diandian extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://api.diandian.com/oauth/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://api.diandian.com/oauth/token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://api.diandian.com/v1/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 点点网API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 点点网调用公共参数 */
|
||||
$params = [
|
||||
'access_token' => $this->token['access_token'],
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['token_type'] && $data['uid']) {
|
||||
$data['openid'] = $data['uid'];
|
||||
unset($data['uid']);
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取点点网ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user/info');
|
||||
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
101
core/extend/org/oauth/driver/Douban.php
Normal file
101
core/extend/org/oauth/driver/Douban.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Douban extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://www.douban.com/service/auth2/auth';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://www.douban.com/service/auth2/token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://api.douban.com/v2/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 豆瓣调用公共参数 */
|
||||
$params = [];
|
||||
$header = ["Authorization: Bearer {$this->token['access_token']}"];
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method, $header);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
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 {
|
||||
throw new \Exception("获取豆瓣ACCESS_TOKEN出错:{$data['msg']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string|null
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取豆瓣用户信息失败:{$data['msg']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
102
core/extend/org/oauth/driver/Github.php
Normal file
102
core/extend/org/oauth/driver/Github.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Github extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://github.com/login/oauth/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://github.com/login/oauth/access_token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://api.github.com/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* Github 调用公共参数 */
|
||||
$params = [];
|
||||
$header = ["Authorization: bearer {$this->token['access_token']}"];
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method, $header);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
parse_str($result, $data);
|
||||
if ($data['access_token'] && $data['token_type']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取 Github ACCESS_TOKEN出错:未知错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('user');
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取Github用户信息失败:{$data}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
108
core/extend/org/oauth/driver/Google.php
Normal file
108
core/extend/org/oauth/driver/Google.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Google extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://accounts.google.com/o/oauth2/auth';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://accounts.google.com/o/oauth2/token';
|
||||
|
||||
/**
|
||||
* 获取request_code的额外参数 URL查询字符串格式
|
||||
* @var srting
|
||||
*/
|
||||
protected $authorize = 'scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://www.googleapis.com/oauth2/v1/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* Google 调用公共参数 */
|
||||
$params = [];
|
||||
$header = ["Authorization: Bearer {$this->token['access_token']}"];
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method, $header);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['access_token'] && $data['token_type'] && $data['expires_in']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取 Google ACCESS_TOKEN出错:未知错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('userinfo');
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取Google用户信息失败:{$data}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
103
core/extend/org/oauth/driver/Kaixin.php
Normal file
103
core/extend/org/oauth/driver/Kaixin.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Kaixin extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'http://api.kaixin001.com/oauth2/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://api.kaixin001.com/oauth2/access_token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://api.kaixin001.com/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 开心网API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 开心网调用公共参数 */
|
||||
$params = [
|
||||
'access_token' => $this->token['access_token'],
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取开心网ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
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 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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取开心网用户信息失败:{$data['error']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
109
core/extend/org/oauth/driver/Msn.php
Normal file
109
core/extend/org/oauth/driver/Msn.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Msn extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://login.live.com/oauth20_authorize.srf';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://login.live.com/oauth20_token.srf';
|
||||
|
||||
/**
|
||||
* 获取request_code的额外参数 URL查询字符串格式
|
||||
* @var srting
|
||||
*/
|
||||
protected $authorize = 'scope=wl.basic wl.offline_access wl.signin wl.emails wl.photos';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://apis.live.net/v5.0/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* MSN 调用公共参数 */
|
||||
$params = [
|
||||
'access_token' => $this->token['access_token'],
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['access_token'] && $data['token_type'] && $data['expires_in']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取 MSN ACCESS_TOKEN出错:未知错误");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
$data = $this->call('me');
|
||||
return !empty($data['id']) ? $data['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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 接口下载';
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取msn用户信息失败:{$data}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
114
core/extend/org/oauth/driver/Qq.php
Normal file
114
core/extend/org/oauth/driver/Qq.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Qq extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://graph.qq.com/oauth2.0/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://graph.qq.com/oauth2.0/token';
|
||||
|
||||
/**
|
||||
* 获取request_code的额外参数,可在配置中修改 URL查询字符串格式
|
||||
* @var srting
|
||||
*/
|
||||
protected $authorize = 'scope=get_user_info,add_share';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://graph.qq.com/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 腾讯QQ调用公共参数 */
|
||||
$params = [
|
||||
'oauth_consumer_key' => $this->AppKey,
|
||||
'access_token' => $this->token['access_token'],
|
||||
'openid' => $this->openid(),
|
||||
'format' => 'json',
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
parse_str($result, $data);
|
||||
if ($data['access_token'] && $data['expires_in']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:{$result}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
if ($data['access_token']) {
|
||||
$data = $this->http($this->url('oauth2.0/me'), ['access_token' => $data['access_token']]);
|
||||
$data = json_decode(trim(substr($data, 9), " );\n"), true);
|
||||
if (isset($data['openid'])) {
|
||||
return $data['openid'];
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user/get_user_info');
|
||||
|
||||
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']}");
|
||||
}
|
||||
}
|
||||
}
|
||||
127
core/extend/org/oauth/driver/Renren.php
Normal file
127
core/extend/org/oauth/driver/Renren.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Renren extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://graph.renren.com/oauth/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://graph.renren.com/oauth/token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'http://api.renren.com/restserver.do';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'POST')
|
||||
{
|
||||
/* 人人网调用公共参数 */
|
||||
$params = [
|
||||
'method' => $api,
|
||||
'access_token' => $this->token['access_token'],
|
||||
'v' => '1.0',
|
||||
'format' => 'json',
|
||||
];
|
||||
|
||||
$data = $this->http($this->url(''), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并默认参数和额外参数
|
||||
* @param array $params 默认参数
|
||||
* @param array/string $param 额外参数
|
||||
* @return array:
|
||||
*/
|
||||
protected function param($params, $param)
|
||||
{
|
||||
$params = parent::param($params, $param);
|
||||
|
||||
/* 签名 */
|
||||
ksort($params);
|
||||
$param = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$param[] = "{$key}={$value}";
|
||||
}
|
||||
$sign = implode('', $param) . $this->AppSecret;
|
||||
$params['sig'] = md5($sign);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token'] && $data['user']['id']) {
|
||||
$data['openid'] = $data['user']['id'];
|
||||
unset($data['user']);
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取人人网ACCESS_TOKEN出错:{$data['error_description']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取人人网用户信息失败:{$data['error_msg']}");
|
||||
}
|
||||
}
|
||||
}
|
||||
103
core/extend/org/oauth/driver/Sina.php
Normal file
103
core/extend/org/oauth/driver/Sina.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Sina extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://api.weibo.com/oauth2/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://api.weibo.com/oauth2/access_token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://api.weibo.com/2/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET', $multi = false)
|
||||
{
|
||||
/* 新浪微博调用公共参数 */
|
||||
$params = [
|
||||
'access_token' => $this->token['access_token'],
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method, $multi);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['remind_in'] && $data['uid']) {
|
||||
$data['openid'] = $data['uid'];
|
||||
unset($data['uid']);
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取新浪微博ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取人人网用户信息失败:{$data['error_msg']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
103
core/extend/org/oauth/driver/Sohu.php
Normal file
103
core/extend/org/oauth/driver/Sohu.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Sohu extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://api.sohu.com/oauth2/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://api.sohu.com/oauth2/token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://api.sohu.com/rest/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 搜狐API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 搜狐调用公共参数 */
|
||||
$params = [
|
||||
'access_token' => $this->token['access_token'],
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
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 {
|
||||
throw new \Exception("获取搜狐ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取搜狐用户信息失败:{$data['message']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
104
core/extend/org/oauth/driver/T163.php
Normal file
104
core/extend/org/oauth/driver/T163.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class T163 extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://api.t.163.com/oauth2/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://api.t.163.com/oauth2/access_token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://api.t.163.com/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 新浪微博调用公共参数 */
|
||||
$params = [
|
||||
'oauth_token' => $this->token['access_token'],
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['uid'] && $data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
|
||||
$data['openid'] = $data['uid'];
|
||||
unset($data['uid']);
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取网易微博ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
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 array
|
||||
*/
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('users/show');
|
||||
|
||||
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']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
107
core/extend/org/oauth/driver/Taobao.php
Normal file
107
core/extend/org/oauth/driver/Taobao.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Taobao extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://oauth.taobao.com/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://oauth.taobao.com/token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://eco.taobao.com/router/rest';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 淘宝网调用公共参数 */
|
||||
$params = [
|
||||
'method' => $api,
|
||||
'access_token' => $this->token['access_token'],
|
||||
'format' => 'json',
|
||||
'v' => '2.0',
|
||||
];
|
||||
$data = $this->http($this->url(''), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
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 {
|
||||
throw new \Exception("获取淘宝网ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @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']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
108
core/extend/org/oauth/driver/Tencent.php
Normal file
108
core/extend/org/oauth/driver/Tencent.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class Tencent extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://open.t.qq.com/cgi-bin/oauth2/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://open.t.qq.com/cgi-bin/oauth2/access_token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://open.t.qq.com/api/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 微博API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET', $multi = false)
|
||||
{
|
||||
/* 腾讯微博调用公共参数 */
|
||||
$params = [
|
||||
'oauth_consumer_key' => $this->AppKey,
|
||||
'access_token' => $this->token['access_token'],
|
||||
'openid' => $this->openid(),
|
||||
'clientip' => $_SERVER['REMOTE_ADDR'],
|
||||
'oauth_version' => '2.a',
|
||||
'scope' => 'all',
|
||||
'format' => 'json',
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api), $this->param($params, $param), $method, $multi);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
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']) {
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取腾讯微博 ACCESS_TOKEN 出错:{$result}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
public function getOpenId()
|
||||
{
|
||||
if (!empty($this->token['openid'])) {
|
||||
return $this->token['openid'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
*/
|
||||
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'];
|
||||
return $userInfo;
|
||||
} else {
|
||||
E("获取人人网用户信息失败:{$data['error_msg']}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
103
core/extend/org/oauth/driver/X360.php
Normal file
103
core/extend/org/oauth/driver/X360.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org\oauth\driver;
|
||||
|
||||
use org\oauth\Driver;
|
||||
|
||||
class X360 extends Driver
|
||||
{
|
||||
/**
|
||||
* 获取requestCode的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getRequestCodeURL = 'https://openapi.360.cn/oauth2/authorize';
|
||||
|
||||
/**
|
||||
* 获取access_token的api接口
|
||||
* @var string
|
||||
*/
|
||||
protected $getAccessTokenURL = 'https://openapi.360.cn/oauth2/access_token';
|
||||
|
||||
/**
|
||||
* API根路径
|
||||
* @var string
|
||||
*/
|
||||
protected $apiBase = 'https://openapi.360.cn/';
|
||||
|
||||
/**
|
||||
* 组装接口调用参数 并调用接口
|
||||
* @param string $api 360开放平台API
|
||||
* @param string $param 调用API的额外参数
|
||||
* @param string $method HTTP请求方法 默认为GET
|
||||
* @return json
|
||||
*/
|
||||
public function call($api, $param = '', $method = 'GET')
|
||||
{
|
||||
/* 360开放平台调用公共参数 */
|
||||
$params = [
|
||||
'access_token' => $this->token['access_token'],
|
||||
];
|
||||
|
||||
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析access_token方法请求后的返回值
|
||||
* @param string $result 获取access_token的方法的返回值
|
||||
*/
|
||||
protected function parseToken($result)
|
||||
{
|
||||
$data = json_decode($result, true);
|
||||
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
|
||||
$data['openid'] = $this->getOpenId();
|
||||
return $data;
|
||||
} else {
|
||||
throw new \Exception("获取360开放平台ACCESS_TOKEN出错:{$data['error']}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前授权应用的openid
|
||||
* @return string
|
||||
*/
|
||||
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 array
|
||||
*/
|
||||
public function getOauthInfo()
|
||||
{
|
||||
$data = $this->call('user/me');
|
||||
|
||||
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