syh 5 лет назад
Родитель
Сommit
402496b7dc

+ 9 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ByteDanceAdvertiserPostController.java

@@ -175,6 +175,15 @@ public class ByteDanceAdvertiserPostController {
     }
 
     /**
+     * 14:获取流量包数据
+     */
+    @RequestMapping("/advertiser/custom/package/get")
+    public Map<String, Object> flowPackageGet(String accountId) {
+        return advertiserDataService.flowPackageGet(accountId);
+    }
+
+
+    /**
      * 15:上传视频信息
      *
      * @param accountId 本平台广告主id

+ 12 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CreateInternalServiceImpl.java

@@ -341,6 +341,14 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
                     JsonNode node = mapper.readTree(res);
                     campaignId = node.get("data").get("campaign_id").asText();
                     System.out.println(res);
+                } else {
+                    header.put("Accept", "application/json, text/javascript, */*; q=0.01");
+                    header.put("Connection", "keep-alive");
+                    header.put("Host", "ad.oceanengine.com");
+                    header.put("Content-Type", "application/json");
+                    header.put("Origin", "https://ad.oceanengine.com");
+                    header.put("X-Requested-With", "XMLHttpRequest");
+                    header.put("Referer", "https://ad.oceanengine.com/pages/campaign/create.html");
                 }
 
                 Integer itratorNum = requestJson.getInteger("itratorNum");
@@ -353,12 +361,16 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
                         webDriver.get(url2);
                         header.put("Referer", url2);
                         for (Cookie cookie : webDriver.manage().getCookies()) {
+                            if ("csrftoken".equals(cookie.getName())) {
+                                csrftoken = cookie.getValue();
+                            }
                             BasicClientCookie ck = new BasicClientCookie(cookie.getName(), cookie.getValue());
                             ck.setDomain("ad.oceanengine.com");
                             ck.setExpiryDate(cookie.getExpiry());
                             ck.setPath(cookie.getPath());
                             HttpUtils2.cookieStore.addCookie(ck);
                         }
+                        header.put("X-CSRFToken", csrftoken);
                         Map<String, Object> audienceParam = new HashMap<>();
                         audienceParam.put("location_type", 4);
                         audienceParam.put("aweme_account_fans", 0);

+ 22 - 8
module-toutiao/src/main/java/cn/com/ctop/toutiao/entity/ByteDanceUserOrientationTemplate.java

