|
@@ -5,6 +5,7 @@ import cn.com.ctop.job.bytedance.data.service.IBytedanceProductUpdateService;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
import cn.com.ctop.job.bytedance.utils.FeishuRobotUtil;
|
|
import cn.com.ctop.job.bytedance.utils.FeishuRobotUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -12,6 +13,7 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -20,7 +22,8 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
@Resource
|
|
@Resource
|
|
|
BytedanceProductUpdateMapper bytedanceProductUpdateMapper;
|
|
BytedanceProductUpdateMapper bytedanceProductUpdateMapper;
|
|
|
|
|
|
|
|
- public static final String APP_ID = "ttba3acc87250c6f7901";
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //商品上传结果通知群
|
|
|
public static final String HOOK_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/92e2445e-76df-44fb-8f61-f55ac94f49bd";
|
|
public static final String HOOK_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/92e2445e-76df-44fb-8f61-f55ac94f49bd";
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -33,16 +36,15 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
iaaProductUpdate(errors);
|
|
iaaProductUpdate(errors);
|
|
|
log.info("免费商品库更新完成");
|
|
log.info("免费商品库更新完成");
|
|
|
if (!Check.isNull(errors)){
|
|
if (!Check.isNull(errors)){
|
|
|
-// List<String> users = Arrays.asList(
|
|
|
|
|
-// "44fbaed6" //zhaotx
|
|
|
|
|
-// ,"58e7a98a" //xsq
|
|
|
|
|
-// );
|
|
|
|
|
|
|
+ errors.add(0, "商品上传报错通知");
|
|
|
FeishuRobotUtil.sendTextToWebhook(StringUtils.join(errors, "\n"), HOOK_URL);
|
|
FeishuRobotUtil.sendTextToWebhook(StringUtils.join(errors, "\n"), HOOK_URL);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化新的字节小程序; 新增字节用的商品库时调用
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public void initNew(){
|
|
public void initNew(){
|
|
|
List<JSONObject> iapPlatformList = bytedanceProductUpdateMapper.getIAPPlatformList();
|
|
List<JSONObject> iapPlatformList = bytedanceProductUpdateMapper.getIAPPlatformList();
|
|
@@ -51,6 +53,18 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
initNew(iapPlatformList);
|
|
initNew(iapPlatformList);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void test() throws Exception {
|
|
|
|
|
+// uploadAlbum(31084L, 1742489802322972L, "d22b45ce9033303d22c5f34abcd4600811b18d88");
|
|
|
|
|
+// uploadAlbum();
|
|
|
|
|
+// Thread.sleep(1000);
|
|
|
|
|
+ refreshAlbumStatus();
|
|
|
|
|
+// List<String> errors = new ArrayList<>();
|
|
|
|
|
+// iapProductUpdate(errors);
|
|
|
|
|
+// System.out.println(errors);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void initNew(List<JSONObject> platformList) {
|
|
public void initNew(List<JSONObject> platformList) {
|
|
|
//为广告主账户创建新的字节小程序
|
|
//为广告主账户创建新的字节小程序
|
|
|
//step1 查询表里广告主是否都有自己的字节小程序、
|
|
//step1 查询表里广告主是否都有自己的字节小程序、
|
|
@@ -96,11 +110,15 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 付费短剧更新
|
|
|
|
|
+ * @param errorBlanket
|
|
|
|
|
+ */
|
|
|
private void iapProductUpdate(List<String> errorBlanket){
|
|
private void iapProductUpdate(List<String> errorBlanket){
|
|
|
//IAP
|
|
//IAP
|
|
|
- List<JSONObject> iapPlatformList = bytedanceProductUpdateMapper.getIAPPlatformList();
|
|
|
|
|
- List<JSONObject> iapVideoList = bytedanceProductUpdateMapper.getIAPVideoList();
|
|
|
|
|
- List<JSONObject> iapProductTypeEnums = bytedanceProductUpdateMapper.getIAPProductTypeEnums();
|
|
|
|
|
|
|
+ List<JSONObject> iapPlatformList = bytedanceProductUpdateMapper.getIAPPlatformList(); //商品库列表
|
|
|
|
|
+ List<JSONObject> iapVideoList = bytedanceProductUpdateMapper.getIAPVideoList(); //剧目列表
|
|
|
|
|
+ List<JSONObject> iapProductTypeEnums = bytedanceProductUpdateMapper.getIAPProductTypeEnums(); //商品类型
|
|
|
Map<String, Map<String, String>> advertiserToLinkMap = new HashMap<>();
|
|
Map<String, Map<String, String>> advertiserToLinkMap = new HashMap<>();
|
|
|
|
|
|
|
|
for (JSONObject obj : iapPlatformList){
|
|
for (JSONObject obj : iapPlatformList){
|
|
@@ -112,7 +130,8 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
System.out.println("没有找到字节小程序的实例ID: " + advertiserId);
|
|
System.out.println("没有找到字节小程序的实例ID: " + advertiserId);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- Map<String, String> albumIdToLinkMap = getBytedancePlayletPromoteLink(advertiserId, accessToken, instanceId, iapVideoList, errorBlanket);
|
|
|
|
|
|
|
+ List<JSONObject> iapVideoDouyinList = iapVideoList.stream().filter(obj1 -> "1".equals(obj1.getString("platform_type"))).collect(Collectors.toList());
|
|
|
|
|
+ Map<String, String> albumIdToLinkMap = getBytedancePlayletPromoteLink(advertiserId, accessToken, instanceId, iapVideoDouyinList, errorBlanket);
|
|
|
advertiserToLinkMap.put(advertiserId, albumIdToLinkMap);
|
|
advertiserToLinkMap.put(advertiserId, albumIdToLinkMap);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -129,69 +148,106 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
System.out.println("\n\n\n");
|
|
System.out.println("\n\n\n");
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ Integer platformType1 = obj.getInteger("platform_type");
|
|
|
|
|
+
|
|
|
for (JSONObject platform : iapPlatformList) {
|
|
for (JSONObject platform : iapPlatformList) {
|
|
|
- String url = "https://ad.oceanengine.com/open_api/2/dpa/product/update/";
|
|
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
|
- headers.put("Access-Token", platform.getString("access_token"));
|
|
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
|
|
-
|
|
|
|
|
- JSONObject request = new JSONObject();
|
|
|
|
|
- String album_id = obj.getString("album_id");
|
|
|
|
|
- request.put("product_id", obj.getLongValue("album_id"));
|
|
|
|
|
- JSONObject product_info = new JSONObject();
|
|
|
|
|
- product_info.put("name", obj.getString("name"));
|
|
|
|
|
- product_info.put("image_url", obj.getString("img"));
|
|
|
|
|
- product_info.put("status", 1);
|
|
|
|
|
- product_info.put("stock", 1);
|
|
|
|
|
- JSONObject productType = iapProductTypeMap.get(theme);
|
|
|
|
|
- product_info.put("first_category_id", productType.getString("first_type_id"));
|
|
|
|
|
- product_info.put("sub_category_id", productType.getString("second_type_id"));
|
|
|
|
|
- product_info.put("third_category_id", productType.getString("third_type_id"));
|
|
|
|
|
- product_info.put("first_category", productType.getString("first_type_name"));
|
|
|
|
|
- product_info.put("sub_category", productType.getString("second_type_name"));
|
|
|
|
|
- product_info.put("third_category", productType.getString("third_type_name"));
|
|
|
|
|
- request.put("advertiser_id", platform.getLongValue("advertiser_id"));
|
|
|
|
|
- request.put("platform_id", platform.getLongValue("platform_id"));
|
|
|
|
|
- JSONObject profession = new JSONObject();
|
|
|
|
|
- profession.put("copyright_owner", obj.getString("copyright_owner"));
|
|
|
|
|
- profession.put("playlet_gender", "3");
|
|
|
|
|
- profession.put("playlet_num", obj.getString("playlet_num"));
|
|
|
|
|
- profession.put("playlet_duration", obj.getString("playlet_duration"));
|
|
|
|
|
- profession.put("start_pay_playlet", obj.getString("start_pay_playlet"));
|
|
|
|
|
- if (platform.getDouble("max_charge") > 0.0){
|
|
|
|
|
- profession.put("max_charge", platform.getString("max_charge"));
|
|
|
|
|
- }
|
|
|
|
|
- if (platform.getDouble("min_charge") > 0.0){
|
|
|
|
|
- profession.put("min_charge", platform.getString("min_charge"));
|
|
|
|
|
|
|
+ Integer platformType2 = platform.getInteger("platform_type");
|
|
|
|
|
+ if (!Objects.equals(platformType1, platformType2)){
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- if (platform.getDouble("recommended_charge") > 0.0){
|
|
|
|
|
- profession.put("recommended_charge", platform.getString("recommended_charge"));
|
|
|
|
|
|
|
+ int rescode = uploadIapProduct(platform, obj, advertiserToLinkMap, errorBlanket, iapProductTypeMap.get(theme));
|
|
|
|
|
+ if (rescode!= 0){
|
|
|
|
|
+// return;
|
|
|
}
|
|
}
|
|
|
- profession.put("has_paid_content", "1");
|
|
|
|
|
- profession.put("has_motivation_content", "2");
|
|
|
|
|
- profession.put("membership_types", platform.getString("membership_types"));
|
|
|
|
|
- profession.put("micro_app_link", advertiserToLinkMap.get(platform.getString("advertiser_id")).get(album_id));
|
|
|
|
|
- //price_info
|
|
|
|
|
- JSONObject price_info = new JSONObject();
|
|
|
|
|
- price_info.put("price", platform.getDoubleValue("single_price"));
|
|
|
|
|
- product_info.put("price_info", price_info);
|
|
|
|
|
- product_info.put("profession", profession);
|
|
|
|
|
- request.put("product_info", product_info);
|
|
|
|
|
|
|
+// System.out.println("\n\n\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 付费短剧更新
|
|
|
|
|
+ * @param platform 商品库信息
|
|
|
|
|
+ * @param album 剧信息
|
|
|
|
|
+ * @param advertiserToLinkMap
|
|
|
|
|
+ * @param errorBlanket
|
|
|
|
|
+ * @param productType 商品短剧类型
|
|
|
|
|
+ */
|
|
|
|
|
+ private int uploadIapProduct(JSONObject platform, JSONObject album,
|
|
|
|
|
+ Map<String, Map<String, String>> advertiserToLinkMap,
|
|
|
|
|
+ List<String> errorBlanket,
|
|
|
|
|
+ JSONObject productType){
|
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/dpa/product/update/";
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", platform.getString("access_token"));
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
|
|
|
-// System.out.println("请求地址:" + url);
|
|
|
|
|
-// System.out.println("请求头:" + headers);
|
|
|
|
|
-// System.out.println("请求参数:" + request.toJSONString());
|
|
|
|
|
- String res = HttpUtils.httpPostRequest(url, request, headers);
|
|
|
|
|
-// System.out.println(res);
|
|
|
|
|
- JSONObject btRes = JSONObject.parseObject(res);
|
|
|
|
|
- int code = btRes.getIntValue("code");
|
|
|
|
|
- if (code != 0){
|
|
|
|
|
- errorBlanket.add("上传付费商品失败,code: " + code + ", msg: " + btRes.getString("message")+", 关联剧目: " + obj.getString("name"));
|
|
|
|
|
- }
|
|
|
|
|
-// System.out.println("\n\n\n");
|
|
|
|
|
|
|
+ JSONObject request = new JSONObject();
|
|
|
|
|
+ String album_id = album.getString("album_id");
|
|
|
|
|
+ request.put("product_id", album.getLongValue("album_id"));
|
|
|
|
|
+ JSONObject product_info = new JSONObject();
|
|
|
|
|
+ product_info.put("name", album.getString("name"));
|
|
|
|
|
+ product_info.put("image_url", album.getString("img"));
|
|
|
|
|
+ product_info.put("status", 1);
|
|
|
|
|
+ product_info.put("stock", 1);
|
|
|
|
|
+ product_info.put("first_category_id", productType.getString("first_type_id"));
|
|
|
|
|
+ product_info.put("sub_category_id", productType.getString("second_type_id"));
|
|
|
|
|
+ product_info.put("third_category_id", productType.getString("third_type_id"));
|
|
|
|
|
+ product_info.put("first_category", productType.getString("first_type_name"));
|
|
|
|
|
+ product_info.put("sub_category", productType.getString("second_type_name"));
|
|
|
|
|
+ product_info.put("third_category", productType.getString("third_type_name"));
|
|
|
|
|
+ request.put("advertiser_id", platform.getLongValue("advertiser_id"));
|
|
|
|
|
+ request.put("platform_id", platform.getLongValue("platform_id"));
|
|
|
|
|
+ JSONObject profession = new JSONObject();
|
|
|
|
|
+ profession.put("copyright_owner", album.getString("copyright_owner"));
|
|
|
|
|
+ profession.put("playlet_gender", "3");
|
|
|
|
|
+ profession.put("playlet_num", album.getString("playlet_num"));
|
|
|
|
|
+ profession.put("playlet_duration", album.getString("playlet_duration"));
|
|
|
|
|
+ profession.put("start_pay_playlet", album.getString("start_pay_playlet"));
|
|
|
|
|
+ if (platform.getDouble("max_charge") > 0.0){
|
|
|
|
|
+ profession.put("max_charge", platform.getString("max_charge"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (platform.getDouble("min_charge") > 0.0){
|
|
|
|
|
+ profession.put("min_charge", platform.getString("min_charge"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (platform.getDouble("recommended_charge") > 0.0){
|
|
|
|
|
+ profession.put("recommended_charge", platform.getString("recommended_charge"));
|
|
|
|
|
+ }
|
|
|
|
|
+ profession.put("has_paid_content", "1");
|
|
|
|
|
+ profession.put("has_motivation_content", "2");
|
|
|
|
|
+ profession.put("membership_types", platform.getString("membership_types"));
|
|
|
|
|
+ Map<String, String> linkObj = advertiserToLinkMap.get(platform.getString("advertiser_id"));
|
|
|
|
|
+ String play_platform = album.getString("play_platform");
|
|
|
|
|
+ List<String> ad_carrier = new ArrayList<>();
|
|
|
|
|
+ if (linkObj != null){
|
|
|
|
|
+ profession.put("micro_app_link", linkObj.get(album_id));
|
|
|
|
|
+ ad_carrier.add("字节小程序");
|
|
|
|
|
+ if (play_platform.contains("1")){
|
|
|
|
|
+ ad_carrier.add("微信小程序");
|
|
|
}
|
|
}
|
|
|
|
|
+ }else {
|
|
|
|
|
+ profession.put("album_id", album_id);
|
|
|
|
|
+ ad_carrier.add("微信小程序");
|
|
|
|
|
+ }
|
|
|
|
|
+ profession.put("ad_carrier", JSON.toJSONString(ad_carrier));
|
|
|
|
|
+
|
|
|
|
|
+ //price_info
|
|
|
|
|
+ JSONObject price_info = new JSONObject();
|
|
|
|
|
+ price_info.put("price", platform.getDoubleValue("single_price"));
|
|
|
|
|
+ product_info.put("price_info", price_info);
|
|
|
|
|
+ product_info.put("profession", profession);
|
|
|
|
|
+ request.put("product_info", product_info);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// System.out.println("请求地址:" + url);
|
|
|
|
|
+// System.out.println("请求头:" + headers);
|
|
|
|
|
+// System.out.println("请求参数:" + request.toJSONString());
|
|
|
|
|
+ String res = HttpUtils.httpPostRequest(url, request, headers);
|
|
|
|
|
+ JSONObject btRes = JSONObject.parseObject(res);
|
|
|
|
|
+ int code = btRes.getIntValue("code");
|
|
|
|
|
+ if (code != 0){
|
|
|
|
|
+ errorBlanket.add("上传付费商品失败,code: " + code + ", msg: " + btRes.getString("message")+", 关联剧目: " + album.getString("name"));
|
|
|
}
|
|
}
|
|
|
|
|
+ return code;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void iaaProductUpdate(List<String> errorBlanket){
|
|
private void iaaProductUpdate(List<String> errorBlanket){
|
|
@@ -211,6 +267,7 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
System.out.println("没有找到字节小程序的实例ID: " + advertiserId);
|
|
System.out.println("没有找到字节小程序的实例ID: " + advertiserId);
|
|
|
continue; //todo
|
|
continue; //todo
|
|
|
}
|
|
}
|
|
|
|
|
+ List<JSONObject> iaaVideoDouyinList = iaaVideoList.stream().filter(obj1 -> "1".equals(obj1.getString("platform_type"))).collect(Collectors.toList());
|
|
|
Map<String, String> albumIdToLinkMap = getBytedancePlayletPromoteLink(advertiserId, accessToken, instanceId, iaaVideoList, errorBlanket);
|
|
Map<String, String> albumIdToLinkMap = getBytedancePlayletPromoteLink(advertiserId, accessToken, instanceId, iaaVideoList, errorBlanket);
|
|
|
advertiserToLinkMap.put(advertiserId, albumIdToLinkMap);
|
|
advertiserToLinkMap.put(advertiserId, albumIdToLinkMap);
|
|
|
}
|
|
}
|
|
@@ -228,51 +285,16 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
System.out.println("\n\n\n");
|
|
System.out.println("\n\n\n");
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ Integer platformType1 = obj.getInteger("platform_type");
|
|
|
|
|
|
|
|
for (JSONObject platform : iaaPlatformList) {
|
|
for (JSONObject platform : iaaPlatformList) {
|
|
|
- String url = "https://ad.oceanengine.com/open_api/2/dpa/product/update/";
|
|
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
|
- headers.put("Access-Token", platform.getString("access_token"));
|
|
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
|
|
- String album_id = obj.getString("album_id");
|
|
|
|
|
- JSONObject request = new JSONObject();
|
|
|
|
|
- request.put("product_id", obj.getLongValue("album_id"));
|
|
|
|
|
- JSONObject product_info = new JSONObject();
|
|
|
|
|
- product_info.put("name", obj.getString("name"));
|
|
|
|
|
- product_info.put("image_url", obj.getString("img"));
|
|
|
|
|
- product_info.put("status", 1);
|
|
|
|
|
- product_info.put("stock", 1);
|
|
|
|
|
- JSONObject productType = iaaProductTypeMap.get(theme);
|
|
|
|
|
- product_info.put("first_category_id", productType.getString("first_type_id"));
|
|
|
|
|
- product_info.put("sub_category_id", productType.getString("second_type_id"));
|
|
|
|
|
- product_info.put("third_category_id", productType.getString("third_type_id"));
|
|
|
|
|
- product_info.put("first_category", productType.getString("first_type_name"));
|
|
|
|
|
- product_info.put("sub_category", productType.getString("second_type_name"));
|
|
|
|
|
- product_info.put("third_category", productType.getString("third_type_name"));
|
|
|
|
|
- JSONObject profession = new JSONObject();
|
|
|
|
|
- profession.put("copyright_owner", obj.getString("copyright_owner"));
|
|
|
|
|
- profession.put("playlet_gender", "3");
|
|
|
|
|
- profession.put("playlet_num", obj.getString("playlet_num"));
|
|
|
|
|
- profession.put("playlet_duration", obj.getString("playlet_duration"));
|
|
|
|
|
- profession.put("has_paid_content", "2");
|
|
|
|
|
- profession.put("has_motivation_content", "2");
|
|
|
|
|
- profession.put("membership_types", "5");
|
|
|
|
|
- profession.put("starting_unlock_episode", obj.getString("starting_unlock_episode"));
|
|
|
|
|
- profession.put("micro_app_link", advertiserToLinkMap.get(platform.getString("advertiser_id")).get(album_id));
|
|
|
|
|
- product_info.put("profession", profession);
|
|
|
|
|
- request.put("product_info", product_info);
|
|
|
|
|
- request.put("advertiser_id", platform.getLongValue("advertiser_id"));
|
|
|
|
|
- request.put("platform_id", platform.getLongValue("platform_id"));
|
|
|
|
|
-
|
|
|
|
|
-// System.out.println("请求地址:" + url);
|
|
|
|
|
-// System.out.println("请求头:" + headers);
|
|
|
|
|
-// System.out.println("请求参数:" + request.toJSONString());
|
|
|
|
|
- String res = HttpUtils.httpPostRequest(url, request, headers);
|
|
|
|
|
- JSONObject btRes = JSONObject.parseObject(res);
|
|
|
|
|
- int code = btRes.getIntValue("code");
|
|
|
|
|
- if (code != 0){
|
|
|
|
|
- errorBlanket.add("上传免费商品失败,code: " + code + ", msg: " + btRes.getString("message")+", 关联剧目: " + obj.getString("name"));
|
|
|
|
|
|
|
+ Integer platformType2 = platform.getInteger("platform_type");
|
|
|
|
|
+ if (!Objects.equals(platformType1, platformType2)){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ int code = uploadIaaProduct(platform, obj, advertiserToLinkMap, errorBlanket, iaaProductTypeMap.get(theme));
|
|
|
|
|
+ if (code !=0){
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
// System.out.println(res);
|
|
// System.out.println(res);
|
|
|
// System.out.println("\n\n\n");
|
|
// System.out.println("\n\n\n");
|
|
@@ -280,6 +302,69 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private int uploadIaaProduct(JSONObject platform, JSONObject album, Map<String,
|
|
|
|
|
+ Map<String, String>> advertiserToLinkMap,
|
|
|
|
|
+ List<String> errorBlanket,
|
|
|
|
|
+ JSONObject productType){
|
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/dpa/product/update/";
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Access-Token", platform.getString("access_token"));
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+ String album_id = album.getString("album_id");
|
|
|
|
|
+ JSONObject request = new JSONObject();
|
|
|
|
|
+ request.put("product_id", album.getLongValue("album_id"));
|
|
|
|
|
+ JSONObject product_info = new JSONObject();
|
|
|
|
|
+ product_info.put("name", album.getString("name"));
|
|
|
|
|
+ product_info.put("image_url", album.getString("img"));
|
|
|
|
|
+ product_info.put("status", 1);
|
|
|
|
|
+ product_info.put("stock", 1);
|
|
|
|
|
+ product_info.put("first_category_id", productType.getString("first_type_id"));
|
|
|
|
|
+ product_info.put("sub_category_id", productType.getString("second_type_id"));
|
|
|
|
|
+ product_info.put("third_category_id", productType.getString("third_type_id"));
|
|
|
|
|
+ product_info.put("first_category", productType.getString("first_type_name"));
|
|
|
|
|
+ product_info.put("sub_category", productType.getString("second_type_name"));
|
|
|
|
|
+ product_info.put("third_category", productType.getString("third_type_name"));
|
|
|
|
|
+ JSONObject profession = new JSONObject();
|
|
|
|
|
+ profession.put("copyright_owner", album.getString("copyright_owner"));
|
|
|
|
|
+ profession.put("playlet_gender", "3");
|
|
|
|
|
+ profession.put("playlet_num", album.getString("playlet_num"));
|
|
|
|
|
+ profession.put("playlet_duration", album.getString("playlet_duration"));
|
|
|
|
|
+ profession.put("has_paid_content", "2");
|
|
|
|
|
+ profession.put("has_motivation_content", "2");
|
|
|
|
|
+ profession.put("membership_types", "5");
|
|
|
|
|
+ profession.put("starting_unlock_episode", album.getString("starting_unlock_episode"));
|
|
|
|
|
+ Map<String, String> linkObj = advertiserToLinkMap.get(platform.getString("advertiser_id"));
|
|
|
|
|
+ String play_platform = album.getString("play_platform");
|
|
|
|
|
+ List<String> ad_carrier = new ArrayList<>();
|
|
|
|
|
+ if (linkObj != null){
|
|
|
|
|
+ profession.put("micro_app_link", linkObj.get(album_id));
|
|
|
|
|
+ ad_carrier.add("字节小程序");
|
|
|
|
|
+ if (play_platform.contains("1")){
|
|
|
|
|
+ ad_carrier.add("微信小程序");
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ profession.put("album_id", album_id);
|
|
|
|
|
+ ad_carrier.add("微信小程序");
|
|
|
|
|
+ }
|
|
|
|
|
+ profession.put("ad_carrier", JSON.toJSONString(ad_carrier));
|
|
|
|
|
+
|
|
|
|
|
+ product_info.put("profession", profession);
|
|
|
|
|
+ request.put("product_info", product_info);
|
|
|
|
|
+ request.put("advertiser_id", platform.getLongValue("advertiser_id"));
|
|
|
|
|
+ request.put("platform_id", platform.getLongValue("platform_id"));
|
|
|
|
|
+
|
|
|
|
|
+// System.out.println("请求地址:" + url);
|
|
|
|
|
+// System.out.println("请求头:" + headers);
|
|
|
|
|
+// System.out.println("请求参数:" + request.toJSONString());
|
|
|
|
|
+ String res = HttpUtils.httpPostRequest(url, request, headers);
|
|
|
|
|
+ JSONObject btRes = JSONObject.parseObject(res);
|
|
|
|
|
+ int code = btRes.getIntValue("code");
|
|
|
|
|
+ if (code != 0){
|
|
|
|
|
+ errorBlanket.add("上传免费商品失败,code: " + code + ", msg: " + btRes.getString("message")+", 关联剧目: " + album.getString("name"));
|
|
|
|
|
+ }
|
|
|
|
|
+ return code;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param advertiserId 商品库主账户ID,也是创建字节小程序的ID
|
|
* @param advertiserId 商品库主账户ID,也是创建字节小程序的ID
|
|
@@ -404,4 +489,179 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public void uploadAlbum() throws IOException {
|
|
|
|
|
+ List<String> info = new ArrayList<>();
|
|
|
|
|
+ info.add("仅微小剧目上传通知");
|
|
|
|
|
+ List<JSONObject> wxVideoInfos = bytedanceProductUpdateMapper.getUploadList();
|
|
|
|
|
+ JSONObject developerAccount = bytedanceProductUpdateMapper.getDeveloperAccount();
|
|
|
|
|
+ Long appId = developerAccount.getLong("app_id");
|
|
|
|
|
+ String appAccessToken = getAppAccessToken(appId, developerAccount.getString("app_secret"));
|
|
|
|
|
+ if (appAccessToken == null){
|
|
|
|
|
+ System.out.println("获取app_access_token失败");
|
|
|
|
|
+ info.add("获取app_access_token失败");
|
|
|
|
|
+ FeishuRobotUtil.sendTextToWebhook(StringUtils.join(info, "\n"), HOOK_URL);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (JSONObject vi : wxVideoInfos){
|
|
|
|
|
+ Long videoId = vi.getLong("video_id");
|
|
|
|
|
+ String albumId = uploadAlbum(videoId, appId, appAccessToken);
|
|
|
|
|
+ if (albumId == null){
|
|
|
|
|
+ info.add("上传短剧失败,videoId: " + videoId + ", 剧目名称: " + vi.getString("name"));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ bytedanceProductUpdateMapper.insertAlbumInfo(albumId, videoId);
|
|
|
|
|
+ info.add("上传短剧成功,videoId: " + videoId + ", 剧目名称: " + vi.getString("name") + ", albumId: " + albumId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ FeishuRobotUtil.sendTextToWebhook(StringUtils.join(info, "\n"), HOOK_URL);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void refreshAlbumStatus() throws IOException {
|
|
|
|
|
+ List<String> info = new ArrayList<>();
|
|
|
|
|
+ info.add("短剧审核状态更新通知");
|
|
|
|
|
+ JSONObject developerAccount = bytedanceProductUpdateMapper.getDeveloperAccount();
|
|
|
|
|
+ Long app_id = developerAccount.getLong("app_id");
|
|
|
|
|
+ String app_secret = developerAccount.getString("app_secret");
|
|
|
|
|
+ String appAccessToken = getAppAccessToken(app_id, app_secret);
|
|
|
|
|
+ if (appAccessToken == null){
|
|
|
|
|
+ System.out.println("获取app_access_token失败");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<JSONObject> listAlbum = bytedanceProductUpdateMapper.selectWaitingAlbums();
|
|
|
|
|
+ for (JSONObject album : listAlbum){
|
|
|
|
|
+ String al = album.getString("album_id");
|
|
|
|
|
+ String albumName = album.getString("name");
|
|
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/dpa/album_status/get/";
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("App-Access-Token", appAccessToken);
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("album_id", al);
|
|
|
|
|
+ params.put("app_id", app_id);
|
|
|
|
|
+ String res = HttpUtils.httpGet(url, params, headers);
|
|
|
|
|
+ if (res == null || res.isEmpty()){
|
|
|
|
|
+ System.out.println("获取短剧状态失败,albumId: " + al);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ JSONObject resObj = JSONObject.parseObject(res);
|
|
|
|
|
+ int code = resObj.getIntValue("code");
|
|
|
|
|
+ if (code != 0){
|
|
|
|
|
+ info.add("获取短剧状态失败,code: " + code + ", msg: " + resObj.getString("message")+", 剧目名称: " + albumName);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ JSONObject data = resObj.getJSONObject("data");
|
|
|
|
|
+ boolean isSuccess = data.getBooleanValue("can_promotion");
|
|
|
|
|
+ if (isSuccess) {
|
|
|
|
|
+ //更新状态
|
|
|
|
|
+ bytedanceProductUpdateMapper.updateAlbumInfo(al, 1, null);
|
|
|
|
|
+ info.add("短剧审核通过,albumId: " + al + ", 剧目名称: " + albumName);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ String failReason = data.getString("can_not_promotion_reason");
|
|
|
|
|
+ if ("RESOURCE_CREATING".equals(failReason) || "RESOURCE_AUDITING".equals(failReason)){
|
|
|
|
|
+ //等待中
|
|
|
|
|
+ bytedanceProductUpdateMapper.updateAlbumInfo(al, 0, failReason);
|
|
|
|
|
+ info.add("短剧审核中,albumId: " + al + ", 剧目名称: " + albumName+", 当前状态: " + failReason);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //失败
|
|
|
|
|
+ bytedanceProductUpdateMapper.updateAlbumInfo(al, 2, failReason);
|
|
|
|
|
+ info.add("短剧审核失败,albumId: " + al + ", 剧目名称: " + albumName + ", 原因: " + failReason);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ FeishuRobotUtil.sendTextToWebhook(StringUtils.join(info, "\n"), HOOK_URL);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传短剧
|
|
|
|
|
+ * @param videoId from ly_videos
|
|
|
|
|
+ * @return albumId
|
|
|
|
|
+ */
|
|
|
|
|
+ private String uploadAlbum(long videoId, Long appId, String appAccessToken){
|
|
|
|
|
+ JSONObject video = bytedanceProductUpdateMapper.getVideoInfo(videoId);
|
|
|
|
|
+ if (video == null){
|
|
|
|
|
+ System.out.println("没有找到视频信息,videoId: " + videoId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String videoName = video.getString("name");
|
|
|
|
|
+ Integer sylloge = video.getInteger("sylloge");//总集数
|
|
|
|
|
+ List<JSONObject> videoDetail = bytedanceProductUpdateMapper.getVideoDetail(videoId);
|
|
|
|
|
+ if (videoDetail == null || videoDetail.isEmpty()){
|
|
|
|
|
+ System.out.println("没有找到视频剧集详情,videoId: " + videoId);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
|
|
+ requestBody.put("album_title", videoName);
|
|
|
|
|
+ requestBody.put("seq_num", sylloge);
|
|
|
|
|
+ requestBody.put("app_id", appId);
|
|
|
|
|
+
|
|
|
|
|
+ List<JSONObject> videoDetailList = new ArrayList<>();
|
|
|
|
|
+ for (JSONObject obj : videoDetail){
|
|
|
|
|
+ String videoUrl = obj.getString("url").replaceAll("oss\\.artlinkworld\\.cn", "bydance.artlinkworld.cn");//使用单独的域名
|
|
|
|
|
+ String title = obj.getString("name");
|
|
|
|
|
+ Integer seq = obj.getInteger("sort");
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject meta = new JSONObject();
|
|
|
|
|
+ meta.put("url", videoUrl);
|
|
|
|
|
+ meta.put("title", title);
|
|
|
|
|
+ meta.put("seq", seq);
|
|
|
|
|
+ videoDetailList.add(meta);
|
|
|
|
|
+ }
|
|
|
|
|
+ requestBody.put("video_meta_mico", videoDetailList);
|
|
|
|
|
+
|
|
|
|
|
+ String url = "https://api.oceanengine.com/open_api/v3.0/dpa/album/create/";
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("App-Access-Token", appAccessToken);
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println(requestBody.toJSONString());
|
|
|
|
|
+// return null;
|
|
|
|
|
+ String res = HttpUtils.httpPostRequest(url, requestBody, headers);
|
|
|
|
|
+ System.out.println(">>> "+res);
|
|
|
|
|
+ if (res == null || res.isEmpty()){
|
|
|
|
|
+ System.out.println("上传短剧失败, 返回null");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ JSONObject resObj = JSONObject.parseObject(res);
|
|
|
|
|
+ int code = resObj.getIntValue("code");
|
|
|
|
|
+ if (code != 0){
|
|
|
|
|
+ System.out.println("上传短剧失败,code: " + code + ", msg: " + resObj.getString("message"));
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ String albumId = resObj.getJSONObject("data").getString("album_id");
|
|
|
|
|
+ return albumId;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private String getAppAccessToken(Long app_id, String app_secret){
|
|
|
|
|
+ String url = "https://open.oceanengine.com/open_api/oauth2/app_access_token/";
|
|
|
|
|
+ if (app_id == null || app_secret == null){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
|
|
+ body.put("app_id", app_id);
|
|
|
|
|
+ body.put("secret", app_secret);
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
|
+ String res = HttpUtils.httpPostRequest(url, body, headers);
|
|
|
|
|
+ if (res == null || res.isEmpty()){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ JSONObject resObj = JSONObject.parseObject(res);
|
|
|
|
|
+ int code = resObj.getIntValue("code");
|
|
|
|
|
+ if (code != 0){
|
|
|
|
|
+ System.out.println("获取app_access_token失败,code: " + code + ", msg: " + resObj.getString("message"));
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return resObj.getJSONObject("data").getString("access_token");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|