PHP code example of jiangwang / ad-ocean-sdk
1. Go to this page and download the library: Download jiangwang/ad-ocean-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jiangwang / ad-ocean-sdk example snippets
AdOceanSdk\Application;
use AdOceanSdk\Advertiser\Params\AdvertiserInfoGetParams;
// 初始化SDK
$app = Application::init();
// 设置Access Token
$app->client()->setAccessToken('your-access-token');
// 调用API - 获取广告主信息
$response = $app->apis()->openAdvertiserInfoGetApi(
AdvertiserInfoGetParams::from(['advertiser_id' => 123456])
);
// 获取响应数据
$advertiserInfo = $response->getData();
echo $advertiserInfo->toArray();
// 也可以直接传入数组
$response = $app->apis()->openAdvertiserInfoGetApi([
'advertiser_id' => 123456
]);
use AdOceanSdk\RequestClientInterceptor;
class MyInterceptor extends RequestClientInterceptor
{
public function response($response, $requestApi, $requestParams, $options)
{
// 在这里可以处理响应数据
echo "API调用: " . $requestApi->getAddress() . "\n";
return parent::response($response, $requestApi, $requestParams, $options);
}
}
$app = Application::init();
$app->client()
->setInterceptor(new MyInterceptor())
->setAccessToken('your-access-token');
use AdOceanSdk\RequestApi;
use AdOceanSdk\RequestParams;
use AdOceanSdk\RequestMethodEnum;
class CustomApi extends RequestApi
{
protected string $address = 'open_api/2/custom/api/';
protected RequestMethodEnum $method = RequestMethodEnum::GET;
public function call($params = [])
{
$response = parent::call($params);
return CustomResponse::from($response->toArray());
}
}
class CustomParams extends RequestParams
{
public int $custom_param;
}
// 使用自定义API
$app = Application::init();
$response = $app->client()->call(new CustomApi(), CustomParams::from([
'custom_param' => 123
]));