Merge remote-tracking branch '群晖/master'
This commit is contained in:
@@ -36,6 +36,9 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static cn.van.business.util.JDUtil.*;
|
||||
|
||||
/**
|
||||
* 京东商品服务类,抽取来源于JDUtil
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class JDProductService {
|
||||
@@ -59,6 +62,13 @@ public class JDProductService {
|
||||
this.xbMessageItemRepository = xbMessageItemRepository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成转链和方案的方法(JSON数组格式)
|
||||
*
|
||||
* @param message 方案内容,包含商品链接
|
||||
* @return 处理后的方案,以标准JSON数组格式返回,每个商品及其文案为一个独立对象
|
||||
*/
|
||||
public synchronized JSONArray generatePromotionContentAsJsonArray(String message) {
|
||||
JSONArray resultArray = new JSONArray();
|
||||
List<String> urls = extractUJDUrls(message);
|
||||
@@ -84,7 +94,9 @@ public class JDProductService {
|
||||
}
|
||||
|
||||
JSONObject productObj = new JSONObject();
|
||||
productObj.put("url", url);
|
||||
productObj.put("originalUrl", url);
|
||||
|
||||
// 商品基本信息
|
||||
productObj.put("materialUrl", productInfo.getData()[0].getMaterialUrl());
|
||||
productObj.put("oriItemId", productInfo.getData()[0].getOriItemId());
|
||||
productObj.put("owner", productInfo.getData()[0].getOwner());
|
||||
@@ -109,7 +121,29 @@ 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();
|
||||
|
||||
String title = "";
|
||||
try {
|
||||
if (!message.equals(url)) {
|
||||
@@ -126,6 +160,7 @@ public class JDProductService {
|
||||
log.error("文案首行异常", e);
|
||||
}
|
||||
|
||||
// 生成各种文案
|
||||
JSONObject wenan1 = new JSONObject();
|
||||
wenan1.put("type", "标价到手-方案1");
|
||||
wenan1.put("content", "(标价到手) " + title + cleanSkuName + "\n" + WENAN_FANAN_LQD.replaceAll("更新", format + "更新"));
|
||||
@@ -146,9 +181,14 @@ public class JDProductService {
|
||||
wenan4.put("content", "【教你下单】 " + title + cleanSkuName + "\n" + WENAN_FANAN_BX.replaceAll("信息更新日期:", "信息更新日期:" + format));
|
||||
wenanArray.add(wenan4);
|
||||
|
||||
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);
|
||||
|
||||
productObj.put("wenan", wenanArray);
|
||||
@@ -162,9 +202,17 @@ public class JDProductService {
|
||||
resultArray.add(errorObj);
|
||||
}
|
||||
}
|
||||
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品信息
|
||||
*
|
||||
* @param uJDUrl 京东商品链接
|
||||
* @return 商品查询结果
|
||||
* @throws Exception 查询异常
|
||||
*/
|
||||
public GoodsQueryResult queryProductInfoByUJDUrl(String uJDUrl) throws Exception {
|
||||
UnionOpenGoodsQueryResponse response = getUnionOpenGoodsQueryRequest(uJDUrl);
|
||||
if (response == null || response.getQueryResult() == null) return null;
|
||||
@@ -173,8 +221,16 @@ public class JDProductService {
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用京东开放平台接口查询商品信息
|
||||
*
|
||||
* @param uJDUrl 京东商品链接
|
||||
* @return 京东商品查询响应
|
||||
* @throws Exception 查询异常
|
||||
*/
|
||||
public UnionOpenGoodsQueryResponse getUnionOpenGoodsQueryRequest(String uJDUrl) throws Exception {
|
||||
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_SECRET_KEY_WZ);
|
||||
|
||||
UnionOpenGoodsQueryRequest request = new UnionOpenGoodsQueryRequest();
|
||||
GoodsReq goodsReq = new GoodsReq();
|
||||
goodsReq.setKeyword(uJDUrl);
|
||||
@@ -195,6 +251,7 @@ public class JDProductService {
|
||||
owner = (owner != null && !owner.isEmpty()) ? owner : "g";
|
||||
|
||||
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_SECRET_KEY_WZ);
|
||||
|
||||
UnionOpenCouponGiftGetRequest request = new UnionOpenCouponGiftGetRequest();
|
||||
CreateGiftCouponReq couponReq = new CreateGiftCouponReq();
|
||||
couponReq.setSkuMaterialId(skuId);
|
||||
@@ -236,8 +293,16 @@ public class JDProductService {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转链接口:通过商品链接、领券链接、活动链接获取普通推广链接或优惠券二合一推广链接
|
||||
*
|
||||
* @param url 原始链接
|
||||
* @param giftCouponKey 礼金Key(可选)
|
||||
* @return 转换后的短链接
|
||||
*/
|
||||
public String transfer(String url, String giftCouponKey) {
|
||||
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_SECRET_KEY_WZ);
|
||||
|
||||
UnionOpenPromotionBysubunionidGetRequest request = new UnionOpenPromotionBysubunionidGetRequest();
|
||||
PromotionCodeReq promotionCodeReq = new PromotionCodeReq();
|
||||
promotionCodeReq.setSceneId(1);
|
||||
@@ -245,6 +310,7 @@ public class JDProductService {
|
||||
if (giftCouponKey != null && !giftCouponKey.isEmpty()) {
|
||||
promotionCodeReq.setGiftCouponKey(giftCouponKey);
|
||||
}
|
||||
|
||||
request.setPromotionCodeReq(promotionCodeReq);
|
||||
request.setVersion("1.0");
|
||||
|
||||
@@ -260,6 +326,14 @@ public class JDProductService {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将礼金信息写入Redis
|
||||
*
|
||||
* @param skuId 商品SKU ID
|
||||
* @param giftKey 礼金Key
|
||||
* @param skuName 商品名称
|
||||
* @param owner 商品所有者
|
||||
*/
|
||||
public void saveGiftCouponToRedis(String skuId, String giftKey, String skuName, String owner) {
|
||||
String key = "gift_coupon:" + skuId;
|
||||
String hashKey = giftKey;
|
||||
@@ -271,9 +345,16 @@ public class JDProductService {
|
||||
data.put("owner", owner);
|
||||
data.put("expireTime", expireTime.format(DateTimeFormatter.ISO_DATE_TIME));
|
||||
|
||||
// 存入 Redis Hash
|
||||
redisTemplate.opsForHash().put(key, hashKey, JSON.toJSONString(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取商品价格信息
|
||||
*
|
||||
* @param productInfo 商品查询结果
|
||||
* @return 包含价格信息的Map
|
||||
*/
|
||||
public Map<String, Object> extractPriceInfo(GoodsQueryResult productInfo) {
|
||||
Map<String, Object> priceMap = new HashMap<>();
|
||||
if (productInfo == null || productInfo.getData() == null || productInfo.getData().length == 0) {
|
||||
|
||||
@@ -107,7 +107,7 @@ public class JDUtil {
|
||||
5:全国联保,全国统一安装标准。支持官方 400,服务号查询,假一赔十。
|
||||
""";
|
||||
public static final String WENAN_FANAN_BX = "本人提供免费指导下单服务,一台也是团购价,细心指导\n" + "\n" + "【质量】官旗下单,包正的\n" + "【物流】您自己账户可跟踪,24小时发货\n" + "【售后】您自己账户直接联系,无忧售后\n" + "【安装】专业人员安装,全程无需您操心\n" + "【价格】标价就是到手价,骑共享单车去酒吧,该省省该花花\n" + "【服务】手把手教您下单,有问题随时咨询\n" + "【体验】所有服务都是官旗提供,价格有内部渠道优惠,同品质更优惠!\n" + "\n" + "信息更新日期:\n" + "\n" + "捡漏价格不定时有变动,优惠不等人,发「省份+型号」免费咨询当日最低价!";
|
||||
public static final String FANAN_COMMON = "\n1 文案复制到微,点击领券,到J东APP结算\n" + "2 换新可直接代消单,不用提供回收\n " + "3 独家虹包 https://u.jd.com/raa0eI4 至高可领256188 \n";
|
||||
public static final String FANAN_COMMON = "\n 文案复制到微x,点击领券,把商品加到J东,去APP结算才能显示折扣补贴\n";
|
||||
|
||||
/**
|
||||
* 内部单号:
|
||||
|
||||
Reference in New Issue
Block a user