This commit is contained in:
van
2026-04-23 21:48:23 +08:00
parent 256b54ffab
commit 751844493b
3 changed files with 22 additions and 9 deletions

View File

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

View File

@@ -18,7 +18,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 企微「开」+ 手机号POST 局域网 /v1/forward将 JSON 中的 {@code reply_text} 作为回显。
* 企微「开」/「慢开」+ 手机号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}(前几条如「查询中…」由对端丢弃)。
@@ -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 与局域网服务可达。";
}
}

View File

@@ -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_textbody 含对应 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());
}
}