|
|
@@ -17,7 +17,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.Instant;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -58,6 +57,11 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public List<Long> queryPageAdvertiserIds() {
|
|
|
+ return bytedanceCdpProjectMapper.queryPageAdvertiserIds();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public boolean delErrApps(String type) {
|
|
|
return bytedanceCdpProjectMapper.delErrApps(type);
|
|
|
}
|
|
|
@@ -73,6 +77,79 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void getpromotionList(Long advertiserId, String date) {
|
|
|
+ this.getpromotionListVo(advertiserId, date, 1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getpromotionListVo(Long advertiserId, String date, Integer page, int count) {
|
|
|
+ try {
|
|
|
+ log.info("执行id:{}", advertiserId);
|
|
|
+ boolean nextPage = false;
|
|
|
+ String accessToken = tokenMapper.onlyGetToken(advertiserId);
|
|
|
+ if (Check.isNull(accessToken)) {
|
|
|
+ log.error("账户({})查询token失败", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
+ filtering.put("promotion_modify_time", date);
|
|
|
+ filtering.put("status_first", "PROMOTION_STATUS_ALL");
|
|
|
+
|
|
|
+ params.put("filtering", filtering);
|
|
|
+ params.put("page", page);
|
|
|
+ params.put("page_size", 20);//最大20
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/promotion/list/";
|
|
|
+ String results = HttpUtils.httpGet(url, params, HttpUtils.postMHeaders(accessToken));
|
|
|
+ JSONObject obj = JSONObject.parseObject(results);
|
|
|
+ if (!Check.isNull(obj)) {
|
|
|
+ Integer code = obj.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
+ Integer totalPage = data.getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (totalPage != 0 && totalPage > data.getJSONObject("page_info").getInteger("page")) {
|
|
|
+ nextPage = true;
|
|
|
+ }
|
|
|
+ JSONArray array = data.getJSONArray("list");
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ checkPromotionInfo(array.getJSONObject(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(array))
|
|
|
+ if (bytedanceCdpProjectMapper.replaceBytedancePromotionList(array) > 0)
|
|
|
+ log.info("---账户({})广告更新成功", advertiserId);
|
|
|
+ } else {
|
|
|
+ //40100请求超频
|
|
|
+ if (40100 == code && count <= 5) {
|
|
|
+ Thread.sleep(800);
|
|
|
+ getpromotionListVo(advertiserId, date, page, count + 1);
|
|
|
+ } else {
|
|
|
+ log.error("获取广告列表失败(url:{}),入参:{}\n结果:{}", url, JSONObject.toJSONString(params), obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (nextPage) {
|
|
|
+ getpromotionListVo(advertiserId, date, page + 1, 1);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkPromotionInfo(JSONObject entity) {
|
|
|
+ JSONObject promotionMaterials = entity.getJSONObject("promotion_materials");
|
|
|
+ if (!Check.isNull(promotionMaterials)) {
|
|
|
+ JSONObject miniProgramInfo = promotionMaterials.getJSONObject("mini_program_info");
|
|
|
+ if (!Check.isNull(miniProgramInfo)) {
|
|
|
+ entity.put("params", miniProgramInfo.getString("params"));
|
|
|
+ entity.put("app_id", miniProgramInfo.getString("app_id"));
|
|
|
+ entity.put("url", miniProgramInfo.getString("url"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void getProjectList(Long advertiserId, String date) {
|
|
|
this.getProjectListVo(advertiserId, null, date, 1, 1);
|
|
|
// this.getProjectListVo(advertiserId, "del", date, 1, 1);
|
|
|
@@ -140,7 +217,6 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
public void getByteAppInfo(Long advertiserId) {
|
|
|
this.getByteAppInfoVo(advertiserId, "CREATE_ONLY", 1, 1);
|
|
|
this.getByteAppInfoVo(advertiserId, "SHARE_ONLY", 1, 1);
|
|
|
- this.getByteAppLinkInfo(advertiserId);
|
|
|
}
|
|
|
|
|
|
private void getByteAppInfoVo(Long advertiserId, String searchType, Integer page, int count) {
|
|
|
@@ -412,6 +488,92 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getAdqWechatPages(Long advertiserId) {
|
|
|
+ try {
|
|
|
+ String accessToken = tokenMapper.onlyGetADQToken(advertiserId);
|
|
|
+ if (Check.isNull(accessToken)) {
|
|
|
+ log.error("账户({})accessToken is null", advertiserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.getAdqWechatPagesVo(advertiserId, accessToken, 1, true, 1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("账户({})获取原生落地页异常", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getAdqWechatPagesVo(Long accountId, String accessToken, Integer page, Boolean isDeleted, int count) throws Exception {
|
|
|
+ boolean nextPage = false;
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ long timestamp = Instant.now().getEpochSecond();
|
|
|
+ param.put("timestamp", String.valueOf(timestamp));
|
|
|
+ param.put("nonce", RandomStringGenerator.generateRandomString(32));
|
|
|
+ param.put("access_token", accessToken);
|
|
|
+ param.put("account_id", accountId);
|
|
|
+ param.put("page", page);
|
|
|
+ param.put("page_size", 100);
|
|
|
+ JSONArray filtering = new JSONArray();
|
|
|
+ JSONObject greObj = new JSONObject();
|
|
|
+ greObj.put("field", "page_type");
|
|
|
+ greObj.put("operator", "EQUALS");
|
|
|
+ greObj.put("values", "PAGE_TYPE_WECHAT_CANVAS");
|
|
|
+ filtering.add(greObj);
|
|
|
+
|
|
|
+// param.put("filtering", filtering);
|
|
|
+ String result = HttpUtils.httpGet("https://api.e.qq.com/v3.0/wechat_pages/get", param, new HashMap<>());
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(obj)) {
|
|
|
+ if (0 == obj.getInteger("code")) {
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONObject pageInfo = data.getJSONObject("page_info");
|
|
|
+ Integer totalPage = pageInfo.getInteger("total_page");
|
|
|
+ if (totalPage != 0 && totalPage > pageInfo.getInteger("page")) {
|
|
|
+ nextPage = true;
|
|
|
+ }
|
|
|
+ JSONArray array = data.getJSONArray("list");
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject object = array.getJSONObject(i);
|
|
|
+ getPageAppId(object);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(array))
|
|
|
+ if (bytedanceCdpProjectMapper.replaceAdqDynamicPages(array, accountId) > 0)
|
|
|
+ log.info("---账户({})广点通落地页更新成功", accountId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (count <= 4) {
|
|
|
+ Thread.sleep(500);
|
|
|
+ getAdqWechatPagesVo(accountId, accessToken, page, isDeleted, count + 1);
|
|
|
+ } else {
|
|
|
+ log.error("账户({})获取动态创意失败,入参:{}\n,结果:{}", accountId, JSONObject.toJSONString(param), obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (nextPage) {
|
|
|
+ getAdqWechatPagesVo(accountId, accessToken, page + 1, isDeleted, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getPageAppId(JSONObject object) {
|
|
|
+ JSONArray pageElementsSpecList = object.getJSONArray("page_elements_spec_list");
|
|
|
+ if (!Check.isNull(pageElementsSpecList)) {
|
|
|
+ for (int i = 0; i < pageElementsSpecList.size(); i++) {
|
|
|
+ JSONObject obj = pageElementsSpecList.getJSONObject(i);
|
|
|
+ JSONObject buttonSpec = obj.getJSONObject("button_spec");
|
|
|
+ if (buttonSpec != null) {
|
|
|
+ JSONObject miniProgramSpec = buttonSpec.getJSONObject("mini_program_spec");
|
|
|
+ if (!Check.isNull(miniProgramSpec)) {
|
|
|
+ object.put("mini_program_id", miniProgramSpec.getString("mini_program_id"));
|
|
|
+ object.put("mini_program_path", miniProgramSpec.getString("mini_program_path"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void getAppId(JSONObject object) {
|
|
|
JSONObject creativeComponents = object.getJSONObject("creative_components");
|
|
|
if (!Check.isNull(creativeComponents)) {
|
|
|
@@ -427,6 +589,7 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
JSONObject wechatMiniProgramSpec = pageSpec.getJSONObject("wechat_mini_program_spec");
|
|
|
if (!Check.isNull(wechatMiniProgramSpec)) {
|
|
|
object.put("mini_program_id", wechatMiniProgramSpec.getString("mini_program_id"));
|
|
|
+ object.put("mini_program_path", wechatMiniProgramSpec.getString("mini_program_path"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -445,6 +608,11 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
JSONObject wechatMiniProgramSpec = pageSpec.getJSONObject("wechat_mini_program_spec");
|
|
|
if (!Check.isNull(wechatMiniProgramSpec)) {
|
|
|
object.put("mini_program_id", wechatMiniProgramSpec.getString("mini_program_id"));
|
|
|
+ object.put("mini_program_path", wechatMiniProgramSpec.getString("mini_program_path"));
|
|
|
+ }
|
|
|
+ JSONObject officialSpec = pageSpec.getJSONObject("wechat_canvas_spec");
|
|
|
+ if (!Check.isNull(officialSpec)) {
|
|
|
+ object.put("page_id", officialSpec.getLong("page_id"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -462,6 +630,11 @@ public class BytedanceCdpProjectServiceImpl implements IBytedanceCdpProjectServi
|
|
|
JSONObject wechatMiniProgramSpec = pageSpec.getJSONObject("wechat_mini_program_spec");
|
|
|
if (!Check.isNull(wechatMiniProgramSpec)) {
|
|
|
object.put("mini_program_id", wechatMiniProgramSpec.getString("mini_program_id"));
|
|
|
+ object.put("mini_program_path", wechatMiniProgramSpec.getString("mini_program_path"));
|
|
|
+ }
|
|
|
+ JSONObject officialSpec = pageSpec.getJSONObject("wechat_canvas_spec");
|
|
|
+ if (!Check.isNull(officialSpec)) {
|
|
|
+ object.put("page_id", officialSpec.getLong("page_id"));
|
|
|
}
|
|
|
}
|
|
|
}
|