From 751844493b5a562d4b9c37648fda9dd7ba7cc63d Mon Sep 17 00:00:00 2001 From: van Date: Thu, 23 Apr 2026 21:48:23 +0800 Subject: [PATCH] 1 --- .../src/main/resources/application-dev.yml | 2 +- .../service/impl/OpenPhoneForwardService.java | 23 +++++++++++++++---- .../service/impl/WeComInboundServiceImpl.java | 6 ++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index ebfc2e5..03a921a 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -228,7 +228,7 @@ jarvis: session-ttl-minutes: 30 session-idle-timeout-minutes: 30 session-sweep-ms: 60000 - # 企微「开」+ 手机号:Jarvis POST 该局域网接口,将响应中的 reply_text 被动回复给用户 + # 企微「开」/「慢开」+ 手机号:POST body 含 text(手机号)与 bot;响应 reply_text 被动回复用户 phone-forward: enabled: true base-url: http://192.168.8.60:18080 diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/OpenPhoneForwardService.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/OpenPhoneForwardService.java index 6683d5c..0917872 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/OpenPhoneForwardService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/OpenPhoneForwardService.java @@ -18,7 +18,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * 企微「开」+ 手机号:POST 局域网 /v1/forward,将 JSON 中的 {@code reply_text} 作为回显。 + * 企微「开」/「慢开」+ 手机号:POST 局域网 /v1/forward,body 含 {@code text}(手机号)与 {@code bot}, + * 将 JSON 中的 {@code reply_text} 作为回显。 *

* 可配置 {@code wait_reply} / {@code reply_take_nth}:服务端先发 text,再等 Bot 回 N 次, * 将第 N 条内容填入 {@code reply_text}(前几条如「查询中…」由对端丢弃)。 @@ -31,6 +32,12 @@ public class OpenPhoneForwardService { private static final Pattern MOBILE_11 = Pattern.compile("(1\\d{10})"); + /** 「开」→ 对应 Bot 用户名(与对端 {@code bot} 字段一致,不含 @) */ + private static final String BOT_OPEN = "AJL05_bot"; + + /** 「慢开」→ 对应 Bot 用户名 */ + private static final String BOT_SLOW_OPEN = "QingBaoJuXWsgkbot"; + @Value("${jarvis.phone-forward.enabled:false}") private boolean enabled; @@ -62,14 +69,19 @@ public class OpenPhoneForwardService { return null; } String text = rawContent.trim().replaceFirst("^\uFEFF", ""); - if (!text.startsWith("开")) { + String bot; + if (text.startsWith("慢开")) { + bot = BOT_SLOW_OPEN; + } else if (text.startsWith("开")) { + bot = BOT_OPEN; + } else { return null; } String phone = extractFirstMobile11(text); if (phone == null) { return null; } - return doForward(phone); + return doForward(phone, bot); } private static String extractFirstMobile11(String text) { @@ -80,7 +92,7 @@ public class OpenPhoneForwardService { return null; } - private String doForward(String phone) { + private String doForward(String phone, String bot) { try { String base = baseUrl.trim(); if (base.endsWith("/")) { @@ -97,6 +109,7 @@ public class OpenPhoneForwardService { JSONObject body = new JSONObject(); body.put("text", phone); + body.put("bot", bot); if (waitReply) { int nth = replyTakeNth >= 1 ? replyTakeNth : 1; if (replyTakeNth < 1) { @@ -141,7 +154,7 @@ public class OpenPhoneForwardService { } } } catch (Exception e) { - log.warn("phone-forward 异常 phone={} err={}", phone, e.toString()); + log.warn("phone-forward 异常 phone={} bot={} err={}", phone, bot, e.toString()); return "「转发服务」连接失败,请确认 Jarvis 与局域网服务可达。"; } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComInboundServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComInboundServiceImpl.java index 18987ec..7a19a28 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComInboundServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComInboundServiceImpl.java @@ -23,7 +23,7 @@ import java.util.regex.Pattern; /** * LinPingFan:全部指令;其他人员:须在超级管理员中识别为本人(wxid=企微 UserID,**或** 企微 UserID 出现在 touser 逗号分隔列表中),且仅「京*」指令 + 京东分享物流链接流程; * 例外:以「单」或「开始」开头且含「分销标记」的录单正文优先于物流(不进入 3.cn 多轮、不占用物流监听)。 - * 以「开」开头且正文含 11 位手机号(1 开头):POST 配置项 jarvis.phone-forward 指向的局域网服务,回显 reply_text。 + * 以「开」或「慢开」开头且正文含 11 位手机号(1 开头):POST 配置项 jarvis.phone-forward 指向的局域网服务,回显 reply_text(body 含对应 bot)。 * 多轮会话使用 Redis({@link WeComChatSession},键 interaction_state:wecom:{FromUserName}),与旧版「开通礼金」interaction_state 思路一致。 */ @Service @@ -53,7 +53,7 @@ public class WeComInboundServiceImpl implements IWeComInboundService { + "· 「京」开头的统计、订单类指令(可先发「京菜单」查看列表)\n" + "· 含 3.cn 的京东物流分享:先发链接,再发备注\n" + "· 以「单」或「开始」开头,且含「分销标记」的录单正文\n" - + "· 以「开」开头且含手机号的查询\n\n" + + "· 以「开」或「慢开」开头且含手机号的查询\n\n" + "如需其他指令,请联系管理员。"; } @@ -163,7 +163,7 @@ public class WeComInboundServiceImpl implements IWeComInboundService { if (!isSuper) { String cmd = content.trim().replaceFirst("^\uFEFF", ""); - if (!cmd.startsWith("京") && !danRecordPriority && !cmd.startsWith("开")) { + if (!cmd.startsWith("京") && !danRecordPriority && !cmd.startsWith("开") && !cmd.startsWith("慢开")) { return WeComInboundResult.passiveOnly(replyGeneralUserScopeHint()); } }