拼多多地址

This commit is contained in:
Leo
2025-04-06 19:18:16 +08:00
parent ef8225be06
commit 2e4d9d97cd
2 changed files with 66 additions and 34 deletions

View File

@@ -152,6 +152,34 @@ public class JDUtil {
return todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 13 || orderRow.getValidCode() == 25 || orderRow.getValidCode() == 26 || orderRow.getValidCode() == 27 || orderRow.getValidCode() == 28 || orderRow.getValidCode() == 29);
}
/**
* 拼多多地址
*/
public String convertAddress(String input) {
try {
// 正则表达式分解输入内容
Pattern pattern = Pattern.compile("^(.+?)\\[(\\d+)\\]\\s+(\\d+)\\s+(.+)\\[\\d+\\]$");
Matcher matcher = pattern.matcher(input);
if (matcher.matches()) {
// 提取各部分内容
String name = matcher.group(1);
String code = matcher.group(2);
String phone = matcher.group(3);
String address = matcher.group(4).trim();
// 构造新地址格式
return String.format("%s 13068923963 %s联系客户%s转%s",
name,
address,
phone,
code);
}
} catch (Exception ignored) {
return "地址格式不匹配";
}
}
public void sendOrderToWxByOrderDefault(String order, String fromWxid) {
logger.info("执行 sendOrderToWxByOrderDefault 方法order: {}, fromWxid: {}", order, fromWxid);
handleUserInteraction(fromWxid, order);
@@ -186,6 +214,11 @@ public class JDUtil {
return content;
}
public void sendOrderToWxByOrderPDD(String order, String fromWxid) {
String convertAddress = convertAddress(order);
wxUtil.sendTextMessage(fromWxid, convertAddress, 0, fromWxid, false);
}
/**
* 接收京粉指令指令
@@ -617,6 +650,22 @@ public class JDUtil {
return result;
}
//public UnionOpenGoodsBigfieldQueryResponse getUnionOpenGoodsBigfieldQueryResponse(){
// JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, APP_KEY, SECRET_KEY);
//
// UnionOpenGoodsBigfieldQueryRequest request=new UnionOpenGoodsBigfieldQueryRequest();
// BigFieldGoodsReq goodsReq=new BigFieldGoodsReq();
// goodsReq.setSkuIds();
// request.setGoodsReq(goodsReq);
// request.setVersion("1.0");
// UnionOpenGoodsBigfieldQueryResponse response= null;
// try {
// response = client.execute(request);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// return response;
//}
/**
* 消毒柜部分的业务逻辑
@@ -638,22 +687,6 @@ public class JDUtil {
}
});
}
//public UnionOpenGoodsBigfieldQueryResponse getUnionOpenGoodsBigfieldQueryResponse(){
// JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, APP_KEY, SECRET_KEY);
//
// UnionOpenGoodsBigfieldQueryRequest request=new UnionOpenGoodsBigfieldQueryRequest();
// BigFieldGoodsReq goodsReq=new BigFieldGoodsReq();
// goodsReq.setSkuIds();
// request.setGoodsReq(goodsReq);
// request.setVersion("1.0");
// UnionOpenGoodsBigfieldQueryResponse response= null;
// try {
// response = client.execute(request);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// return response;
//}
private void handleUserInteraction(String fromWxid, String message) {
String key = INTERACTION_STATE_PREFIX + fromWxid;
@@ -702,7 +735,6 @@ public class JDUtil {
return state;
}
private boolean isStateExpired(UserInteractionState state) {
LocalDateTime lastTime = LocalDateTime.parse(state.getLastInteractionTime(), DATE_TIME_FORMATTER);
return ChronoUnit.MINUTES.between(lastTime, LocalDateTime.now()) > TIMEOUT_MINUTES;
@@ -851,7 +883,7 @@ public class JDUtil {
state.setCurrentField("confirm");
try {
Thread.sleep(5000);
}catch (InterruptedException ignored){
} catch (InterruptedException ignored) {
}
wxUtil.sendTextMessage(wxid,
@@ -932,7 +964,6 @@ public class JDUtil {
saveState(INTERACTION_STATE_PREFIX + wxid, state);
}
// 在发送提示信息时增加进度指示
private void sendStepPrompt(String wxid, int step, int totalSteps) {
String progress = String.format("[%d/%d] ", step, totalSteps);
@@ -1083,7 +1114,6 @@ public class JDUtil {
}
}
/**
* 生成转链和方案的方法
*
@@ -1487,7 +1517,6 @@ public class JDUtil {
return urls;
}
/**
* 通过这个可以将u.jd.*** 查询到对应的商品信息 和 商品图片,甚至可以查询到是不是自营的商品
*/
@@ -1573,7 +1602,6 @@ public class JDUtil {
return queryResult;
}
// 新增礼金创建方法
public String createGiftCoupon(String skuId, double amount, int quantity, String owner, String skuName) throws Exception {
logger.debug("准备创建礼金SKU={}, 金额={}元,数量={}, Owner={}", skuId, amount, quantity, owner);
@@ -1643,7 +1671,6 @@ public class JDUtil {
return null;
}
// 修改activateGiftMoney方法调用真实接口
private boolean activateGiftMoney(String skuId, double amount, int quantity, String owner) {
return false;
@@ -1667,7 +1694,6 @@ public class JDUtil {
return "200".equals(response.getCode());
}
boolean isValidAmount(String input) {
// 新增:直接处理 null 或空字符串
if (input == null || input.trim().isEmpty()) {
@@ -1681,7 +1707,6 @@ public class JDUtil {
}
}
private boolean isValidQuantity(String input) {
if (input == null || input.trim().isEmpty()) {
logger.error("数量为空或无效: {}", input);

View File

@@ -247,7 +247,19 @@ private void handlePrivateMessage(WxMessage wxMessage) throws Exception {
}
String msg = innerData.getMsg();
if (msg.startsWith("")) {
logger.info("消息以京开头,处理京东指令消息");
jdUtils.sendOrderToWxByOrderJD(msg.replace("", ""), fromWxid);
return;
} else {
logger.info("消息不以京开头");
}
if (msg.startsWith("")) {
logger.info("消息以拼开头,处理拼多多指令消息");
jdUtils.sendOrderToWxByOrderPDD(msg.replace("", ""), fromWxid);
return;
}
logger.info("未命中前置指令,开始命中 Default 流程");
jdUtils.sendOrderToWxByOrderDefault(msg, fromWxid);
}
private void handleGroupMessage (WxMessage wxMessage) {
@@ -269,16 +281,11 @@ private void handlePrivateMessage(WxMessage wxMessage) throws Exception {
}
String msg = innerData.getMsg();
if (msg.startsWith("")) {
logger.info("消息以京开头,处理京东指令消息");
jdUtils.sendOrderToWxByOrderJD(msg.replace("", ""), fromWxid);
if (msg.startsWith("")) {
logger.info("消息以拼开头,处理拼多多指令消息");
jdUtils.sendOrderToWxByOrderPDD(msg.replace("", ""), fromWxid);
return;
} else {
logger.info("消息不以京开头");
}
logger.info("未命中前置指令,开始命中 Default 流程");
jdUtils.sendOrderToWxByOrderDefault(msg, fromWxid);
/**