Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/cn/van/business/util/JDProductService.java
This commit is contained in:
2025-08-21 19:48:50 +08:00
4 changed files with 160 additions and 146 deletions

View File

@@ -2,50 +2,118 @@ package cn.van.business.controller.jd;
import cn.van.business.util.JDProductService; import cn.van.business.util.JDProductService;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map; import java.util.Map;
/**
* @author Leo
* @version 1.0
* @create 2025/8/15 10:12
* @description没有权限校验只暴露本地调用
*/
@Controller
@RequestMapping("/jd")
@RestController @RestController
@RequestMapping("/jd")
@Slf4j @Slf4j
public class JDInnerController { public class JDInnerController {
private static final Logger logger = LoggerFactory.getLogger(JDInnerController.class); private static final Logger logger = LoggerFactory.getLogger(JDInnerController.class);
private static final String SKEY = "2192057370ef8140c201079969c956a3";
private final static String skey = "2192057370ef8140c201079969c956a3"; private boolean checkSkey(String provided) {
private boolean checkSkey(String skey) { return !SKEY.equals(provided);
return skey.equals(this.skey);
} }
private JDProductService jdProductService;
private final JDProductService jdProductService;
@Autowired @Autowired
public JDInnerController(JDProductService jdProductService) { public JDInnerController(JDProductService jdProductService) {
this.jdProductService = jdProductService; this.jdProductService = jdProductService;
} }
@RequestMapping("/generatePromotionContent") @PostMapping("/generatePromotionContent")
public JSONArray generatePromotionContent(@RequestBody Map<String, String> requestBody) { public Object generatePromotionContent(@RequestBody Map<String, Object> requestBody) {
String promotionContent = requestBody.get("promotionContent"); String skey = requestBody.get("skey") != null ? String.valueOf(requestBody.get("skey")) : null;
logger.info("generatePromotionContent message:{}", promotionContent); String promotionContent = requestBody.get("promotionContent") != null ? String.valueOf(requestBody.get("promotionContent")) : null;
if (!checkSkey(skey)) { logger.info("generatePromotionContent message: {}", promotionContent);
return null; if (checkSkey(skey)) {
return error("invalid skey");
} }
return jdProductService.generatePromotionContentAsJsonArray(promotionContent); if (promotionContent == null || promotionContent.trim().isEmpty()) {
return error("promotionContent is required");
}
JSONArray arr = jdProductService.generatePromotionContentAsJsonArray(promotionContent);
return arr;
} }
@PostMapping("/createGiftCoupon")
public Object createGiftCoupon(@RequestBody Map<String, Object> body) {
String skey = body.get("skey") != null ? String.valueOf(body.get("skey")) : null;
if (checkSkey(skey)) {
return error("invalid skey");
}
String skuId = body.get("skuId") != null ? String.valueOf(body.get("skuId")) : null;
String materialUrl = body.get("materialUrl") != null ? String.valueOf(body.get("materialUrl")) : null;
String owner = body.get("owner") != null ? String.valueOf(body.get("owner")) : "g";
String skuName = body.get("skuName") != null ? String.valueOf(body.get("skuName")) : "";
double amount = parseDouble(body.get("amount"), -1);
int quantity = parseInt(body.get("quantity"), -1);
String idOrUrl = skuId != null && !skuId.trim().isEmpty() ? skuId : materialUrl;
if (idOrUrl == null || idOrUrl.trim().isEmpty()) {
return error("skuId or materialUrl is required");
}
if (amount <= 0 || quantity <= 0) {
return error("amount and quantity must be positive");
}
try {
String giftKey = jdProductService.createGiftCoupon(idOrUrl, amount, quantity, owner, skuName);
JSONObject resp = new JSONObject();
resp.put("giftCouponKey", giftKey);
// 可选:入库/缓存
if (giftKey != null) {
jdProductService.saveGiftCouponToRedis(idOrUrl, giftKey, skuName, owner);
}
return resp;
} catch (Exception e) {
logger.error("createGiftCoupon error", e);
return error("createGiftCoupon failed: " + e.getMessage());
}
}
@PostMapping("/transfer")
public Object transfer(@RequestBody Map<String, Object> body) {
String skey = body.get("skey") != null ? String.valueOf(body.get("skey")) : null;
if (checkSkey(skey)) {
return error("invalid skey");
}
String materialUrl = body.get("materialUrl") != null ? String.valueOf(body.get("materialUrl")) : null;
String giftCouponKey = body.get("giftCouponKey") != null ? String.valueOf(body.get("giftCouponKey")) : null;
if (materialUrl == null || materialUrl.trim().isEmpty()) {
return error("materialUrl is required");
}
try {
String shortUrl = jdProductService.transfer(materialUrl, giftCouponKey);
JSONObject resp = new JSONObject();
resp.put("shortURL", shortUrl);
return resp;
} catch (Exception e) {
logger.error("transfer error", e);
return error("transfer failed: " + e.getMessage());
}
}
private static JSONObject error(String msg) {
JSONObject o = new JSONObject();
o.put("error", msg);
return o;
}
private static int parseInt(Object o, int def) {
try { return o == null ? def : Integer.parseInt(String.valueOf(o)); } catch (Exception e) { return def; }
}
private static double parseDouble(Object o, double def) {
try { return o == null ? def : Double.parseDouble(String.valueOf(o)); } catch (Exception e) { return def; }
}
} }

