Skip to content

Commit 2e3865f

Browse files
AaronChen2012binarywang
authored andcommitted
🐛 【企业微信】修复重复消息误判的问题
1 parent 371a59d commit 2e3865f

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouter.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,17 @@ public WxCpTpMessageRouterRule rule() {
187187
return new WxCpTpMessageRouterRule(this);
188188
}
189189

190+
190191
/**
191192
* 处理微信消息.
192193
*
194+
* @param suiteId the suiteId
193195
* @param wxMessage the wx message
194196
* @param context the context
195197
* @return the wx cp xml out message
196198
*/
197-
public WxCpXmlOutMessage route(final WxCpTpXmlMessage wxMessage, final Map<String, Object> context) {
198-
if (isMsgDuplicated(wxMessage)) {
199+
public WxCpXmlOutMessage route(final String suiteId, final WxCpTpXmlMessage wxMessage, final Map<String, Object> context) {
200+
if (isMsgDuplicated(suiteId, wxMessage)) {
199201
// 如果是重复消息,那么就不做处理
200202
return null;
201203
}
@@ -254,6 +256,18 @@ public WxCpXmlOutMessage route(final WxCpTpXmlMessage wxMessage, final Map<Strin
254256
return res;
255257
}
256258

259+
260+
/**
261+
* 处理微信消息.
262+
*
263+
* @param wxMessage the wx message
264+
* @param context the context
265+
* @return the wx cp xml out message
266+
*/
267+
public WxCpXmlOutMessage route(final WxCpTpXmlMessage wxMessage, final Map<String, Object> context) {
268+
return this.route(null, wxMessage, new HashMap<>(2));
269+
}
270+
257271
/**
258272
* 处理微信消息.
259273
*
@@ -264,8 +278,9 @@ public WxCpXmlOutMessage route(final WxCpTpXmlMessage wxMessage) {
264278
return this.route(wxMessage, new HashMap<>(2));
265279
}
266280

267-
private boolean isMsgDuplicated(WxCpTpXmlMessage wxMessage) {
281+
private boolean isMsgDuplicated(final String suiteId, WxCpTpXmlMessage wxMessage) {
268282
StringBuilder messageId = new StringBuilder();
283+
messageId.append(wxMessage.getToUserName());
269284
if (wxMessage.getInfoType() != null) {
270285
messageId.append(wxMessage.getInfoType())
271286
.append("-").append(StringUtils.trimToEmpty(wxMessage.getSuiteId()))
@@ -275,6 +290,10 @@ private boolean isMsgDuplicated(WxCpTpXmlMessage wxMessage) {
275290
.append("-").append(StringUtils.trimToEmpty(wxMessage.getChangeType()))
276291
.append("-").append(StringUtils.trimToEmpty(wxMessage.getServiceCorpId()))
277292
.append("-").append(StringUtils.trimToEmpty(wxMessage.getExternalUserID()));
293+
} else {
294+
if (StringUtils.isNotBlank(suiteId)) {
295+
messageId.append(suiteId);
296+
}
278297
}
279298

280299
if (wxMessage.getMsgType() != null) {

0 commit comments

Comments
 (0)