Skip to content

Commit

Permalink
add QQ BizMail/exmail OAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
xjflyttp committed Jul 16, 2015
1 parent 5fb6e6f commit 9160a9c
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 36 deletions.
26 changes: 19 additions & 7 deletions DoubanAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* Douban OAuth
* @author light <[email protected]>
*/
class DoubanAuth extends OAuth2 implements IAuth {
class DoubanAuth extends OAuth2 implements IAuth
{

/**
* @inheritdoc
Expand All @@ -31,25 +32,35 @@ class DoubanAuth extends OAuth2 implements IAuth {
*/
public $scope = 'douban_basic_common';

protected function initUserAttributes()
{
//nothing
return $this->api('v2/user/~me', 'GET');
}

/**
* Get authed user info
*
* @return array
* @see http://developers.douban.com/wiki/?title=user_v2#User
*/
public function getUserInfo() {
return $this->api('v2/user/~me', 'GET');
public function getUserInfo()
{
return $this->getUserAttributes();
}

protected function defaultName() {
protected function defaultName()
{
return 'douban';
}

protected function defaultTitle() {
protected function defaultTitle()
{
return 'Douban';
}

protected function defaultViewOptions() {
protected function defaultViewOptions()
{
return [
'popupWidth' => 800,
'popupHeight' => 500,
Expand All @@ -60,7 +71,8 @@ protected function defaultViewOptions() {
*
* @ineritdoc
*/
public function api($apiSubUrl, $method = 'GET', array $params = [], array $headers = []) {
public function api($apiSubUrl, $method = 'GET', array $params = [], array $headers = [])
{
if (preg_match('/^https?:\\/\\//is', $apiSubUrl)) {
$url = $apiSubUrl;
} else {
Expand Down
24 changes: 16 additions & 8 deletions QqAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
* QQ OAuth
* @author xjflyttp <[email protected]>
*/
class QqAuth extends OAuth2 implements IAuth {
class QqAuth extends OAuth2 implements IAuth
{

public $authUrl = 'https://graph.qq.com/oauth2.0/authorize';
public $tokenUrl = 'https://graph.qq.com/oauth2.0/token';
public $apiBaseUrl = 'https://graph.qq.com';

public function init() {
public function init()
{
parent::init();
if ($this->scope === null) {
$this->scope = implode(',', [
Expand All @@ -23,7 +25,8 @@ public function init() {
}
}

protected function initUserAttributes() {
protected function initUserAttributes()
{
return $this->api('oauth2.0/me', 'GET');
}

Expand All @@ -32,23 +35,27 @@ protected function initUserAttributes() {
* @return []
* @see http://wiki.connect.qq.com/get_user_info
*/
public function getUserInfo() {
public function getUserInfo()
{
$openid = $this->getUserAttributes();
return $this->api("user/get_user_info", 'GET', [
'oauth_consumer_key' => $openid['client_id'],
'openid' => $openid['openid'
]]);
}

protected function defaultName() {
protected function defaultName()
{
return 'QQ';
}

protected function defaultTitle() {
protected function defaultTitle()
{
return 'QQ';
}

protected function defaultViewOptions() {
protected function defaultViewOptions()
{
return [
'popupWidth' => 800,
'popupHeight' => 500,
Expand All @@ -62,7 +69,8 @@ protected function defaultViewOptions() {
* @throws Exception on failure.
* @return array actual response.
*/
protected function processResponse($rawResponse, $contentType = self::CONTENT_TYPE_AUTO) {
protected function processResponse($rawResponse, $contentType = self::CONTENT_TYPE_AUTO)
{
if ($contentType == self::CONTENT_TYPE_AUTO) {
//jsonp to json
if (strpos($rawResponse, "callback") === 0) {
Expand Down
Loading

0 comments on commit 9160a9c

Please sign in to comment.