PHP Class BaiduApiClient, thinksns

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

Public Properties

Property Type Description
$BD_OPENAPI_DEFAULT_DOMAINS Scheme & domain for Baidu OpenAPI interfaces.
$BD_OPENAPI_DEFAULT_PREFIXS URL prefixs for Baidu OpenAPI interfaces.

Protected Properties

Property Type Description
$accessToken
$batchMode integer Mode of batch/run api
$batchQueue array Array of api calls to be batch run.
$clientId
$finalEncode Charset of the app pages, default is UTF-8

Public Methods

Method Description
__construct ( string $clientId, string $accessToken ) Constructor
api ( string $uri, array $params = [], string $httpMethod = 'GET', string $type = 'rest' ) : array | false Call an api which is opened by Baidu, file upload apis should not be called by this interface.
beginBatch ( ) Start a batch operation.
end_batch ( ) End current batch operation
getAccessToken ( ) : string Get the access token for the following api calls.
getClientId ( ) : string Get the client_id.
getFinalEncode ( ) : string Get the charset of the app.
iconv ( $var, $inCharset = 'UTF-8', $outCharset = 'GBK' )
setAccessToken ( string $accessToken ) : BaiduApiClient Set access token for the following api calls.
setBatchMode ( integer $batchMode ) : BaiduApiClient Set the mode of batch/run api.
setClientId ( string $clientId ) : BaiduApiClient Set the client_id.
setFinalEncode ( string $finalEncode ) : BaiduApiClient Set the charset for the app.
upload ( string $uri, $params = [] ) : Returns Call a file upload api.

Private Methods

Method Description
batchRun ( )
converJson2Array ( $json )
doBatchRun ( $useHttps = true )

Method Details

__construct() public method

Constructor
public __construct ( string $clientId, string $accessToken )
$clientId string Client_id of the baidu thirdparty app or access_key of the developer.
$accessToken string Access token for api call.

api() public method

Call an api which is opened by Baidu, file upload apis should not be called by this interface.
public api ( string $uri, array $params = [], string $httpMethod = 'GET', string $type = 'rest' ) : array | false
$uri string Uri for the api, it could be the whole url, like 'https://openapi.baidu.com/rest/2.0/passport/user/info/get', or url path only, like '/rest/2.0/passport/user/info/get', or just api method only, like 'passport/user/info/get'.
$params array Api specific parameters.
$httpMethod string Http method, could be 'GET' or 'POST'.
$type string Type name of the openapi, could be 'rest', or 'public'.
return array | false Returns an array if success, or false if failed.

beginBatch() public method

Start a batch operation.
public beginBatch ( )

end_batch() public method

End current batch operation
public end_batch ( )

getAccessToken() public method

Get the access token for the following api calls.
public getAccessToken ( ) : string
return string

getClientId() public method

Get the client_id.
public getClientId ( ) : string
return string

getFinalEncode() public method

Get the charset of the app.
public getFinalEncode ( ) : string
return string

iconv() public static method

public static iconv ( $var, $inCharset = 'UTF-8', $outCharset = 'GBK' )

setAccessToken() public method

Set access token for the following api calls.
public setAccessToken ( string $accessToken ) : BaiduApiClient
$accessToken string
return BaiduApiClient

setBatchMode() public method

Set the mode of batch/run api.
public setBatchMode ( integer $batchMode ) : BaiduApiClient
$batchMode integer Use BaiduApiClient::BATCH_MODE_SERVER_PARALLEL or BaiduApiClient::BATCH_MODE_SERIAL_ONLY
return BaiduApiClient

setClientId() public method

Set the client_id.
public setClientId ( string $clientId ) : BaiduApiClient
$clientId string Client_id of the baidu thirdparty app or access_key of the developer.
return BaiduApiClient

setFinalEncode() public method

Set the charset for the app.
public setFinalEncode ( string $finalEncode ) : BaiduApiClient
$finalEncode string 'UTF-8' or 'GBK'
return BaiduApiClient

upload() public method

Call a file upload api.
public upload ( string $uri, $params = [] ) : Returns
$uri string Uri for the api, it could be the whole url, like 'https://openapi.baidu.com/file/2.0/cloudalbum/picture/upload', or just api method only, like 'cloudalbum/picture/upload', if the api is provided under the domain of openapi.baidu.com.
$params Api specific parameters.
return Returns an array if success, or false if failed.

Property Details

$BD_OPENAPI_DEFAULT_DOMAINS public_oe static_oe property

Scheme & domain for Baidu OpenAPI interfaces.
public static $BD_OPENAPI_DEFAULT_DOMAINS

$BD_OPENAPI_DEFAULT_PREFIXS public_oe static_oe property

URL prefixs for Baidu OpenAPI interfaces.
public static $BD_OPENAPI_DEFAULT_PREFIXS

$accessToken protected_oe property

protected $accessToken

$batchMode protected_oe property

Mode of batch/run api
protected int $batchMode
return integer

$batchQueue protected_oe property

Array of api calls to be batch run.
protected array $batchQueue
return array

$clientId protected_oe property

protected $clientId

$finalEncode protected_oe property

Charset of the app pages, default is UTF-8
protected $finalEncode