1
This commit is contained in:
@@ -76,8 +76,9 @@ public class WeComCallbackController {
|
||||
String toCorp = WeComPlainXmlParser.toUserName(plainXml);
|
||||
String agentId = WeComPlainXmlParser.agentId(plainXml);
|
||||
String msgId = WeComPlainXmlParser.msgId(plainXml);
|
||||
Long wxCreateTime = WeComPlainXmlParser.createTimeUnix(plainXml);
|
||||
|
||||
String reply = callJarvisBridge(from, content, toCorp, agentId, msgId);
|
||||
String reply = callJarvisBridge(from, content, toCorp, agentId, msgId, wxCreateTime);
|
||||
if (StrUtil.isBlank(reply)) {
|
||||
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body("success");
|
||||
}
|
||||
@@ -90,7 +91,7 @@ public class WeComCallbackController {
|
||||
}
|
||||
|
||||
private String callJarvisBridge(String fromUserName, String content, String toUserName,
|
||||
String agentId, String msgId) {
|
||||
String agentId, String msgId, Long wxCreateTime) {
|
||||
if (StrUtil.isBlank(jarvisBridgeUrl) || StrUtil.isBlank(jarvisSharedSecret)) {
|
||||
logger.warn("未配置 jarvis.wecom.bridge-url 或 shared-secret,跳过转发");
|
||||
return null;
|
||||
@@ -101,6 +102,9 @@ public class WeComCallbackController {
|
||||
body.put("toUserName", toUserName);
|
||||
body.put("agentId", agentId);
|
||||
body.put("msgId", msgId);
|
||||
if (wxCreateTime != null) {
|
||||
body.put("wxCreateTime", wxCreateTime);
|
||||
}
|
||||
try {
|
||||
String resp = HttpRequest.post(jarvisBridgeUrl.trim())
|
||||
.header("Content-Type", "application/json;charset=UTF-8")
|
||||
|
||||
@@ -69,4 +69,21 @@ public final class WeComPlainXmlParser {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 企微消息 CreateTime,秒级 Unix 时间戳 */
|
||||
public static Long createTimeUnix(String plainXml) {
|
||||
if (plainXml == null) {
|
||||
return null;
|
||||
}
|
||||
Pattern p = Pattern.compile("<CreateTime>(\\d+)</CreateTime>");
|
||||
Matcher m = p.matcher(plainXml);
|
||||
if (m.find()) {
|
||||
try {
|
||||
return Long.parseLong(m.group(1));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user