View File

@@ -7,8 +7,6 @@ import cn.van.business.repository.XbMessageRepository;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.jd.open.api.sdk.DefaultJdClient; import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient; import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.domain.kplunion.CouponService.request.get.CreateGiftCouponReq; import com.jd.open.api.sdk.domain.kplunion.CouponService.request.get.CreateGiftCouponReq;
@@ -45,7 +43,6 @@ import static cn.van.business.util.JDUtil.*;
@Slf4j @Slf4j
public class JDProductService { public class JDProductService {
// 京东开放平台配置
private static final String LPF_APP_KEY_WZ = "98e21c89ae5610240ec3f5f575f86a59"; private static final String LPF_APP_KEY_WZ = "98e21c89ae5610240ec3f5f575f86a59";
private static final String LPF_SECRET_KEY_WZ = "3dcb6b23a1104639ac433fd07adb6dfb"; private static final String LPF_SECRET_KEY_WZ = "3dcb6b23a1104639ac433fd07adb6dfb";
private static final String SERVER_URL = "https://api.jd.com/routerjson"; private static final String SERVER_URL = "https://api.jd.com/routerjson";
@@ -55,8 +52,11 @@ public class JDProductService {
private final StringRedisTemplate redisTemplate; private final StringRedisTemplate redisTemplate;
private final XbMessageRepository xbMessageRepository; private final XbMessageRepository xbMessageRepository;
private final XbMessageItemRepository xbMessageItemRepository; private final XbMessageItemRepository xbMessageItemRepository;
@Autowired @Autowired
public JDProductService(StringRedisTemplate redisTemplate, XbMessageRepository xbMessageRepository, XbMessageItemRepository xbMessageItemRepository) { public JDProductService(StringRedisTemplate redisTemplate,
XbMessageRepository xbMessageRepository,
XbMessageItemRepository xbMessageItemRepository) {
this.redisTemplate = redisTemplate; this.redisTemplate = redisTemplate;
this.xbMessageRepository = xbMessageRepository; this.xbMessageRepository = xbMessageRepository;
this.xbMessageItemRepository = xbMessageItemRepository; this.xbMessageItemRepository = xbMessageItemRepository;
@@ -71,8 +71,6 @@ public class JDProductService {
*/ */
public synchronized JSONArray generatePromotionContentAsJsonArray(String message) { public synchronized JSONArray generatePromotionContentAsJsonArray(String message) {
JSONArray resultArray = new JSONArray(); JSONArray resultArray = new JSONArray();
// 提取方案中的所有 u.jd.com 链接
List<String> urls = extractUJDUrls(message); List<String> urls = extractUJDUrls(message);
if (urls.isEmpty()) { if (urls.isEmpty()) {
JSONObject errorObj = new JSONObject(); JSONObject errorObj = new JSONObject();
@@ -81,17 +79,13 @@ public class JDProductService {
return resultArray; return resultArray;
} }
String format = null;
DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒"); DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
for (String url : urls) { for (String url : urls) {
try { try {
// 新建格式好日期 String format = dateFormat.format(new Date());
format = dateFormat.format(new Date());
// 查询商品信息
GoodsQueryResult productInfo = queryProductInfoByUJDUrl(url); GoodsQueryResult productInfo = queryProductInfoByUJDUrl(url);
if (productInfo == null || productInfo.getCode() != 200) { if (productInfo == null || productInfo.getCode() != 200 || productInfo.getData() == null || productInfo.getData().length == 0) {
JSONObject errorObj = new JSONObject(); JSONObject errorObj = new JSONObject();
errorObj.put("url", url); errorObj.put("url", url);
errorObj.put("error", "链接查询失败"); errorObj.put("error", "链接查询失败");
@@ -99,16 +93,6 @@ public class JDProductService {
continue; continue;
} }
long totalCount = productInfo.getTotalCount();
if (totalCount == 0) {
JSONObject errorObj = new JSONObject();
errorObj.put("url", url);
errorObj.put("error", "未找到商品信息");
resultArray.add(errorObj);
continue;
}
// 创建商品对象
JSONObject productObj = new JSONObject(); JSONObject productObj = new JSONObject();
productObj.put("originalUrl", url); productObj.put("originalUrl", url);
@@ -124,11 +108,13 @@ public class JDProductService {
productObj.put("spuid", String.valueOf(productInfo.getData()[0].getSpuid())); productObj.put("spuid", String.valueOf(productInfo.getData()[0].getSpuid()));
productObj.put("commission", String.valueOf(productInfo.getData()[0].getCommissionInfo().getCommission())); productObj.put("commission", String.valueOf(productInfo.getData()[0].getCommissionInfo().getCommission()));
productObj.put("commissionShare", String.valueOf(productInfo.getData()[0].getCommissionInfo().getCommissionShare())); productObj.put("commissionShare", String.valueOf(productInfo.getData()[0].getCommissionInfo().getCommissionShare()));
productObj.put("price", String.valueOf(productInfo.getData()[0].getPriceInfo().getPrice())); if (productInfo.getData()[0].getPriceInfo() != null && productInfo.getData()[0].getPriceInfo().getPrice() != null) {
productObj.put("price", String.valueOf(productInfo.getData()[0].getPriceInfo().getPrice()));
}
// 图片信息
JSONArray imageArray = new JSONArray(); JSONArray imageArray = new JSONArray();
if (productInfo.getData()[0].getImageInfo() != null) { if (productInfo.getData()[0].getImageInfo() != null &&
productInfo.getData()[0].getImageInfo().getImageList() != null) {
for (UrlInfo image : productInfo.getData()[0].getImageInfo().getImageList()) { for (UrlInfo image : productInfo.getData()[0].getImageInfo().getImageList()) {
imageArray.add(image.getUrl()); imageArray.add(image.getUrl());
} }
@@ -164,8 +150,7 @@ public class JDProductService {
String[] lines = message.split("\\r?\\n"); String[] lines = message.split("\\r?\\n");
if (lines.length > 0) { if (lines.length > 0) {
title = lines[0]; title = lines[0];
// 有的换行了 if (lines.length > 1 && lines[1].length() > 3 && !lines[1].contains("u.jd")) {
if (lines[1].length() > 3 && !lines[1].contains("u.jd")) {
title = title + lines[1]; title = title + lines[1];
} }
title = title.replaceAll("@|所有人", ""); title = title.replaceAll("@|所有人", "");
@@ -206,6 +191,7 @@ public class JDProductService {
commonWenan.put("content", format + FANAN_COMMON + messageWithShortUrl); commonWenan.put("content", format + FANAN_COMMON + messageWithShortUrl);
wenanArray.add(commonWenan); wenanArray.add(commonWenan);
productObj.put("wenan", wenanArray);
resultArray.add(productObj); resultArray.add(productObj);
} catch (Exception e) { } catch (Exception e) {
@@ -229,13 +215,9 @@ public class JDProductService {
*/ */
public GoodsQueryResult queryProductInfoByUJDUrl(String uJDUrl) throws Exception { public GoodsQueryResult queryProductInfoByUJDUrl(String uJDUrl) throws Exception {
UnionOpenGoodsQueryResponse response = getUnionOpenGoodsQueryRequest(uJDUrl); UnionOpenGoodsQueryResponse response = getUnionOpenGoodsQueryRequest(uJDUrl);
if (response == null || response.getQueryResult() == null) { if (response == null || response.getQueryResult() == null) return null;
return null;
}
GoodsQueryResult queryResult = response.getQueryResult(); GoodsQueryResult queryResult = response.getQueryResult();
if (queryResult.getCode() != 200) { if (queryResult.getCode() != 200) return null;
return null;
}
return queryResult; return queryResult;
} }
@@ -256,56 +238,32 @@ public class JDProductService {
request.setGoodsReqDTO(goodsReq); request.setGoodsReqDTO(goodsReq);
request.setVersion("1.0"); request.setVersion("1.0");
request.setSignmethod("md5"); request.setSignmethod("md5");
request.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
// 时间戳格式为yyyy-MM-dd HH:mm:ss时区为GMT+8 return client.execute(request);
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
request.setTimestamp(simpleDateFormat.format(date));
UnionOpenGoodsQueryResponse execute = client.execute(request);
return execute;
} }
/**
* 创建礼金
*
* @param skuId 商品SKU ID
* @param amount 礼金金额
* @param quantity 礼金数量
* @param owner 商品所有者(g:自营, pop:POP商家)
* @param skuName 商品名称
* @return 礼金Key
* @throws Exception 创建异常
*/
public String createGiftCoupon(String skuId, double amount, int quantity, String owner, String skuName) throws Exception { public String createGiftCoupon(String skuId, double amount, int quantity, String owner, String skuName) throws Exception {
log.debug("准备创建礼金SKU={}, 金额={}元,数量={}, Owner={}", skuId, amount, quantity, owner); log.debug("准备创建礼金SKU={}, 金额={}元,数量={}, Owner={}", skuId, amount, quantity, owner);
if (skuId == null || skuId.trim().isEmpty() || amount <= 0 || quantity <= 0) {
// 参数校验
if (skuId == null || amount <= 0 || quantity <= 0) {
log.error("礼金创建失败参数错误SKU={}, 金额={}元,数量={}", skuId, amount, quantity); log.error("礼金创建失败参数错误SKU={}, 金额={}元,数量={}", skuId, amount, quantity);
return null; return null;
} }
owner = (owner != null && !owner.isEmpty()) ? owner : "g";
// 设置默认值
owner = (owner != null) ? owner : "g";
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_SECRET_KEY_WZ); JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_SECRET_KEY_WZ);
UnionOpenCouponGiftGetRequest request = new UnionOpenCouponGiftGetRequest(); UnionOpenCouponGiftGetRequest request = new UnionOpenCouponGiftGetRequest();
CreateGiftCouponReq couponReq = new CreateGiftCouponReq(); CreateGiftCouponReq couponReq = new CreateGiftCouponReq();
couponReq.setSkuMaterialId(skuId); // 使用SKU或链接 couponReq.setSkuMaterialId(skuId);
couponReq.setDiscount(amount); couponReq.setDiscount(amount);
couponReq.setAmount(quantity); couponReq.setAmount(quantity);
// 自营的只能设置一天pop的只能设置7天默认为自营 String startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
String startTime;
String endTime; String endTime;
if ("pop".equals(owner)) { if ("pop".equalsIgnoreCase(owner)) {
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
endTime = LocalDateTime.now().plusDays(6).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH")); endTime = LocalDateTime.now().plusDays(6).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
couponReq.setEffectiveDays(7); couponReq.setEffectiveDays(7);
} else { } else {
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
endTime = LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH")); endTime = LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
couponReq.setEffectiveDays(1); couponReq.setEffectiveDays(1);
} }
@@ -316,32 +274,22 @@ public class JDProductService {
couponReq.setExpireType(1); couponReq.setExpireType(1);
couponReq.setShare(-1); couponReq.setShare(-1);
if (skuName.length() >= 25) { if (skuName == null) skuName = "";
skuName = skuName.substring(0, 25); if (skuName.length() > 25) skuName = skuName.substring(0, 25);
} skuName = skuName + " " + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
// 新建格式日期
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
skuName = skuName + " " + dateFormat.format(new Date());
couponReq.setCouponTitle(skuName); couponReq.setCouponTitle(skuName);
couponReq.setContentMatch(1); couponReq.setContentMatch(1);
request.setCouponReq(couponReq); request.setCouponReq(couponReq);
request.setVersion("1.0"); request.setVersion("1.0");
log.debug("请求参数:{}", JSON.toJSONString(request));
UnionOpenCouponGiftGetResponse response = client.execute(request); UnionOpenCouponGiftGetResponse response = client.execute(request);
log.debug("API响应{}", JSON.toJSONString(response)); if ("0".equals(response.getCode()) && response.getGetResult() != null && response.getGetResult().getCode() == 200) {
if ("0".equals(response.getCode()) && response.getGetResult().getCode() == 200) {
String giftKey = response.getGetResult().getData().getGiftCouponKey(); String giftKey = response.getGetResult().getData().getGiftCouponKey();
log.debug("礼金创建成功:批次ID={}, 返回数据:{}", giftKey, response.getGetResult().getData()); log.debug("礼金创建成功:giftKey={}", giftKey);
return giftKey; return giftKey;
} else {
log.error("礼金创建失败:错误码={}, 错误信息={}", response.getCode(), response.getMsg());
} }
log.error("礼金创建失败code={}, msg={}", response != null ? response.getCode() : "null", response != null ? response.getMsg() : "null");
return null; return null;
} }
@@ -359,31 +307,23 @@ public class JDProductService {
PromotionCodeReq promotionCodeReq = new PromotionCodeReq(); PromotionCodeReq promotionCodeReq = new PromotionCodeReq();
promotionCodeReq.setSceneId(1); promotionCodeReq.setSceneId(1);
promotionCodeReq.setMaterialId(url); promotionCodeReq.setMaterialId(url);
if (giftCouponKey != null && !giftCouponKey.isEmpty()) {
if (giftCouponKey != null) {
promotionCodeReq.setGiftCouponKey(giftCouponKey); promotionCodeReq.setGiftCouponKey(giftCouponKey);
} }
request.setPromotionCodeReq(promotionCodeReq); request.setPromotionCodeReq(promotionCodeReq);
request.setVersion("1.0"); request.setVersion("1.0");
UnionOpenPromotionBysubunionidGetResponse response;
try { try {
response = client.execute(request); UnionOpenPromotionBysubunionidGetResponse response = client.execute(request);
if (response != null && "0".equals(response.getCode()) &&
response.getGetResult() != null && response.getGetResult().getCode() == 200) {
return response.getGetResult().getData().getShortURL();
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return null;
String result = "";
if (response != null) {
if ("0".equals(response.getCode()) && response.getGetResult().getCode() == 200) {
result = response.getGetResult().getData().getShortURL();
}
} else {
result = null;
}
return result;
} }
/** /**
@@ -397,7 +337,7 @@ public class JDProductService {
public void saveGiftCouponToRedis(String skuId, String giftKey, String skuName, String owner) { public void saveGiftCouponToRedis(String skuId, String giftKey, String skuName, String owner) {
String key = "gift_coupon:" + skuId; String key = "gift_coupon:" + skuId;
String hashKey = giftKey; String hashKey = giftKey;
LocalDateTime expireTime = LocalDateTime.now().plus(owner.equals("g") ? 0 : 7, java.time.temporal.ChronoUnit.DAYS); LocalDateTime expireTime = LocalDateTime.now().plus("g".equals(owner) ? 0 : 7, java.time.temporal.ChronoUnit.DAYS);
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("giftKey", giftKey); data.put("giftKey", giftKey);
@@ -417,28 +357,21 @@ public class JDProductService {
*/ */
public Map<String, Object> extractPriceInfo(GoodsQueryResult productInfo) { public Map<String, Object> extractPriceInfo(GoodsQueryResult productInfo) {
Map<String, Object> priceMap = new HashMap<>(); Map<String, Object> priceMap = new HashMap<>();
if (productInfo == null || productInfo.getData() == null || productInfo.getData().length == 0) { if (productInfo == null || productInfo.getData() == null || productInfo.getData().length == 0) {
priceMap.put("error", "商品信息为空"); priceMap.put("error", "商品信息为空");
return priceMap; return priceMap;
} }
try { try {
// 获取第一个商品的价格信息
var priceInfo = productInfo.getData()[0].getPriceInfo(); var priceInfo = productInfo.getData()[0].getPriceInfo();
if (priceInfo != null) { if (priceInfo != null) {
priceMap.put("price", priceInfo.getPrice()); // 原价 priceMap.put("price", priceInfo.getPrice());
priceMap.put("lowestPrice", priceInfo.getLowestPrice()); // 最低价 priceMap.put("lowestPrice", priceInfo.getLowestPrice());
priceMap.put("lowestCouponPrice", priceInfo.getLowestCouponPrice()); // 最低券后价 priceMap.put("lowestCouponPrice", priceInfo.getLowestCouponPrice());
priceMap.put("lowestPriceType", priceInfo.getLowestPriceType()); // 最低价类型 priceMap.put("lowestPriceType", priceInfo.getLowestPriceType());
// 计算优惠金额
if (priceInfo.getPrice() != null && priceInfo.getLowestCouponPrice() != null) { if (priceInfo.getPrice() != null && priceInfo.getLowestCouponPrice() != null) {
double discount = priceInfo.getPrice() - priceInfo.getLowestCouponPrice(); double discount = priceInfo.getPrice() - priceInfo.getLowestCouponPrice();
priceMap.put("discount", discount); // 优惠金额 priceMap.put("discount", discount);
} }
// 格式化价格显示
priceMap.put("priceFormatted", "¥" + (priceInfo.getPrice() != null ? priceInfo.getPrice() / 100.0 : 0)); priceMap.put("priceFormatted", "¥" + (priceInfo.getPrice() != null ? priceInfo.getPrice() / 100.0 : 0));
priceMap.put("lowestPriceFormatted", "¥" + (priceInfo.getLowestPrice() != null ? priceInfo.getLowestPrice() / 100.0 : 0)); priceMap.put("lowestPriceFormatted", "¥" + (priceInfo.getLowestPrice() != null ? priceInfo.getLowestPrice() / 100.0 : 0));
priceMap.put("lowestCouponPriceFormatted", "¥" + (priceInfo.getLowestCouponPrice() != null ? priceInfo.getLowestCouponPrice() / 100.0 : 0)); priceMap.put("lowestCouponPriceFormatted", "¥" + (priceInfo.getLowestCouponPrice() != null ? priceInfo.getLowestCouponPrice() / 100.0 : 0));
@@ -449,16 +382,9 @@ public class JDProductService {
log.error("提取价格信息时发生异常", e); log.error("提取价格信息时发生异常", e);
priceMap.put("error", "提取价格信息时发生异常: " + e.getMessage()); priceMap.put("error", "提取价格信息时发生异常: " + e.getMessage());
} }
return priceMap; return priceMap;
} }
/**
* 通过商品链接提取价格信息
*
* @param uJDUrl 京东商品链接
* @return 包含价格信息的Map
*/
public Map<String, Object> extractPriceInfoByUrl(String uJDUrl) { public Map<String, Object> extractPriceInfoByUrl(String uJDUrl) {
try { try {
GoodsQueryResult productInfo = queryProductInfoByUJDUrl(uJDUrl); GoodsQueryResult productInfo = queryProductInfoByUJDUrl(uJDUrl);

View File

@@ -165,10 +165,22 @@ public class JDUtil {
} }
private void handleProductWithJF() { private void handleProductWithJF() {
productWithJF.put("ZQD130F-EB130", "https://u.jd.com/v1cykVo"); /**
productWithJF.put("ZQD130F-EB130B", "https://u.jd.com/vDcy9SN"); * 130
productWithJF.put("ZQD150F-EB150", "https://u.jd.com/v1cykoL"); * https://u.jd.com/Y6ZKmwN
productWithJF.put("ZQD180F-EB200", "https://u.jd.com/v6cyfaX"); * 130B
* https://u.jd.com/YGZKHZS
* 150
* https://u.jd.com/YDZK5rD
* 180
* https://u.jd.com/YDZKmb2
* 92dpro
* https://u.jd.com/YgZKViD*/
productWithJF.put("ZQD130F-EB130", "https://u.jd.com/Y6ZKmwN");
productWithJF.put("ZQD130F-EB130B", "https://u.jd.com/YGZKHZS");
productWithJF.put("ZQD150F-EB150", " https://u.jd.com/YDZK5rD");
productWithJF.put("ZQD180F-EB200", "https://u.jd.com/YDZKmb2");
productWithJF.put("CXW-298-IQ92DPRO", "https://u.jd.com/Y1AMT2l");
} }
private List<OrderRow> filterOrdersByDate(List<OrderRow> orderRows, int daysBack) { private List<OrderRow> filterOrdersByDate(List<OrderRow> orderRows, int daysBack) {
@@ -1622,11 +1634,19 @@ public class JDUtil {
*/ */
public static List<String> extractUJDUrls(String message) { public static List<String> extractUJDUrls(String message) {
List<String> urls = new ArrayList<>(); List<String> urls = new ArrayList<>();
Pattern pattern = Pattern.compile("https://u\\.jd\\.com/\\S+"); // 支持两类链接:
// 1) u.jd.com 短链
// 2) jingfen.jd.com/detail/<token>.html协议可选
Pattern pattern = Pattern.compile("(?:https?://)?(?:u\\.jd\\.com/\\S+|jingfen\\.jd\\.com/detail/[^\\s]+\\.html)");
Matcher matcher = pattern.matcher(message); Matcher matcher = pattern.matcher(message);
while (matcher.find()) { while (matcher.find()) {
urls.add(matcher.group()); String found = matcher.group();
// 规范化:缺省协议时补全为 https://
if (!found.startsWith("http")) {
found = "https://" + found;
}
urls.add(found);
} }
return urls; return urls;

View File

@@ -184,8 +184,8 @@ public class WXUtil {
/* 线报采集来源群 */ /* 线报采集来源群 */
// 玩了买 // 玩了买
chatRoom_xb.put("23143922156@chatroom", "玩乐买"); chatRoom_xb.put("23143922156@chatroom", "玩乐买");
// 舵手群48621589056@chatroom"曲莉亚@河南慧推电子商务有限公司、齐学法@河南慧推电子商务有限公司"为企业微信用户,<_wc_custom_link_ href="https://weixin.qq.com/cgi-bin/newreadtemplate?t=work_wechat/about_group">了解更多</_wc_custom_link_>。
chatRoom_xb.put("48621589056@chatroom", "舵手"); chatRoom_xb.put("44980131813@chatroom", "舵手");
//786|14:05:38|wxid_kr145nk7l0an31|收到群聊|群46156118222@chatroom"130大号"修改群名为“\uD83E\uDD16 转链 礼金通知” //786|14:05:38|wxid_kr145nk7l0an31|收到群聊|群46156118222@chatroom"130大号"修改群名为“\uD83E\uDD16 转链 礼金通知”
chatRoom_xb.put("46156118222@chatroom", "测试群"); chatRoom_xb.put("46156118222@chatroom", "测试群");