增加按suiteId分别消息处理

This commit is contained in:
陈秀信 2024-03-29 06:18:55 +08:00
parent 87c34ab6cc
commit ebd85ff094

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,7 +278,7 @@ 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()); messageId.append(wxMessage.getToUserName());
if (wxMessage.getInfoType() != null) { if (wxMessage.getInfoType() != null) {
@ -276,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) {