Bläddra i källkod

修改头条数据获取方式

syh 4 år sedan
förälder
incheckning
60037fd8f7

+ 11 - 11
module-common/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java

@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.utils.PropertiesUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
@@ -28,7 +29,12 @@ import java.util.Map;
 @Service
 @Primary
 public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMapper, BindAccountAuth> implements IBindAccountAuthService {
-
+    @Value("${bytedance.appId}")
+    private String bytedanceAppId;
+    @Value("${bytedance.url.callback-url}")
+    private String bytedanceCallbackUrl;
+    @Value("${bytedance.url.auth-prefix}")
+    private String bytedanceAuthUrl;
     @Autowired
     private BindAccountAuthMapper bindAccountAuthMapper;
 
@@ -69,9 +75,6 @@ public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMappe
                     .append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D")
                     .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("kuaishou_config", "kuaishou_callback_url"), "UTF-8"));
         } else if (agentType == 0) {
-
-            // &scope=%5B%22ad_query%22%2C%22ad_manage%22%5D&
-            // &scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D
             sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
                     .append(KuaishouInterfaceConstant.AUTH_PATH)
                     .append ("?app_id=" + PropertiesUtils.getValue("kuaishou_config", "kuaishou_third_appid"))
@@ -79,21 +82,18 @@ public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMappe
                     .append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D")
                     .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("kuaishou_config", "kuaishou_third_callback_url"), "UTF-8"));
         }
-
         return sb.toString();
     }
 
     @Override
     public String getByteDanceCodeUrl(String state) throws UnsupportedEncodingException {
-        StringBuffer sb = new StringBuffer();
-
-
-        sb.append(PropertiesUtils.getValue("bytedance_config", "bytedance_auth_url"))
+        StringBuilder sb = new StringBuilder();
+        sb.append(bytedanceAuthUrl)
                 .append(BytedanceInterfaceConstant.AUTH_PATH)
-                .append("?app_id=" + PropertiesUtils.getValue("bytedance_config", "bytedance_appid"))
+                .append("?app_id=" + bytedanceAppId)
                 .append("&state=" + URLEncoder.encode(state))
                 .append("&material_auth=1")
-                .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("bytedance_config", "bytedance_callback_url"), "UTF-8"));
+                .append("&redirect_uri=" + URLEncoder.encode(bytedanceCallbackUrl, "UTF-8"));
         return sb.toString();
     }
 

+ 25 - 28
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
@@ -23,6 +24,15 @@ import java.util.*;
 @Service
 @Primary
 public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserDataService {
+    @Value("${bytedance.appId}")
+    private String bytedanceAppId;
+    @Value("${bytedance.secret}")
+    private String bytedanceSecret;
+    @Value("${bytedance.url.api-prefix}")
+    private String bytedanceApiUrl;
+    @Value("${bytedance.url.ad-get}")
+    private String bytedanceAdGetUrl;
+
     @Autowired
     private ICtopOauthTokenService tokenService;
     @Autowired
@@ -85,14 +95,11 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
     @Override
     public Map<String, Object> getAdvertiserInfo(String accountId, String token) {
         Map<String, Object> resultMap = new HashMap<>();
-        //   CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);
-        //2: 根据token以及用户id获取用户信息数据
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_advertiser_info");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_advertiser_info");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", token);
         TreeMap<String, Object> params = new TreeMap<>();
-        //TODO jsonArray
         params.put("advertiser_ids", "[" + accountId + "]");
         String result = HttpUtils.httpGetRequest(url, headers, params);
         JSONObject jsonObject = JSONObject.parseObject(result);
@@ -125,18 +132,13 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
 
     @Override
     public JSONArray advertiserList(String token) {
-        Map<String, Object> resultMap = new HashMap<>();
-        //   CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);
-        //2: 根据token以及用户id获取用户信息数据
         String url = "https://ad.oceanengine.com/open_api/oauth2/advertiser/get/";
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         TreeMap<String, Object> params = new TreeMap<>();
         params.put("access_token", token);
-        String appId = PropertiesUtils.getValue("bytedance_config", "bytedance_appid");
-        String secret = PropertiesUtils.getValue("bytedance_config", "bytedance_secret");
-        params.put("secret", secret);
-        params.put("app_id", appId);
+        params.put("secret", bytedanceSecret);
+        params.put("app_id", bytedanceAppId);
         String result = HttpUtils.httpGetRequest(url, headers, params);
         JSONObject jsonObject = JSONObject.parseObject(result);
         log.info("返回信息:{}", jsonObject);
@@ -147,12 +149,9 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
                 JSONArray listArr = dataJson.getJSONArray("list");
                 if (!Check.isNull(listArr)) {
                     return listArr;
-
                 }
             }
-
         }
-
         return new JSONArray();
     }
 
@@ -161,7 +160,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         JSONArray getIds = new JSONArray();
         getIds.add(id);
         // 请求地址
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
+        String url = bytedanceApiUrl + bytedanceAdGetUrl;
         // 请求参数
         Map<String, Object> filtering = new HashMap<>();
         filtering.put("ids", getIds);
@@ -203,7 +202,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         }
 
         // 请求地址
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
         // 请求参数
         Map<String, Object> filtering = new HashMap<>();
         if (null != getIds && getIds.size() > 0) {
@@ -257,7 +256,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         Map<String, Object> resultMap = new HashMap<>();
         CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);
         //2: 根据token以及用户id获取用户信息数据
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", cTopOauthToken.getAccessToken());
@@ -291,7 +290,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         Map<String, Object> resultMap = new HashMap<>();
         CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);
         //2: 根据token以及用户id获取用户信息数据
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_creative_material_get");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_creative_material_get");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", cTopOauthToken.getAccessToken());
@@ -351,13 +350,11 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
 
 
     public JSONObject getCreative(CtopOauthToken token, String date, int pageNumber) {
-        final Long advertiser_id = token.getAccountId();  //操作的广告主id
         // 请求地址
         String url = "https://ad.oceanengine.com/open_api/2/creative/get/";
-
         // 请求参数
         JSONObject param = new JSONObject();
-        param.put("advertiser_id", advertiser_id);
+        param.put("advertiser_id", token.getAccountId());
         param.put("page", pageNumber);
         param.put("page_size", 100);
         if (null != date && !"".equals(date.trim())) {
@@ -379,7 +376,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
             }
         }
         //2: 根据token以及用户id获取用户信息数据
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_status");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_status");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", token.getAccessToken());
@@ -431,7 +428,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
             }
         }
         //2: 根据token以及用户id获取用户信息数据
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_bid");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_bid");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", token.getAccessToken());
@@ -482,7 +479,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
             }
         }
         //2: 根据token以及用户id获取用户信息数据
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_budget");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_budget");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", token.getAccessToken());
@@ -533,7 +530,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
             ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_PARAM_ERROR);
             return resultMap;
         }
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_dmp_custom_audience_select");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_dmp_custom_audience_select");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", token.getAccessToken());
@@ -573,7 +570,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
     public Map<String, Object> getAdvertiserCampaignList(String accountId) {
         Map<String, Object> resultMap = new HashMap<>();
         CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
+        String url = bytedanceApiUrl + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", cTopOauthToken.getAccessToken());
@@ -751,10 +748,10 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
     }
 
 
+    @Override
     public void getBytedancePlanList(String accountId, String accessToken, int pageNum, String createDate, String updateDate) {
-
         // 请求地址
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
+        String url = bytedanceApiUrl + bytedanceAdGetUrl;
         // 请求参数
         Map<String, Object> filtering = new HashMap<>();
         if (null != createDate && !"".equals(createDate)) {