企微短剧业务系统

ReportsOpenApi.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace App\Support\tencentAdSDK;
  3. use App\Log;
  4. use App\Models\TencentAdAuth;
  5. use App\Service\HttpService;
  6. class ReportsOpenApi extends BaseOpenApi
  7. {
  8. /**
  9. * 日报获取
  10. */
  11. public static function dailyReportsGet($data, $retry = 5)
  12. {
  13. $version = self::getAccountVersion($data['account_id']);
  14. $interface = 'daily_reports/get';
  15. $url = 'https://api.e.qq.com/' . $version . '/' . $interface;
  16. $access_token = TencentAdAuth::getAccessToken($data['account_id']);
  17. if (empty($access_token)) return false;
  18. $parameters = [
  19. 'account_id' => $data['account_id'],
  20. 'level' => 'REPORT_LEVEL_ADVERTISER',
  21. 'date_range' => [
  22. 'start_date' => $data['start_date'],
  23. 'end_date' => $data['end_date'],
  24. ],
  25. 'order_by' => [
  26. [
  27. 'sort_field' => 'date',
  28. 'sort_type' => 'ASCENDING'
  29. ]
  30. ],
  31. 'group_by' => [
  32. 'date'
  33. ],
  34. 'fields' => [
  35. 'view_count','view_user_count','date','account_id','cost', 'valid_click_count',
  36. 'follow_count','scan_follow_count','scan_follow_user_count', 'conversions_count',
  37. 'deep_conversions_count'
  38. ],
  39. 'page' => 1,
  40. 'page_size' => 100
  41. ];
  42. do {
  43. $parameters['access_token'] = $access_token;
  44. $parameters['timestamp'] = time();
  45. $parameters['nonce'] = md5(time().rand(10000,99999));
  46. foreach ($parameters as $key => $value) {
  47. if (!is_string($value)) {
  48. $parameters[$key] = json_encode($value);
  49. }
  50. }
  51. $request_url = $url . '?' . http_build_query($parameters);
  52. $res = HttpService::httpGet($request_url);
  53. // 记录日志
  54. Log::logInfo('获取日报数据API:' . $interface, [
  55. 'url' => $request_url,
  56. 'version' => $version,
  57. 'params' => $parameters,
  58. 'response' => $res,
  59. ], 'ReportsOpenApi');
  60. $resArr = json_decode($res, true);
  61. if (!$resArr) {
  62. $resArr = [
  63. 'code' => 666666,
  64. 'message' => '请求失败(自定义)'
  65. ];
  66. }
  67. if($resArr['code'] != 0) {
  68. sleep(1);
  69. }
  70. } while(($resArr['code'] != 0) && (--$retry > 0));
  71. if ($resArr['code'] == 0) {
  72. return self::returnSuccess($resArr['data']);
  73. } else {
  74. return self::returnFail([], $resArr['message']);
  75. }
  76. }
  77. /**
  78. * 日报获取
  79. */
  80. public static function mergeFundTypeFundsGet($accountId, $retry = 5)
  81. {
  82. $version = self::getAccountVersion($accountId);
  83. $interface = 'merge_fund_type_funds/get';
  84. $url = 'https://api.e.qq.com/' . $version . '/' . $interface;
  85. $access_token = TencentAdAuth::getAccessToken($accountId);
  86. if (empty($access_token)) return false;
  87. do {
  88. $parameters['timestamp'] = time();
  89. $parameters['access_token'] = $access_token;
  90. $parameters['nonce'] = md5(time().rand(10000,99999));
  91. $parameters['account_id'] = $accountId;
  92. foreach ($parameters as $key => $value) {
  93. if (!is_string($value)) {
  94. $parameters[$key] = json_encode($value);
  95. }
  96. }
  97. $request_url = $url . '?' . http_build_query($parameters);
  98. $res = HttpService::httpGet($request_url);
  99. // 记录日志
  100. Log::logInfo('获取资金账户数据API:' . $interface, [
  101. 'url' => $request_url,
  102. 'version' => $version,
  103. 'params' => $parameters,
  104. 'response' => $res,
  105. ], 'ReportsOpenApi');
  106. $resArr = json_decode($res, true);
  107. if (!$resArr) {
  108. $resArr = [
  109. 'code' => 666666,
  110. 'message' => '请求失败(自定义)'
  111. ];
  112. }
  113. if($resArr['code'] != 0) {
  114. sleep(10);
  115. }
  116. } while(($resArr['code'] != 0) && (--$retry > 0));
  117. if ($resArr['code'] == 0) {
  118. return self::returnSuccess($resArr['data']);
  119. } else {
  120. return self::returnFail([], $resArr['message']);
  121. }
  122. }
  123. public static function getAccountVersion($accountId) {
  124. $accountList = [
  125. 39369591,39369590,39584550,38560767,38560766,39369558,38560787,38560786,38560804,39584519,39584517,39369557,
  126. 39369541,39369564,39369567,39369568,38560752,38560751,38560993,38560899,38560971,39369562,38560824,38560750,
  127. 38560749,38560748,38560747,38560820,38560825,38560473,38560973,39369562,38560971,38560780,38560782,38560785,
  128. 38560765,38560764,38560763,38560762,38560761,38560760,38560759,38560755,38560754,38560753,38560795,39584565,
  129. 39584568,39584570,39584571,39584572,39369536,39369537,39369538,39369539,39369540,38561071,39369542,39369543,
  130. 39369544,38560797,38560798,38560799,38560805,38560808,38560811,38560793,38560818,39584517,39369556,39369553,
  131. 35881409,38560792,38560784,39584519,39369723,39369585,35881506,39369701,39369702,39584552,38560801,38560802,
  132. 38560803,38560999,39369553,39369556,38560801,38560802,38560803,38560999,39369553,39369556,42094657,42094655,
  133. 42094652,42094651
  134. ];
  135. $version = 'v1.3';
  136. if(date('Y-m-d H:i:s') >= '2024-04-20 00:00:00' || in_array($accountId, $accountList)) {
  137. $version = 'v3.0';
  138. }
  139. return 'v3.0';
  140. }
  141. }