This commit is contained in:
van
2026-04-23 21:55:47 +08:00
parent 751844493b
commit acd693f122
3 changed files with 38 additions and 12 deletions

View File

@@ -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

View File

@@ -226,7 +226,7 @@ jarvis:
connect-timeout-ms: 8000
read-timeout-ms: 120000
wait-reply: true
reply-take-nth: 2
# reply_take_nthJava 按 bot 固定(开=2慢开=3
# Ollama 大模型服务(监控健康度调试用)
ollama:
base-url: http://192.168.8.34:11434

View File

@@ -21,8 +21,8 @@ import java.util.regex.Pattern;
* 企微「开」/「慢开」+ 手机号POST 局域网 /v1/forwardbody 含 {@code text}(手机号)与 {@code bot}
* 将 JSON 中的 {@code reply_text} 作为回显。
* <p>
* 可配置 {@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 条;
* 「慢开」返回正文会去掉固定广告行(替换为空格)。
* </p>
*/
@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 "";