|
|
@@ -181,7 +181,11 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
String accessToken = obj.getString("access_token");
|
|
|
String instanceId = obj.getString("mini_instance_id");
|
|
|
List<JSONObject> iapVideoDouyinList = iapVideoList.stream().filter(obj1 -> "1".equals(obj1.getString("platform_type"))).collect(Collectors.toList());
|
|
|
+ System.out.println(">>查找小程序付费推广链接: 小程序id: "+instanceId);
|
|
|
+ long st = System.currentTimeMillis();
|
|
|
Map<String, String> albumIdToLinkMap = getBytedancePlayletPromoteLink(advertiserId, accessToken, instanceId, iapVideoDouyinList, errorBlanket);
|
|
|
+ long ed = System.currentTimeMillis();
|
|
|
+ System.out.println(">>查找小程序"+instanceId+"付费推广链接完成, 耗时: " + (ed-st) + "ms");
|
|
|
advertiserToLinkMap.put(advertiserId, albumIdToLinkMap);
|
|
|
}
|
|
|
|
|
|
@@ -455,29 +459,39 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
* @return map key: album_id, value: 对应的字节小程序推广链接,sslocal开头
|
|
|
*/
|
|
|
private Map<String, String> getBytedancePlayletPromoteLink(String advertiserId, String accessToken, String instanceId, List<JSONObject> requests, Set<String> errorBlanket){
|
|
|
- JSONArray playletDetailInfo = getPlayletDetail(advertiserId, accessToken, instanceId, errorBlanket,1);
|
|
|
- if (playletDetailInfo == null || playletDetailInfo.isEmpty()){
|
|
|
- return null;
|
|
|
- }
|
|
|
List<String> reqAlbumIds = requests.stream()
|
|
|
.map(obj -> obj.getString("album_id"))
|
|
|
.collect(Collectors.toList());
|
|
|
Map<String, String> res = new HashMap<>(reqAlbumIds.size());
|
|
|
|
|
|
- for (int i = 0; i < playletDetailInfo.size(); i++) {
|
|
|
- JSONObject obj = playletDetailInfo.getJSONObject(i);
|
|
|
- String startParam = obj.getString("start_param");
|
|
|
- for (String album_id : reqAlbumIds){
|
|
|
- if (startParam.contains("tt_album_id="+album_id)){
|
|
|
- res.put(album_id, obj.getString("link"));
|
|
|
+ List<JSONObject> unfound = new ArrayList<>(requests);
|
|
|
+ for (int page=1; page<60; page++){
|
|
|
+ JSONArray playletDetailInfo = getPlayletDetail(advertiserId, accessToken, instanceId, errorBlanket,1);
|
|
|
+ if (playletDetailInfo == null || playletDetailInfo.isEmpty()){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < playletDetailInfo.size(); i++) {
|
|
|
+ JSONObject obj = playletDetailInfo.getJSONObject(i);
|
|
|
+ String startParam = obj.getString("start_param");
|
|
|
+ for (String album_id : reqAlbumIds){
|
|
|
+ if (startParam.contains("tt_album_id="+album_id)){
|
|
|
+ res.put(album_id, obj.getString("link"));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ unfound = requests.stream()
|
|
|
+ .filter(obj -> !res.containsKey(obj.getString("album_id")))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (unfound.isEmpty()){
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- List<JSONObject> unfound = requests.stream()
|
|
|
- .filter(obj -> !res.containsKey(obj.getString("album_id")))
|
|
|
- .collect(Collectors.toList());
|
|
|
+
|
|
|
if (unfound.isEmpty()){
|
|
|
+ System.out.println("所有剧目都找到了对应的推广链接");
|
|
|
return res;
|
|
|
+ }else {
|
|
|
+ System.out.println("有" + unfound.size() + "个剧目没有找到对应的推广链接,准备新建链接");
|
|
|
}
|
|
|
//没有找到对应的album_id,需要新建链接
|
|
|
for (JSONObject obj : unfound){
|
|
|
@@ -552,7 +566,7 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONArray getPlayletDetail(String advertiserId, String accessToken, String instanceId, Set<String> errorBlanket, Integer pageNum) {
|
|
|
- if (pageNum >50){
|
|
|
+ if (pageNum >60){
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
String getPlayletDetailUrl = "https://api.oceanengine.com/open_api/v3.0/tools/asset_link/list/";
|
|
|
@@ -578,13 +592,16 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
return new JSONArray();
|
|
|
}else {
|
|
|
JSONArray list = jsonObject.getJSONObject("data").getJSONArray("list");
|
|
|
- JSONObject page_info = jsonObject.getJSONObject("data").getJSONObject("page_info");
|
|
|
- int total_page = page_info.getIntValue("total_page");
|
|
|
- if (total_page > pageNum){
|
|
|
- //递归获取下一页
|
|
|
- JSONArray nextPage = getPlayletDetail(advertiserId, accessToken, instanceId, errorBlanket, pageNum + 1);
|
|
|
- list.addAll(nextPage);
|
|
|
+ if (list.size() > 0){
|
|
|
+ return list;
|
|
|
}
|
|
|
+// JSONObject page_info = jsonObject.getJSONObject("data").getJSONObject("page_info");
|
|
|
+// int total_page = page_info.getIntValue("total_page");
|
|
|
+// if (total_page > pageNum){
|
|
|
+// //递归获取下一页
|
|
|
+// JSONArray nextPage = getPlayletDetail(advertiserId, accessToken, instanceId, errorBlanket, pageNum + 1);
|
|
|
+// list.addAll(nextPage);
|
|
|
+// }
|
|
|
return list;
|
|
|
}
|
|
|
}
|