1
This commit is contained in:
@@ -38,7 +38,7 @@ public class JDOrderController {
|
||||
param.put("promotionContent", promotionContent);
|
||||
result = HttpUtils.sendJsonPost(url, param.toJSONString());
|
||||
|
||||
// 尝试将 priceInfo.price 提取为顶层 price 字段
|
||||
// 尝试将 priceInfo.price 提取为顶层 price 字段,并清理文案中的 URL
|
||||
try {
|
||||
Object parsed = JSON.parse(result);
|
||||
if (parsed instanceof JSONArray) {
|
||||
@@ -51,6 +51,7 @@ public class JDOrderController {
|
||||
if (priceInfo != null && priceInfo.get("price") != null) {
|
||||
obj.put("price", priceInfo.get("price"));
|
||||
}
|
||||
sanitizeWenan(obj);
|
||||
}
|
||||
}
|
||||
result = arr.toJSONString();
|
||||
@@ -65,6 +66,7 @@ public class JDOrderController {
|
||||
if (priceInfo != null && priceInfo.get("price") != null) {
|
||||
o.put("price", priceInfo.get("price"));
|
||||
}
|
||||
sanitizeWenan(o);
|
||||
}
|
||||
}
|
||||
obj.put("list", list);
|
||||
@@ -77,9 +79,13 @@ public class JDOrderController {
|
||||
if (priceInfo != null && priceInfo.get("price") != null) {
|
||||
o.put("price", priceInfo.get("price"));
|
||||
}
|
||||
sanitizeWenan(o);
|
||||
}
|
||||
}
|
||||
obj.put("data", data);
|
||||
} else {
|
||||
// 单对象结构也尝试清理
|
||||
sanitizeWenan(obj);
|
||||
}
|
||||
result = obj.toJSONString();
|
||||
}
|
||||
@@ -92,6 +98,42 @@ public class JDOrderController {
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理对象中 wenan[].content 的 URL(包含 http/https 及裸露的 u.jd.com 短链)
|
||||
*/
|
||||
private void sanitizeWenan(JSONObject obj) {
|
||||
if (obj == null) return;
|
||||
Object wenan = obj.get("wenan");
|
||||
if (wenan instanceof JSONArray) {
|
||||
JSONArray wa = (JSONArray) wenan;
|
||||
for (int i = 0; i < wa.size(); i++) {
|
||||
Object w = wa.get(i);
|
||||
if (w instanceof JSONObject) {
|
||||
JSONObject wj = (JSONObject) w;
|
||||
Object content = wj.get("content");
|
||||
if (content instanceof String) {
|
||||
String cleaned = stripUrls((String) content);
|
||||
wj.put("content", cleaned);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除文本中的 URL 链接
|
||||
*/
|
||||
private String stripUrls(String text) {
|
||||
if (text == null || text.isEmpty()) return text;
|
||||
// 移除 http/https 链接
|
||||
String cleaned = text.replaceAll("https?://\\S+", "");
|
||||
// 移除裸露的 u.jd.com 短链
|
||||
cleaned = cleaned.replaceAll("(?i)\\bu\\.jd\\.com/\\S+", "");
|
||||
// 压缩多余空白
|
||||
cleaned = cleaned.replaceAll("[\\t ]+", " ").replaceAll("\n{3,}", "\n\n").trim();
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开礼金(转发到内部服务)
|
||||
* 入参:materialUrl 或 skuId,amount(金额,单位元),quantity(数量),owner(g/pop),skuName(可选)
|
||||
|
||||
Reference in New Issue
Block a user