1
This commit is contained in:
@@ -228,7 +228,7 @@ jarvis:
|
|||||||
session-ttl-minutes: 30
|
session-ttl-minutes: 30
|
||||||
session-idle-timeout-minutes: 30
|
session-idle-timeout-minutes: 30
|
||||||
session-sweep-ms: 60000
|
session-sweep-ms: 60000
|
||||||
# 企微「开」+ 手机号:Jarvis POST 该局域网接口,将响应中的 reply_text 被动回复给用户
|
# 企微「开」/「慢开」+ 手机号:POST body 含 text(手机号)与 bot;响应 reply_text 被动回复用户
|
||||||
phone-forward:
|
phone-forward:
|
||||||
enabled: true
|
enabled: true
|
||||||
base-url: http://192.168.8.60:18080
|
base-url: http://192.168.8.60:18080
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企微「开」+ 手机号:POST 局域网 /v1/forward,将 JSON 中的 {@code reply_text} 作为回显。
|
* 企微「开」/「慢开」+ 手机号:POST 局域网 /v1/forward,body 含 {@code text}(手机号)与 {@code bot},
|
||||||
|
* 将 JSON 中的 {@code reply_text} 作为回显。
|
||||||
* <p>
|
* <p>
|
||||||
* 可配置 {@code wait_reply} / {@code reply_take_nth}:服务端先发 text,再等 Bot 回 N 次,
|
* 可配置 {@code wait_reply} / {@code reply_take_nth}:服务端先发 text,再等 Bot 回 N 次,
|
||||||
* 将第 N 条内容填入 {@code reply_text}(前几条如「查询中…」由对端丢弃)。
|
* 将第 N 条内容填入 {@code reply_text}(前几条如「查询中…」由对端丢弃)。
|
||||||
@@ -31,6 +32,12 @@ public class OpenPhoneForwardService {
|
|||||||
|
|
||||||
private static final Pattern MOBILE_11 = Pattern.compile("(1\\d{10})");
|
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}")
|
@Value("${jarvis.phone-forward.enabled:false}")
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
@@ -62,14 +69,19 @@ public class OpenPhoneForwardService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String text = rawContent.trim().replaceFirst("^\uFEFF", "");
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
String phone = extractFirstMobile11(text);
|
String phone = extractFirstMobile11(text);
|
||||||
if (phone == null) {
|
if (phone == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return doForward(phone);
|
return doForward(phone, bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String extractFirstMobile11(String text) {
|
private static String extractFirstMobile11(String text) {
|
||||||
@@ -80,7 +92,7 @@ public class OpenPhoneForwardService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doForward(String phone) {
|
private String doForward(String phone, String bot) {
|
||||||
try {
|
try {
|
||||||
String base = baseUrl.trim();
|
String base = baseUrl.trim();
|
||||||
if (base.endsWith("/")) {
|
if (base.endsWith("/")) {
|
||||||
@@ -97,6 +109,7 @@ public class OpenPhoneForwardService {
|
|||||||
|
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("text", phone);
|
body.put("text", phone);
|
||||||
|
body.put("bot", bot);
|
||||||
if (waitReply) {
|
if (waitReply) {
|
||||||
int nth = replyTakeNth >= 1 ? replyTakeNth : 1;
|
int nth = replyTakeNth >= 1 ? replyTakeNth : 1;
|
||||||
if (replyTakeNth < 1) {
|
if (replyTakeNth < 1) {
|
||||||
@@ -141,7 +154,7 @@ public class OpenPhoneForwardService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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 与局域网服务可达。";
|
return "「转发服务」连接失败,请确认 Jarvis 与局域网服务可达。";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.util.regex.Pattern;
|
|||||||
/**
|
/**
|
||||||
* LinPingFan:全部指令;其他人员:须在超级管理员中识别为本人(wxid=企微 UserID,**或** 企微 UserID 出现在 touser 逗号分隔列表中),且仅「京*」指令 + 京东分享物流链接流程;
|
* LinPingFan:全部指令;其他人员:须在超级管理员中识别为本人(wxid=企微 UserID,**或** 企微 UserID 出现在 touser 逗号分隔列表中),且仅「京*」指令 + 京东分享物流链接流程;
|
||||||
* 例外:以「单」或「开始」开头且含「分销标记」的录单正文优先于物流(不进入 3.cn 多轮、不占用物流监听)。
|
* 例外:以「单」或「开始」开头且含「分销标记」的录单正文优先于物流(不进入 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 思路一致。
|
* 多轮会话使用 Redis({@link WeComChatSession},键 interaction_state:wecom:{FromUserName}),与旧版「开通礼金」interaction_state 思路一致。
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@@ -53,7 +53,7 @@ public class WeComInboundServiceImpl implements IWeComInboundService {
|
|||||||
+ "· 「京」开头的统计、订单类指令(可先发「京菜单」查看列表)\n"
|
+ "· 「京」开头的统计、订单类指令(可先发「京菜单」查看列表)\n"
|
||||||
+ "· 含 3.cn 的京东物流分享:先发链接,再发备注\n"
|
+ "· 含 3.cn 的京东物流分享:先发链接,再发备注\n"
|
||||||
+ "· 以「单」或「开始」开头,且含「分销标记」的录单正文\n"
|
+ "· 以「单」或「开始」开头,且含「分销标记」的录单正文\n"
|
||||||
+ "· 以「开」开头且含手机号的查询\n\n"
|
+ "· 以「开」或「慢开」开头且含手机号的查询\n\n"
|
||||||
+ "如需其他指令,请联系管理员。";
|
+ "如需其他指令,请联系管理员。";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ public class WeComInboundServiceImpl implements IWeComInboundService {
|
|||||||
|
|
||||||
if (!isSuper) {
|
if (!isSuper) {
|
||||||
String cmd = content.trim().replaceFirst("^\uFEFF", "");
|
String cmd = content.trim().replaceFirst("^\uFEFF", "");
|
||||||
if (!cmd.startsWith("京") && !danRecordPriority && !cmd.startsWith("开")) {
|
if (!cmd.startsWith("京") && !danRecordPriority && !cmd.startsWith("开") && !cmd.startsWith("慢开")) {
|
||||||
return WeComInboundResult.passiveOnly(replyGeneralUserScopeHint());
|
return WeComInboundResult.passiveOnly(replyGeneralUserScopeHint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user