@@ -245,6 +245,8 @@ public class ByteDanceUserOrientationTemplate {
 
     private String adTagStr;
 
+    private String deviceType;
+
     /**
      * status
      */
@@ -266,6 +268,10 @@ public class ByteDanceUserOrientationTemplate {
     }
 
     public ByteDanceUserOrientationTemplate(String userId, JSONObject template) {
+        Long id = template.getLong("id");
+        if (null != id && id != 0) {
+            this.id = id;
+        }
         this.userId = userId;
         String name = template.getString("name");
         if (null != name && !name.equals("")) {
@@ -284,6 +290,14 @@ public class ByteDanceUserOrientationTemplate {
         if (null != ageRange) {
             this.age = ageRange.toJSONString();
         }
+        String deviceType = template.getString("deviceType");
+        if (null != deviceType && !deviceType.trim().equals("")) {
+            this.deviceType = deviceType;
+        }
+        String superiorPopularityType = template.getString("superiorPopularityType");
+        if (null != superiorPopularityType && !"".equals(superiorPopularityType.trim())) {
+            this.superiorPopularityType = superiorPopularityType;
+        }
         //兴趣定向类别
         String intrestType = template.getString("intrestType");
         if (null != intrestType && !intrestType.equals("")) {
@@ -301,8 +315,8 @@ public class ByteDanceUserOrientationTemplate {
                     categoryList.forEach(category -> {
                         JSONObject categoryObject = JSONObject.parseObject(JSONObject.toJSONString(category));
                         adTagStr.add(categoryObject);
-                        Long id = categoryObject.getLong("value");
-                        tags.add(id);
+                        Long tagId = categoryObject.getLong("value");
+                        tags.add(tagId);
                     });
                 }
                 this.adTag = tags.toJSONString();
@@ -347,8 +361,8 @@ public class ByteDanceUserOrientationTemplate {
             cityList.forEach(city -> {
                 JSONObject cityObject = JSONObject.parseObject(JSONObject.toJSONString(city));
                 cityStr.add(cityObject);
-                Long id = cityObject.getLong("value");
-                cityArray.add(id);
+                Long cityId = cityObject.getLong("value");
+                cityArray.add(cityId);
             });
         }
         this.city = cityArray.toJSONString();
@@ -361,8 +375,8 @@ public class ByteDanceUserOrientationTemplate {
             areaList.forEach(area -> {
                 JSONObject areaObject = JSONObject.parseObject(JSONObject.toJSONString(area));
                 areaStr.add(areaObject);
-                Long id = areaObject.getLong("value");
-                areaArray.add(id);
+                Long areaId = areaObject.getLong("value");
+                areaArray.add(areaId);
             });
         }
         this.district = areaArray.toJSONString();
@@ -374,8 +388,8 @@ public class ByteDanceUserOrientationTemplate {
         if (null != intrestTagList && intrestTagList.size() > 0) {
             intrestTagList.forEach(intrestCategory -> {
                 JSONObject intrestCategoryObject = JSONObject.parseObject(JSONObject.toJSONString(intrestCategory));
-                Long id = intrestCategoryObject.getLong("value");
-                intrestTagArray.add(id);
+                Long intrestId = intrestCategoryObject.getLong("value");
+                intrestTagArray.add(intrestId);
             });
         }
         this.interestTags = areaArray.toJSONString();

+ 2 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/service/IByteDanceAdvertiserDataService.java

@@ -45,4 +45,6 @@ public interface IByteDanceAdvertiserDataService {
     JSONObject setUserOrentationData(JSONObject data, ByteDanceUserOrientationTemplate template);
 
     Map<String, Object> getAdvertiserCampaignList(String accountId);
+
+    Map<String, Object> flowPackageGet(String accountId);
 }

+ 86 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -1,5 +1,7 @@
 package cn.com.ctop.toutiao.service.impl;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.common.module.utils.ResultMapUtils;
@@ -11,8 +13,6 @@ import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -632,6 +632,42 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         //根据adId获取公告计划信息
         ByteDanceAdvertisePlan advertisePlan = advertisePlanService.getById(adId);
         data.put("modify_time", advertisePlan.getModifyTime());
+        Integer deliveryType = requestJson.getInteger("deviceType");
+        if (null != deliveryType && deliveryType == 2) {
+            //穿山甲
+            //精选流量包类型
+            String superiorPopularityType = template.getSuperiorPopularityType();
+            if (null != superiorPopularityType && "ZDY".equals(superiorPopularityType)) {
+                JSONArray flowPackage = requestJson.getJSONArray("flowPackage");
+                if (null != flowPackage && flowPackage.size() > 0) {
+                    JSONArray getFlowPackage = new JSONArray();
+                    for (int i = 0; i < flowPackage.size(); i++) {
+                        String flowPackageString = flowPackage.getString(i);
+                        getFlowPackage.add(Long.parseLong(flowPackageString));
+                    }
+                    data.put("flow_package", getFlowPackage);
+                }
+                JSONArray excludeFlowPackage = requestJson.getJSONArray("excludeFlowPackage");
+                if (null != excludeFlowPackage && excludeFlowPackage.size() > 0) {
+                    JSONArray getExcludeFlowPackage = new JSONArray();
+                    for (int i = 0; i < excludeFlowPackage.size(); i++) {
+                        String excludeFlowPackageString = excludeFlowPackage.getString(i);
+                        getExcludeFlowPackage.add(Long.parseLong(excludeFlowPackageString));
+                    }
+                    data.put("exclude_flow_package", getExcludeFlowPackage);
+                }
+            } else {
+                data.put("superior_popularity_type", superiorPopularityType);
+            }
+            //设备类型
+            String deviceType = template.getDeviceType();
+            if (null != deviceType && !"".equals(deviceType) && !"NONE".equals(deviceType)) {
+                JSONArray typeArray = new JSONArray();
+                typeArray.add(deviceType);
+                data.put("device_type", typeArray);
+            }
+        }
+
         JSONArray retargetingTagsExclude = requestJson.getJSONArray("retargetingTagsExclude");
         JSONArray retargetingTagsInclude = requestJson.getJSONArray("retargetingTagsInclude");
         if (null != retargetingTagsExclude && retargetingTagsExclude.size() > 0) {
@@ -805,6 +841,54 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         return resultMap;
     }
 
+    /**
+     * 获取流量包数据接口
+     *
+     * @param accountId
+     * @return
+     */
+    @Override
+    public Map<String, Object> flowPackageGet(String accountId) {
+        JSONObject jsonObject = flowPackageGetJSONObject(accountId);
+        JSONObject result = new JSONObject();
+        Integer code = jsonObject.getInteger("code");
+        String message = jsonObject.getString("message");
+        result.put("code", code);
+        result.put("message", message);
+        if (null == code || code != 0) {
+            result.put("success", false);
+            return result;
+        }
+        JSONArray packageList = jsonObject.getJSONObject("data").getJSONArray("list");
+        if (null != packageList && packageList.size() > 0) {
+            JSONArray packageArray = new JSONArray();
+            for (int i = 0; i < packageList.size(); i++) {
+                JSONObject packageObject = packageList.getJSONObject(i);
+                packageObject.remove("rit");
+                String status = packageObject.getString("status");
+                if (null != status && status.equals("FLOW_PACKAGE_ENABLE")) {
+                    packageArray.add(packageObject);
+                }
+            }
+            result.put("data", packageArray);
+        }
+        result.put("success", true);
+        return result;
+    }
+
+    public JSONObject flowPackageGetJSONObject(String accountId) {
+        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId);
+        // 请求地址
+        String url = "https://ad.toutiao.com/open_api/2/tools/union/flow_package/get/";
+        // 请求参数
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id", token.getAccountId());
+        params.put("page", 1);
+        params.put("page_size", 100);
+        JSONObject resultObject = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
+        return resultObject;
+    }
+
 
     private void getAdvertiserCreativeByPageNumber(String accountId, Integer pageNumber, String ids) {
         CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);