This commit is contained in:
van
2026-05-09 23:38:10 +08:00
parent 7582d22d2a
commit 217ea3afdc
4 changed files with 119 additions and 31 deletions

View File

@@ -9,10 +9,11 @@ import java.util.List;
public interface IPhoneForwardActivePush {
/**
* 异步排队推送到企微成员
* 在被动回复已发出后,按序推送到企微成员(首条前短暂延迟,避免次序错乱)。
*
* @param toUser 成员 UserIDFromUserName
* @param chunks 每段不超过 UTF-8 2048 字节的正文
* @return {@code true} 表示配置齐全且每一段非空正文均收到 wxSend 2xx 响应
*/
void schedulePushChunks(String toUser, List<String> chunks);
boolean schedulePushChunks(String toUser, List<String> chunks);
}

View File

@@ -258,20 +258,56 @@ public class OpenPhoneForwardService {
private void runForwardAndPush(String toUser, String phone, String bot, String cKey) {
try {
log.info("phone-forward 异步 TG 查询开始 phone={} bot={} toUser={}", phone, bot, toUser);
String reply = doForward(phone, bot, dedupEnabled ? cKey : null);
List<String> chunks = WeComUtf8ChunkUtil.splitUtf8Chunks(reply, WeComUtf8ChunkUtil.WE_COM_TEXT_MAX_UTF8_BYTES);
chunks.removeIf(s -> !StringUtils.hasText(s));
if (chunks.isEmpty()) {
chunks = Collections.singletonList("(无返回内容)");
}
phoneForwardActivePush.schedulePushChunks(toUser, chunks);
boolean pushed = phoneForwardActivePush.schedulePushChunks(toUser, chunks);
if (!pushed) {
log.error(
"phone-forward 结果未能推送到企微 user={} phone={}(可能为 TG/转发错误或服务端返回的正文,请检查 wxSend 与 jarvis.wecom",
toUser, phone);
}
} catch (Exception e) {
log.warn("phone-forward 异步推送异常 phone={} err={}", phone, e.toString());
log.error("phone-forward 异步处理异常 phone={} user={}", phone, toUser, e);
pushForwardFailureNotice(toUser, userVisibleThrowableMessage(e));
} finally {
clearForwardInflight(cKey);
}
}
private void pushForwardFailureNotice(String toUser, String line) {
if (phoneForwardActivePush == null || !StringUtils.hasText(toUser)) {
return;
}
try {
List<String> parts = WeComUtf8ChunkUtil.splitUtf8Chunks(line, WeComUtf8ChunkUtil.WE_COM_TEXT_MAX_UTF8_BYTES);
if (parts.isEmpty()) {
parts = Collections.singletonList("「转发服务」异常,请稍后重试。");
}
boolean ok = phoneForwardActivePush.schedulePushChunks(toUser.trim(), parts);
if (!ok) {
log.error("phone-forward 异常说明未能推送到企微 user={}", toUser);
}
} catch (Exception e2) {
log.warn("phone-forward 异常说明推送过程失败 err={}", e2.toString());
}
}
private static String userVisibleThrowableMessage(Throwable e) {
String m = e.getMessage();
if (!StringUtils.hasText(m)) {
m = e.getClass().getSimpleName();
}
if (m.length() > 500) {
m = m.substring(0, 500) + "";
}
return "「转发服务」异常:" + m + "。请稍后重试。";
}
private String dedupGet(String key) {
if (!dedupEnabled || key == null) {
return null;