🐛 【企业微信】修复重复消息误判的问题

This commit is contained in:
Aaron 2024-03-29 11:23:55 +00:00 committed by Binary Wang
parent 371a59d786
commit 2e3865fd21

View File

@ -187,15 +187,17 @@ public class WxCpTpMessageRouter {
return new WxCpTpMessageRouterRule(this); return new WxCpTpMessageRouterRule(this);
} }
/** /**
* 处理微信消息. * 处理微信消息.
* *
* @param suiteId the suiteId
* @param wxMessage the wx message * @param wxMessage the wx message
* @param context the context * @param context the context
* @return the wx cp xml out message * @return the wx cp xml out message
*/ */
public WxCpXmlOutMessage route(final WxCpTpXmlMessage wxMessage, final Map<String, Object> context) { public WxCpXmlOutMessage route(final String suiteId, final WxCpTpXmlMessage wxMessage, final Map<String, Object> context) {
if (isMsgDuplicated(wxMessage)) { if (isMsgDuplicated(suiteId, wxMessage)) {
// 如果是重复消息那么就不做处理 // 如果是重复消息那么就不做处理
return null; return null;
} }
@ -254,6 +256,18 @@ public class WxCpTpMessageRouter {
return res; return res;
} }
/**
* 处理微信消息.
*
* @param wxMessage the wx message
* @param context the context
* @return the wx cp xml out message
*/
public WxCpXmlOutMessage route(final WxCpTpXmlMessage wxMessage, final Map<String, Object> context) {
return this.route(null, wxMessage, new HashMap<>(2));
}
/** /**
* 处理微信消息. * 处理微信消息.
* *
@ -264,8 +278,9 @@ public class WxCpTpMessageRouter {
return this.route(wxMessage, new HashMap<>(2)); return this.route(wxMessage, new HashMap<>(2));
} }
private boolean isMsgDuplicated(WxCpTpXmlMessage wxMessage) { private boolean isMsgDuplicated(final String suiteId, WxCpTpXmlMessage wxMessage) {
StringBuilder messageId = new StringBuilder(); StringBuilder messageId = new StringBuilder();
messageId.append(wxMessage.getToUserName());
if (wxMessage.getInfoType() != null) { if (wxMessage.getInfoType() != null) {
messageId.append(wxMessage.getInfoType()) messageId.append(wxMessage.getInfoType())
.append("-").append(StringUtils.trimToEmpty(wxMessage.getSuiteId())) .append("-").append(StringUtils.trimToEmpty(wxMessage.getSuiteId()))
@ -275,6 +290,10 @@ public class WxCpTpMessageRouter {
.append("-").append(StringUtils.trimToEmpty(wxMessage.getChangeType())) .append("-").append(StringUtils.trimToEmpty(wxMessage.getChangeType()))
.append("-").append(StringUtils.trimToEmpty(wxMessage.getServiceCorpId())) .append("-").append(StringUtils.trimToEmpty(wxMessage.getServiceCorpId()))
.append("-").append(StringUtils.trimToEmpty(wxMessage.getExternalUserID())); .append("-").append(StringUtils.trimToEmpty(wxMessage.getExternalUserID()));
} else {
if (StringUtils.isNotBlank(suiteId)) {
messageId.append(suiteId);
}
} }
if (wxMessage.getMsgType() != null) { if (wxMessage.getMsgType() != null) {