From acd693f1229fdd485954d5eebd075f06c9a5592c Mon Sep 17 00:00:00 2001 From: van Date: Thu, 23 Apr 2026 21:55:47 +0800 Subject: [PATCH] 1 --- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-prod.yml | 2 +- .../service/impl/OpenPhoneForwardService.java | 46 +++++++++++++++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 03a921a..41a7345 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -237,7 +237,7 @@ jarvis: # wait_reply 时服务端会等多条 Bot 回复,宜适当加大 read-timeout-ms: 120000 wait-reply: true - reply-take-nth: 2 + # reply_take_nth 由 Java 按 bot 固定:开(AJL05_bot)=2,慢开(QingBao)=3 # Ollama 大模型服务(监控健康度调试用) ollama: base-url: http://192.168.8.34:11434 diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 7d66184..9d9574d 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -226,7 +226,7 @@ jarvis: connect-timeout-ms: 8000 read-timeout-ms: 120000 wait-reply: true - reply-take-nth: 2 + # reply_take_nth:Java 按 bot 固定(开=2,慢开=3) # Ollama 大模型服务(监控健康度调试用) ollama: base-url: http://192.168.8.34:11434 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 0917872..ce03610 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 @@ -21,8 +21,8 @@ import java.util.regex.Pattern; * 企微「开」/「慢开」+ 手机号: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}(前几条如「查询中…」由对端丢弃)。 + * {@code wait_reply} 时按 Bot 取第 N 条回复:{@code AJL05_bot} 为第 2 条,{@code QingBaoJuXWsgkbot} 为第 3 条; + * 「慢开」返回正文会去掉固定广告行(替换为空格)。 *

*/ @Service @@ -38,6 +38,20 @@ public class OpenPhoneForwardService { /** 「慢开」→ 对应 Bot 用户名 */ private static final String BOT_SLOW_OPEN = "QingBaoJuXWsgkbot"; + private static final int REPLY_TAKE_NTH_OPEN_BOT = 2; + + private static final int REPLY_TAKE_NTH_SLOW_BOT = 3; + + /** + * QingBao 机器人回复尾部的固定推广行(👉 与正文间可能含 ZWJ U+200D),整段替换为空格。 + */ + private static final String[] QINGBAO_REPLY_JUNK = { + "\uD83D\uDC49\u200D公安路线查询价格表 (https://t.me/+C20ADPmEKJU0ZGFl)\uD83D\uDC48", + "\uD83D\uDC49\u200D如机器人提示被注销点我防丢 (https://telegra.ph/qingbaoju-10-01)\uD83D\uDC48", + "\uD83D\uDC49公安路线查询价格表 (https://t.me/+C20ADPmEKJU0ZGFl)\uD83D\uDC48", + "\uD83D\uDC49如机器人提示被注销点我防丢 (https://telegra.ph/qingbaoju-10-01)\uD83D\uDC48", + }; + @Value("${jarvis.phone-forward.enabled:false}") private boolean enabled; @@ -57,10 +71,6 @@ public class OpenPhoneForwardService { @Value("${jarvis.phone-forward.wait-reply:true}") private boolean waitReply; - /** 与 wait_reply 配合:取第几条 Bot 回复作为 reply_text,须 ≥ 1 */ - @Value("${jarvis.phone-forward.reply-take-nth:2}") - private int replyTakeNth; - /** * @return 非 null 表示本条消息已由本服务处理(含错误提示);null 表示不匹配规则 */ @@ -111,10 +121,7 @@ public class OpenPhoneForwardService { body.put("text", phone); body.put("bot", bot); if (waitReply) { - int nth = replyTakeNth >= 1 ? replyTakeNth : 1; - if (replyTakeNth < 1) { - log.warn("phone-forward reply-take-nth={} 无效,已按 1 处理", replyTakeNth); - } + int nth = replyTakeNthForBot(bot); body.put("wait_reply", true); body.put("reply_take_nth", nth); } @@ -147,6 +154,9 @@ public class OpenPhoneForwardService { if (!StringUtils.hasText(reply)) { return "「转发服务」未返回 reply_text。"; } + if (BOT_SLOW_OPEN.equals(bot)) { + reply = filterQingBaoAdLines(reply); + } return reply; } finally { if (conn != null) { @@ -159,6 +169,22 @@ public class OpenPhoneForwardService { } } + private static int replyTakeNthForBot(String bot) { + if (BOT_SLOW_OPEN.equals(bot)) { + return REPLY_TAKE_NTH_SLOW_BOT; + } + return REPLY_TAKE_NTH_OPEN_BOT; + } + + /** 将固定广告段替换为空格后 trim。 */ + private static String filterQingBaoAdLines(String reply) { + String s = reply; + for (String junk : QINGBAO_REPLY_JUNK) { + s = s.replace(junk, " "); + } + return s.trim(); + } + private static String readAll(InputStream is) throws java.io.IOException { if (is == null) { return "";