\SaeTOAuthV2

新浪微博 OAuth 认证类(OAuth2)

授权机制说明请大家参考微博开放平台文档:http://open.weibo.com/wiki/Oauth2

Summary

Methods
Properties
Constants
__construct()
getAuthorizeURL()
getAccessToken()
parseSignedRequest()
getTokenFromJSSDK()
getTokenFromArray()
get()
post()
delete()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(  $client_id,   $client_secret,   $access_token = NULL,   $refresh_token = NULL) 

construct WeiboOAuth object

Parameters

$client_id
$client_secret
$access_token
$refresh_token

getAuthorizeURL()

getAuthorizeURL(string  $url, string  $response_type = 'code', string  $state = NULL, string  $display = NULL) : array

authorize接口

对应API:Oauth2/authorize

Parameters

string $url

授权后的回调地址,站外应用需与回调地址一致,站内应用需要填写canvas page的地址

string $response_type

支持的值包括 code 和token 默认值为code

string $state

用于保持请求和回调的状态。在回调时,会在Query Parameter中回传该参数

string $display

授权页面类型 可选范围:

  • default 默认授权页面
  • mobile 支持html5的手机
  • popup 弹窗授权页
  • wap1.2 wap1.2页面
  • wap2.0 wap2.0页面
  • js js-sdk 专用 授权页面是弹窗,返回结果为js-sdk回掉函数
  • apponweibo 站内应用专用,站内应用不传display参数,并且response_type为token时,默认使用改display.授权后不会返回access_token,只是输出js刷新站内应用父框架

Returns

array

getAccessToken()

getAccessToken(string  $type = 'code', array  $keys) : array

access_token接口

对应API:OAuth2/access_token

Parameters

string $type

请求的类型,可以为:code, password, token

array $keys

其他参数:

  • 当$type为code时: array('code'=>..., 'redirect_uri'=>...)
  • 当$type为password时: array('username'=>..., 'password'=>...)
  • 当$type为token时: array('refresh_token'=>...)

Returns

array

parseSignedRequest()

parseSignedRequest(string  $signed_request) : array

解析 signed_request

Parameters

string $signed_request

应用框架在加载iframe时会通过向Canvas URL post的参数signed_request

Returns

array

getTokenFromJSSDK()

getTokenFromJSSDK() : array

读取jssdk授权信息,用于和jssdk的同步登录

Returns

array —

成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false

getTokenFromArray()

getTokenFromArray(array  $arr) : array

从数组中读取access_token和refresh_token 常用于从Session或Cookie中读取token,或通过Session/Cookie中是否存有token判断登录状态。

Parameters

array $arr

存有access_token和secret_token的数组

Returns

array —

成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false

get()

get(  $url,   $parameters = array()) : mixed

GET wrappwer for oAuthRequest.

Parameters

$url
$parameters

Returns

mixed

post()

post(  $url,   $parameters = array(),   $multi = false) : mixed

POST wreapper for oAuthRequest.

Parameters

$url
$parameters
$multi

Returns

mixed

delete()

delete(  $url,   $parameters = array()) : mixed

DELTE wrapper for oAuthReqeust.

Parameters

$url
$parameters

Returns

mixed