PHP Class SaeTOAuthV2, libweibo

授权机制说明请大家参考微博开放平台文档:{@link http://open.weibo.com/wiki/Oauth2}
Author: Elmer Zhang
Show file Open project: xiaosier/libweibo Class Usage Examples

Public Properties

Property Type Description
$access_token
$boundary boundary of multipart
$client_id
$client_secret
$connecttimeout Set connect timeout.
$debug print the debug info
$decode_json Decode returned json data.
$format Respons format.
$host Set up the API root URL.
$http_code Contains the last HTTP status code returned.
$http_info Contains the last HTTP headers returned.
$refresh_token
$ssl_verifypeer Verify SSL Cert.
$timeout Set timeout default.
$url Contains the last API call.
$useragent Set the useragnet.

Public Methods

Method Description
__construct ( $client_id, $client_secret, $access_token = NULL, $refresh_token = NULL ) construct WeiboOAuth object
accessTokenURL ( )
authorizeURL ( )
base64decode ( $str )
build_http_query_multi ( $params )
delete ( $url, $parameters = [] ) : mixed DELTE wrapper for oAuthReqeust.
get ( $url, $parameters = [] ) : mixed GET wrappwer for oAuthRequest.
getAccessToken ( string $type = 'code', array $keys ) : array access_token接口
getAuthorizeURL ( string $url, string $response_type = 'code', string $state = NULL, string $display = NULL ) : array authorize接口
getHeader ( $ch, $header ) : integer Get the header info to store.
getTokenFromArray ( array $arr ) : array 从数组中读取access_token和refresh_token 常用于从Session或Cookie中读取token,或通过Session/Cookie中是否存有token判断登录状态。
getTokenFromJSSDK ( ) : array 读取jssdk授权信息,用于和jssdk的同步登录
http ( $url, $method, $postfields = NULL, $headers = [] ) : string Make an HTTP request
oAuthRequest ( $url, $method, $parameters, $multi = false ) : string Format and sign an OAuth / API request
parseSignedRequest ( string $signed_request ) : array 解析 signed_request
post ( $url, $parameters = [], $multi = false ) : mixed POST wreapper for oAuthRequest.

Method Details

__construct() public method

construct WeiboOAuth object
public __construct ( $client_id, $client_secret, $access_token = NULL, $refresh_token = NULL )

accessTokenURL() public method

public accessTokenURL ( )

authorizeURL() public method

public authorizeURL ( )

base64decode() public method

public base64decode ( $str )

build_http_query_multi() public static method

public static build_http_query_multi ( $params )

delete() public method

DELTE wrapper for oAuthReqeust.
public delete ( $url, $parameters = [] ) : mixed
return mixed

get() public method

GET wrappwer for oAuthRequest.
public get ( $url, $parameters = [] ) : mixed
return mixed

getAccessToken() public method

对应API:{@link http://open.weibo.com/wiki/OAuth2/access_token OAuth2/access_token}
public getAccessToken ( string $type = 'code', array $keys ) : array
$type string 请求的类型,可以为:code, password, token
$keys array 其他参数: - 当$type为code时: array('code'=>..., 'redirect_uri'=>...) - 当$type为password时: array('username'=>..., 'password'=>...) - 当$type为token时: array('refresh_token'=>...)
return array

getAuthorizeURL() public method

对应API:{@link http://open.weibo.com/wiki/Oauth2/authorize Oauth2/authorize}
public getAuthorizeURL ( string $url, string $response_type = 'code', string $state = NULL, string $display = NULL ) : array
$url string 授权后的回调地址,站外应用需与回调地址一致,站内应用需要填写canvas page的地址
$response_type string 支持的值包括 code 和token 默认值为code
$state string 用于保持请求和回调的状态。在回调时,会在Query Parameter中回传该参数
$display string 授权页面类型 可选范围: - 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刷新站内应用父框架
return array

getHeader() public method

Get the header info to store.
public getHeader ( $ch, $header ) : integer
return integer

getTokenFromArray() public method

从数组中读取access_token和refresh_token 常用于从Session或Cookie中读取token,或通过Session/Cookie中是否存有token判断登录状态。
public getTokenFromArray ( array $arr ) : array
$arr array 存有access_token和secret_token的数组
return array 成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false

getTokenFromJSSDK() public method

读取jssdk授权信息,用于和jssdk的同步登录
public getTokenFromJSSDK ( ) : array
return array 成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false

http() public method

Make an HTTP request
public http ( $url, $method, $postfields = NULL, $headers = [] ) : string
return string API results

oAuthRequest() public method

Format and sign an OAuth / API request
public oAuthRequest ( $url, $method, $parameters, $multi = false ) : string
return string

parseSignedRequest() public method

解析 signed_request
public parseSignedRequest ( string $signed_request ) : array
$signed_request string 应用框架在加载iframe时会通过向Canvas URL post的参数signed_request
return array

post() public method

POST wreapper for oAuthRequest.
public post ( $url, $parameters = [], $multi = false ) : mixed
return mixed

Property Details

$access_token public property

public $access_token

$boundary public static property

boundary of multipart
public static $boundary

$client_id public property

public $client_id

$client_secret public property

public $client_secret

$connecttimeout public property

Set connect timeout.
public $connecttimeout

$debug public property

print the debug info
public $debug

$decode_json public property

Decode returned json data.
public $decode_json

$format public property

Respons format.
public $format

$host public property

Set up the API root URL.
public $host

$http_code public property

Contains the last HTTP status code returned.
public $http_code

$http_info public property

Contains the last HTTP headers returned.
public $http_info

$refresh_token public property

public $refresh_token

$ssl_verifypeer public property

Verify SSL Cert.
public $ssl_verifypeer

$timeout public property

Set timeout default.
public $timeout

$url public property

Contains the last API call.
public $url

$useragent public property

Set the useragnet.
public $useragent