123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace App\Support\tencentAdSDK;
- use App\Log;
- use App\Models\TencentAdAuth;
- use App\Service\HttpService;
- class ReportsOpenApi extends BaseOpenApi
- {
- /**
- * 日报获取
- */
- public static function dailyReportsGet($data, $retry = 5)
- {
- $version = self::getAccountVersion($data['account_id']);
- $interface = 'daily_reports/get';
- $url = 'https://api.e.qq.com/' . $version . '/' . $interface;
- $access_token = TencentAdAuth::getAccessToken($data['account_id']);
- if (empty($access_token)) return false;
- $parameters = [
- 'account_id' => $data['account_id'],
- 'level' => 'REPORT_LEVEL_ADVERTISER',
- 'date_range' => [
- 'start_date' => $data['start_date'],
- 'end_date' => $data['end_date'],
- ],
- 'order_by' => [
- [
- 'sort_field' => 'date',
- 'sort_type' => 'ASCENDING'
- ]
- ],
- 'group_by' => [
- 'date'
- ],
- 'fields' => [
- 'view_count','view_user_count','date','account_id','cost', 'valid_click_count',
- 'follow_count','scan_follow_count','scan_follow_user_count', 'conversions_count',
- 'deep_conversions_count'
- ],
- 'page' => 1,
- 'page_size' => 100
- ];
- do {
- $parameters['access_token'] = $access_token;
- $parameters['timestamp'] = time();
- $parameters['nonce'] = md5(time().rand(10000,99999));
- foreach ($parameters as $key => $value) {
- if (!is_string($value)) {
- $parameters[$key] = json_encode($value);
- }
- }
- $request_url = $url . '?' . http_build_query($parameters);
- $res = HttpService::httpGet($request_url);
- // 记录日志
- Log::logInfo('获取日报数据API:' . $interface, [
- 'url' => $request_url,
- 'version' => $version,
- 'params' => $parameters,
- 'response' => $res,
- ], 'ReportsOpenApi');
- $resArr = json_decode($res, true);
- if (!$resArr) {
- $resArr = [
- 'code' => 666666,
- 'message' => '请求失败(自定义)'
- ];
- }
- if($resArr['code'] != 0) {
- sleep(1);
- }
- } while(($resArr['code'] != 0) && (--$retry > 0));
- if ($resArr['code'] == 0) {
- return self::returnSuccess($resArr['data']);
- } else {
- return self::returnFail([], $resArr['message']);
- }
- }
- /**
- * 日报获取
- */
- public static function mergeFundTypeFundsGet($accountId, $retry = 5)
- {
- $version = self::getAccountVersion($accountId);
- $interface = 'merge_fund_type_funds/get';
- $url = 'https://api.e.qq.com/' . $version . '/' . $interface;
- $access_token = TencentAdAuth::getAccessToken($accountId);
- if (empty($access_token)) return false;
- do {
- $parameters['timestamp'] = time();
- $parameters['access_token'] = $access_token;
- $parameters['nonce'] = md5(time().rand(10000,99999));
- $parameters['account_id'] = $accountId;
- foreach ($parameters as $key => $value) {
- if (!is_string($value)) {
- $parameters[$key] = json_encode($value);
- }
- }
- $request_url = $url . '?' . http_build_query($parameters);
- $res = HttpService::httpGet($request_url);
- // 记录日志
- Log::logInfo('获取资金账户数据API:' . $interface, [
- 'url' => $request_url,
- 'version' => $version,
- 'params' => $parameters,
- 'response' => $res,
- ], 'ReportsOpenApi');
- $resArr = json_decode($res, true);
- if (!$resArr) {
- $resArr = [
- 'code' => 666666,
- 'message' => '请求失败(自定义)'
- ];
- }
- if($resArr['code'] != 0) {
- sleep(10);
- }
- } while(($resArr['code'] != 0) && (--$retry > 0));
- if ($resArr['code'] == 0) {
- return self::returnSuccess($resArr['data']);
- } else {
- return self::returnFail([], $resArr['message']);
- }
- }
- public static function getAccountVersion($accountId) {
- $accountList = [
- 39369591,39369590,39584550,38560767,38560766,39369558,38560787,38560786,38560804,39584519,39584517,39369557,
- 39369541,39369564,39369567,39369568,38560752,38560751,38560993,38560899,38560971,39369562,38560824,38560750,
- 38560749,38560748,38560747,38560820,38560825,38560473,38560973,39369562,38560971,38560780,38560782,38560785,
- 38560765,38560764,38560763,38560762,38560761,38560760,38560759,38560755,38560754,38560753,38560795,39584565,
- 39584568,39584570,39584571,39584572,39369536,39369537,39369538,39369539,39369540,38561071,39369542,39369543,
- 39369544,38560797,38560798,38560799,38560805,38560808,38560811,38560793,38560818,39584517,39369556,39369553,
- 35881409,38560792,38560784,39584519,39369723,39369585,35881506,39369701,39369702,39584552,38560801,38560802,
- 38560803,38560999,39369553,39369556,38560801,38560802,38560803,38560999,39369553,39369556,42094657,42094655,
- 42094652,42094651
- ];
- $version = 'v1.3';
- if(date('Y-m-d H:i:s') >= '2024-04-20 00:00:00' || in_array($accountId, $accountList)) {
- $version = 'v3.0';
- }
- return 'v3.0';
- }
- }
|