This commit is contained in:
雷欧(林平凡)
2025-01-09 11:22:35 +08:00
parent e54de8e55e
commit 3e617ad656
4 changed files with 49 additions and 15 deletions

View File

@@ -492,7 +492,7 @@ public class JDUtils {
/** /**
* 接收京粉指令指令 * 接收京粉指令指令
*/ */
public void sendOrderToWxByOrderJD(String order) { public void sendOrderToWxByOrderJD(String order,String fromWxid) {
int[] param = {-1}; int[] param = {-1};
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(param); List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(param);
/** /**
@@ -781,10 +781,10 @@ public class JDUtils {
} }
default: default:
sendOrderToWxByOrderJDAdvanced(order); sendOrderToWxByOrderJDAdvanced(order,fromWxid);
} }
if (content.length() > 0) { if (content.length() > 0) {
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid); wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1,fromWxid);
} }
} }
@@ -793,7 +793,7 @@ public class JDUtils {
* 接收京粉指令指令 * 接收京粉指令指令
* 高级菜单 * 高级菜单
*/ */
public void sendOrderToWxByOrderJDAdvanced(String order) { public void sendOrderToWxByOrderJDAdvanced(String order,String fromWxid) {
int[] parm = {-1}; int[] parm = {-1};
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm); List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);
@@ -855,13 +855,13 @@ public class JDUtils {
for (String s : split) { for (String s : split) {
content.append("https://item.jd.com/").append(s).append(".html").append("\r\n"); content.append("https://item.jd.com/").append(s).append(".html").append("\r\n");
} }
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid); wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, fromWxid);
content = new StringBuilder(); content = new StringBuilder();
content.append("手机端").append("\r\n"); content.append("手机端").append("\r\n");
for (String s : split) { for (String s : split) {
content.append("https://item.m.jd.com/product/").append(s).append(".html").append("\r\n"); content.append("https://item.m.jd.com/product/").append(s).append(".html").append("\r\n");
} }
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid); wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, fromWxid);
content = new StringBuilder(); content = new StringBuilder();
@@ -876,13 +876,13 @@ public class JDUtils {
} }
} else { } else {
try { try {
sendOrderToWxByOrderJD("菜单"); sendOrderToWxByOrderJD("菜单",fromWxid);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
if (content.length() > 0) { if (content.length() > 0) {
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid); wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, fromWxid);
} }
} }
//public UnionOpenGoodsBigfieldQueryResponse getUnionOpenGoodsBigfieldQueryResponse(){ //public UnionOpenGoodsBigfieldQueryResponse getUnionOpenGoodsBigfieldQueryResponse(){

View File

@@ -13,6 +13,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import static cn.van.business.util.WXUtil.jdidToWxidMap;
/** /**
* @author Leo * @author Leo
@@ -49,7 +51,8 @@ public class OrderUtil {
if (!isAutoFlush || !lastValidCode.equals(newValidCode)) { if (!isAutoFlush || !lastValidCode.equals(newValidCode)) {
// 当 isAutoFlush 为 false 或状态确实有变化时,进行消息发送 // 当 isAutoFlush 为 false 或状态确实有变化时,进行消息发送
String content = getFormattedOrderInfo(orderRow, lastValidCode); String content = getFormattedOrderInfo(orderRow, lastValidCode);
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content, 1, WXUtil.super_admin_wxid); String wxId = jdidToWxidMap.get(orderRow.getUnionId());
wxUtil.sendTextMessage(wxId, content, 1, wxId);
} }
// 更新 Redis 状态值 // 更新 Redis 状态值

View File

@@ -15,10 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
/** /**
* @author Leo * @author Leo
@@ -31,6 +28,38 @@ public class WXUtil {
private static final Logger logger = LoggerFactory.getLogger(WXUtil.class); private static final Logger logger = LoggerFactory.getLogger(WXUtil.class);
public static final String super_admin_wxid = "wxid_ytpc72mdoskt22"; public static final String super_admin_wxid = "wxid_ytpc72mdoskt22";
public static Map<String, SuperAdmin> super_admins = new HashMap<>();
public static Map<String, String> jdidToWxidMap = new HashMap<>();
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SuperAdmin {
private String wxid;
private String name;
// 联盟ID
private String unionId;
private String appKey ;
private String secretKey ;
}
// 初始化超级管理员
public void initSuperAdmins() {
SuperAdmin admin1 = new SuperAdmin("wxid_ytpc72mdoskt22", "", "2014264913","98e21c89ae5610240ec3f5f575f86a59","3dcb6b23a1104639ac433fd07adb6dfb");
super_admins.put(admin1.getWxid(), admin1);
jdidToWxidMap.put(admin1.getUnionId(), admin1.getWxid());
SuperAdmin admin2 = new SuperAdmin("wxid_yneqf1implxu12", "", "","","");
super_admins.put(admin2.getWxid(), admin2);
jdidToWxidMap.put(admin2.getUnionId(), admin2.getWxid());
// add more admins as needed...
}
public static String getWxidFromJdid(String jdid) {
return jdidToWxidMap.get(jdid);
}
/** /**
* url http://127.0.0.1:7777/DaenWxHook/httpapi/ * url http://127.0.0.1:7777/DaenWxHook/httpapi/
* 获取微信列表 (X0000) * 获取微信列表 (X0000)

View File

@@ -21,6 +21,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static cn.van.business.util.WXUtil.super_admin_wxid; import static cn.van.business.util.WXUtil.super_admin_wxid;
import static cn.van.business.util.WXUtil.super_admins;
/** /**
@@ -286,7 +287,8 @@ public class WxMessageConsumer {
return; return;
} }
// 只处理超管的消息 // 只处理超管的消息
if (!Objects.equals(innerData.getFromWxid(), super_admin_wxid)) { String fromWxid = innerData.getFromWxid();
if (!Objects.equals(fromWxid, super_admins.get(super_admin_wxid).getWxid())) {
logger.info("不是超管消息,不处理"); logger.info("不是超管消息,不处理");
return; return;
} }
@@ -314,7 +316,7 @@ public class WxMessageConsumer {
// wxUtil.sendTextMessage(wxid, transferResultUrl, msgType, null); // wxUtil.sendTextMessage(wxid, transferResultUrl, msgType, null);
//} //}
} else if (msg.startsWith("")) { } else if (msg.startsWith("")) {
jdUtils.sendOrderToWxByOrderJD(msg.replace("", "")); jdUtils.sendOrderToWxByOrderJD(msg.replace("", ""),fromWxid);
} }
//else if (msg.startsWith("美团 ")) { //else if (msg.startsWith("美团 ")) {
// logger.info("处理美团的消息"); // logger.info("处理美团的消息");