123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace App\Support\tencentAdSDK;
- use App\Log;
- use App\Models\TencentAdAuth;
- use App\Service\HttpService;
- class AdvertiserOpenApi extends BaseOpenApi
- {
- /**
- * 日报获取
- */
- public static function advertiserSpecificationGet($accountId, $retry = 5)
- {
- $interface = 'wechat_advertiser_specification/get';
- $url = 'https://api.e.qq.com/v1.3/' . $interface;
- $access_token = TencentAdAuth::getAccessToken($accountId);
- if (empty($access_token)) return false;
- $common_parameters = [
- 'access_token' => $access_token,
- 'timestamp' => time(),
- 'nonce' => md5(uniqid('', true))
- ];
- $parameters = [
- 'account_id' => $accountId,
- 'fields' => [
- 'wechat_account_id',
- 'wechat_account_name',
- 'corporation_name'
- ],
- 'page' => 1,
- 'page_size' => 10,
- ];
- $parameters = array_merge($common_parameters, $parameters);
- foreach ($parameters as $key => $value) {
- if (!is_string($value)) {
- $parameters[$key] = json_encode($value);
- }
- }
- $request_url = $url . '?' . http_build_query($parameters);
- do {
- $res = HttpService::httpGet($request_url);
- // 记录日志
- Log::logInfo('获取公众号详情信息API:' . $interface, [
- 'url' => $request_url,
- 'params' => $parameters,
- 'response' => $res,
- ], 'AdvertiserOpenApi');
- $resArr = json_decode($res, true);
- if (!$resArr) {
- $resArr = [
- 'code' => 666666,
- 'message' => '请求失败(自定义)'
- ];
- }
- } while(($resArr['code'] != 0) && (--$retry > 0));
- if ($resArr['code'] == 0) {
- return self::returnSuccess($resArr['data']);
- } else {
- return self::returnFail([], $resArr['message']);
- }
- }
- public static function getOrganizationAccount($accountId, $cursor, $retry = 0) {
- $interface = 'organization_account_relation/get';
- $url = 'https://api.e.qq.com/v3.0/' . $interface;
- $accessToken = TencentAdAuth::getAccessToken($accountId);
- if (empty($accessToken)) {
- Log::logError('获取accessToken失败', ['account_id' => $accountId], 'getOrganizationAccount');
- return false;
- }
- $parameters = array (
- 'access_token' => $accessToken,
- 'timestamp' => time(),
- 'nonce' => md5(uniqid('', true)),
- 'pagination_mode' => 'PAGINATION_MODE_CURSOR',
- "cursor" => $cursor,
- "page_size" => 100
- );
- foreach ($parameters as $key => $value) {
- if (!is_string($value)) {
- $parameters[$key] = json_encode($value);
- }
- }
- $request_url = $url . '?' . http_build_query($parameters);
- $response = HttpService::httpGet($request_url);
- if(empty($response) && $retry < 5) {
- sleep(1);
- $retry++;
- return self::getOrganizationAccount($accountId, $cursor, $retry);
- }
- // 记录日志
- Log::logInfo('获取业务单元下的投放账户:' . $interface, [
- 'url' => $request_url,
- 'params' => $parameters,
- 'response' => $response,
- ], 'getOrganizationAccount');
- return json_decode($response, true);
- }
- }
|