PHP Класс BaiduApiClient, thinksns

Автор: zhujianting([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$BD_OPENAPI_DEFAULT_DOMAINS Scheme & domain for Baidu OpenAPI interfaces.
$BD_OPENAPI_DEFAULT_PREFIXS URL prefixs for Baidu OpenAPI interfaces.

Защищенные свойства (Protected)

Свойство Тип Описание
$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

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
batchRun ( )
converJson2Array ( $json )
doBatchRun ( $useHttps = true )

Описание методов

__construct() публичный Метод

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() публичный Метод

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'.
Результат array | false Returns an array if success, or false if failed.

beginBatch() публичный Метод

Start a batch operation.
public beginBatch ( )

end_batch() публичный Метод

End current batch operation
public end_batch ( )

getAccessToken() публичный Метод

Get the access token for the following api calls.
public getAccessToken ( ) : string
Результат string

getClientId() публичный Метод

Get the client_id.
public getClientId ( ) : string
Результат string

getFinalEncode() публичный Метод

Get the charset of the app.
public getFinalEncode ( ) : string
Результат string

iconv() публичный статический Метод

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

setAccessToken() публичный Метод

Set access token for the following api calls.
public setAccessToken ( string $accessToken ) : BaiduApiClient
$accessToken string
Результат BaiduApiClient

setBatchMode() публичный Метод

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
Результат BaiduApiClient

setClientId() публичный Метод

Set the client_id.
public setClientId ( string $clientId ) : BaiduApiClient
$clientId string Client_id of the baidu thirdparty app or access_key of the developer.
Результат BaiduApiClient

setFinalEncode() публичный Метод

Set the charset for the app.
public setFinalEncode ( string $finalEncode ) : BaiduApiClient
$finalEncode string 'UTF-8' or 'GBK'
Результат BaiduApiClient

upload() публичный Метод

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.
Результат Returns an array if success, or false if failed.

Описание свойств

$BD_OPENAPI_DEFAULT_DOMAINS публичное статическое свойство

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

$BD_OPENAPI_DEFAULT_PREFIXS публичное статическое свойство

URL prefixs for Baidu OpenAPI interfaces.
public static $BD_OPENAPI_DEFAULT_PREFIXS

$accessToken защищенное свойство

protected $accessToken

$batchMode защищенное свойство

Mode of batch/run api
protected int $batchMode
Результат integer

$batchQueue защищенное свойство

Array of api calls to be batch run.
protected array $batchQueue
Результат array

$clientId защищенное свойство

protected $clientId

$finalEncode защищенное свойство

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