|
@@ -34,12 +34,70 @@ class GdtAdapter
|
|
|
// 获取小时消耗
|
|
// 获取小时消耗
|
|
|
public function getHourlyCost($advertiserId, $accessToken, $date): array
|
|
public function getHourlyCost($advertiserId, $accessToken, $date): array
|
|
|
{
|
|
{
|
|
|
- return [];
|
|
|
|
|
|
|
+ $page = 1;
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ do {
|
|
|
|
|
+ $nonce = md5(time().rand(00000, 99999));
|
|
|
|
|
+ $url = 'https://api.e.qq.com/v3.0/hourly_reports/get?access_token='.$accessToken.'×tamp='.time().'&nonce='.$nonce;
|
|
|
|
|
+ $request_data = [
|
|
|
|
|
+ 'account_id' => $advertiserId,
|
|
|
|
|
+ 'level' => 'REPORT_LEVEL_ADGROUP',
|
|
|
|
|
+ 'date_range' => json_encode(['start_date' => $date, 'end_date' => $date]),
|
|
|
|
|
+ 'group_by' => json_encode(['hour', 'adgroup_id']),
|
|
|
|
|
+ 'fields' => json_encode(['hour', 'adgroup_id', 'adgroup_name', 'view_count', 'valid_click_count', 'cost', 'activated_count']),
|
|
|
|
|
+ 'page' => $page,
|
|
|
|
|
+ 'page_size' => 100,
|
|
|
|
|
+ ];
|
|
|
|
|
+ $url = $url."&".http_build_query($request_data);
|
|
|
|
|
+ $httpClient = new Client(['timeout' => 10]);
|
|
|
|
|
+ $res = $httpClient->request('GET', $url);
|
|
|
|
|
+ $result = json_decode($res->getBody(), true);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($result['data']['list'])) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $data = array_merge($data, $result['data']['list']);
|
|
|
|
|
+ $totalPage = $result['data']['page_info']['total_page'] ?? 1;
|
|
|
|
|
+ $page++;
|
|
|
|
|
+ } while ($page <= $totalPage);
|
|
|
|
|
+
|
|
|
|
|
+ return $data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取媒体消耗
|
|
// 获取媒体消耗
|
|
|
public function getVideoCost($advertiserId, $accessToken, $date): array
|
|
public function getVideoCost($advertiserId, $accessToken, $date): array
|
|
|
{
|
|
{
|
|
|
- return [];
|
|
|
|
|
|
|
+ $page = 1;
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ do {
|
|
|
|
|
+ $nonce = md5(time().rand(00000, 99999));
|
|
|
|
|
+ $url = 'https://api.e.qq.com/v3.0/daily_reports/get?access_token='.$accessToken.'×tamp='.time().'&nonce='.$nonce;
|
|
|
|
|
+
|
|
|
|
|
+ $request_data = [
|
|
|
|
|
+ 'account_id' => $advertiserId,
|
|
|
|
|
+ 'level' => 'REPORT_LEVEL_MATERIAL_VIDEO',
|
|
|
|
|
+ 'date_range' => json_encode(['start_date'=>$date,'end_date'=>$date]),
|
|
|
|
|
+ 'group_by' => json_encode(['date','video_id','adgroup_id']),
|
|
|
|
|
+ 'fields' => json_encode(['date','video_id','adgroup_id','adgroup_name', 'view_count','valid_click_count','cost', 'activated_count','download_count','first_pay_count','video_outer_play_count','video_outer_play100_count']),
|
|
|
|
|
+ 'page' => $page,
|
|
|
|
|
+ 'page_size' => 1000,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $url = $url."&".http_build_query($request_data);
|
|
|
|
|
+ $httpClient = new Client(['timeout' => 10]);
|
|
|
|
|
+ $res = $httpClient->request('GET', $url);
|
|
|
|
|
+ $result = json_decode($res->getBody(), true);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($result['data']['list'])) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $data = array_merge($data, $result['data']['list']);
|
|
|
|
|
+ $totalPage = $result['data']['page_info']['total_page'] ?? 1;
|
|
|
|
|
+ $page++;
|
|
|
|
|
+ } while ($page <= $totalPage);
|
|
|
|
|
+
|
|
|
|
|
+ return $data;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|