1
This commit is contained in:
@@ -110,7 +110,7 @@ public class JDProductService {
|
||||
|
||||
// 创建商品对象
|
||||
JSONObject productObj = new JSONObject();
|
||||
productObj.put("url", url);
|
||||
productObj.put("originalUrl", url);
|
||||
|
||||
// 商品基本信息
|
||||
productObj.put("materialUrl", productInfo.getData()[0].getMaterialUrl());
|
||||
@@ -135,6 +135,26 @@ public class JDProductService {
|
||||
}
|
||||
productObj.put("images", imageArray);
|
||||
|
||||
// 生成转链后的短链
|
||||
try {
|
||||
String shortUrl = transfer(url, null);
|
||||
if (shortUrl != null && !shortUrl.isEmpty()) {
|
||||
productObj.put("shortUrl", shortUrl);
|
||||
productObj.put("transferSuccess", true);
|
||||
// 将短链替换原始链接,用于后续文案生成
|
||||
url = shortUrl;
|
||||
} else {
|
||||
productObj.put("shortUrl", url); // 如果转链失败,使用原链接
|
||||
productObj.put("transferSuccess", false);
|
||||
log.warn("转链失败,使用原链接: {}", url);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("生成转链时发生异常: {}", url, e);
|
||||
productObj.put("shortUrl", url); // 转链异常时使用原链接
|
||||
productObj.put("transferSuccess", false);
|
||||
productObj.put("transferError", e.getMessage());
|
||||
}
|
||||
|
||||
// 文案信息
|
||||
JSONArray wenanArray = new JSONArray();
|
||||
|
||||
@@ -178,10 +198,12 @@ public class JDProductService {
|
||||
|
||||
productObj.put("wenan", wenanArray);
|
||||
|
||||
// 添加通用文案
|
||||
// 添加通用文案 - 使用转链后的短链替换原始链接
|
||||
JSONObject commonWenan = new JSONObject();
|
||||
commonWenan.put("type", "通用文案");
|
||||
commonWenan.put("content", format + FANAN_COMMON + message);
|
||||
// 将原始消息中的链接替换为转链后的短链
|
||||
String messageWithShortUrl = message.replace(productObj.getString("originalUrl"), url);
|
||||
commonWenan.put("content", format + FANAN_COMMON + messageWithShortUrl);
|
||||
wenanArray.add(commonWenan);
|
||||
|
||||
resultArray.add(productObj);
|
||||
|
||||
Reference in New Issue
Block a user