PHP Class BaiduAPI, thinksns

Author: zhujianting([email protected])
Show file Open project: medz/thinksns-4 Class Usage Examples

Protected Properties

Property Type Description
$clientId string The client_id of the app or access_key of the developer.
$clientSecret string The client_secret of the app or secret_key of the developer.
$oauth2 BaiduOAuth2
$redirectUri string Redirect uri of the app, where we will redirect to after user authorization.
$session array User session info.
$state string
$store BaiduStore Storage for the user session related datas, like state, authorization code, access token and so on.

Public Methods

Method Description
__construct ( string $clientId, string $clientSecret, string $redirectUri, BaiduStore $store = null ) Constructor
getAccessToken ( ) : string | false Get access token for openapi calls.
getBaiduApiClientService ( ) : BaiduApiClient Get an instance of BaiduApiClient class.
getBaiduOAuth2Service ( ) : BaiduOAuth2 Get an instance of BaiduOAuth2 class.
getLoggedInUser ( ) : uint | false Get currently logged in user's uid.
getLoginUrl ( string $scope = '', string $display = 'page' ) : string Get a Login URL for use with redirects. By default, full page redirect is assumed. If you are using the generated URL with a window.open() call in JavaScript, you can pass in display=popup as part of the $params.
getLogoutUrl ( string $next ) : string Get the Logout URL suitable for use with redirects.
getRefreshToken ( ) : string | false Get refresh token.
getSession ( ) : array Get user session info.
setSession ( array $session ) : Baidu Set user session.

Protected Methods

Method Description
doGetSession ( ) : array | false Get session info from Baidu server or from the store in app server side.
establishCSRFTokenState ( ) Lays down a CSRF state token for this process.
getCode ( ) : mixed Get the authorization code from the query parameters, if it exists, otherwise return false to signal no authorization code was discoverable.
getUser ( ) : array | false Get current user's uid and uname.
setStore ( BaiduStore $store ) : Baidu Set the session data storage instance.

Method Details

__construct() public method

Constructor
public __construct ( string $clientId, string $clientSecret, string $redirectUri, BaiduStore $store = null )
$clientId string The client_id of the app or access_key of the developer.
$clientSecret string The client_secret of the app or secret_key of the developer.
$redirectUri string Redirect uri of the app.
$store BaiduStore Storage for the user session related datas.

doGetSession() protected method

Get session info from Baidu server or from the store in app server side.
protected doGetSession ( ) : array | false
return array | false

establishCSRFTokenState() protected method

Lays down a CSRF state token for this process.
protected establishCSRFTokenState ( )

getAccessToken() public method

Get access token for openapi calls.
public getAccessToken ( ) : string | false
return string | false Returns access token if user has authorized the app, or false if not.

getBaiduApiClientService() public method

Get an instance of BaiduApiClient class.
public getBaiduApiClientService ( ) : BaiduApiClient
return BaiduApiClient

getBaiduOAuth2Service() public method

Get an instance of BaiduOAuth2 class.
public getBaiduOAuth2Service ( ) : BaiduOAuth2
return BaiduOAuth2

getCode() protected method

Get the authorization code from the query parameters, if it exists, otherwise return false to signal no authorization code was discoverable.
protected getCode ( ) : mixed
return mixed Returns the authorization code, or false if the authorization code could not be determined.

getLoggedInUser() public method

Get currently logged in user's uid.
public getLoggedInUser ( ) : uint | false
return uint | false Return uid of the loggedin user, or return false if user isn't loggedin.

getLoginUrl() public method

Get a Login URL for use with redirects. By default, full page redirect is assumed. If you are using the generated URL with a window.open() call in JavaScript, you can pass in display=popup as part of the $params.
public getLoginUrl ( string $scope = '', string $display = 'page' ) : string
$scope string blank space separated list of requested extended perms
$display string Authorization page style, 'page', 'popup', 'touch' or 'mobile'
return string the URL for the login flow

getLogoutUrl() public method

Get the Logout URL suitable for use with redirects.
public getLogoutUrl ( string $next ) : string
$next string Url to go to after a successful logout.
return string

getRefreshToken() public method

Get refresh token.
public getRefreshToken ( ) : string | false
return string | false Returns refresh token if app has, or false if not.

getSession() public method

Get user session info.
public getSession ( ) : array
return array

getUser() protected method

Get current user's uid and uname.
protected getUser ( ) : array | false
return array | false array('uid' => xx, 'uname' => xx)

setSession() public method

Set user session.
public setSession ( array $session ) : Baidu
$session array User session info.
return Baidu

setStore() protected method

Set the session data storage instance.
protected setStore ( BaiduStore $store ) : Baidu
$store BaiduStore
return Baidu

Property Details

$clientId protected property

The client_id of the app or access_key of the developer.
protected string $clientId
return string

$clientSecret protected property

The client_secret of the app or secret_key of the developer.
protected string $clientSecret
return string

$oauth2 protected property

protected BaiduOAuth2 $oauth2
return BaiduOAuth2

$redirectUri protected property

Redirect uri of the app, where we will redirect to after user authorization.
protected string $redirectUri
return string

$session protected property

User session info.
protected array $session
return array

$state protected property

protected string $state
return string

$store protected property

Storage for the user session related datas, like state, authorization code, access token and so on.
protected BaiduStore $store
return BaiduStore