WxJava icon indicating copy to clipboard operation
WxJava copied to clipboard

企微第三方加好友回调,创建时间一样被判定为重复消息

Open wayne-wei-q opened this issue 1 year ago • 3 comments

简要描述

在企微第三方回调接口使用消息路由时发现,当加好友回调消息的创建时间一样,但外部联系人不同,企微用户也不同时会被判断为重复消息,导致没有进入到后续的handle,造成该客户的相关业务未能处理。

模块版本情况

  • WxJava 模块名: weixin-java-cp
  • WxJava 版本号: 4.6.0

详细描述

Class: me.chanjar.weixin.cp.tp.message.WxCpTpMessageRouter Mehtod: isMsgDuplicated() `private boolean isMsgDuplicated(WxCpTpXmlMessage wxMessage) { StringBuilder messageId = new StringBuilder(); if (wxMessage.getInfoType() != null) { messageId.append(wxMessage.getInfoType()) .append("-").append(StringUtils.trimToEmpty(wxMessage.getSuiteId())) .append("-").append(wxMessage.getTimeStamp()) .append("-").append(StringUtils.trimToEmpty(wxMessage.getAuthCorpId())) .append("-").append(StringUtils.trimToEmpty(wxMessage.getUserID())) .append("-").append(StringUtils.trimToEmpty(wxMessage.getChangeType())) .append("-").append(StringUtils.trimToEmpty(wxMessage.getServiceCorpId())) .append("-").append(StringUtils.trimToEmpty(wxMessage.getExternalUserID())); }

if (wxMessage.getMsgType() != null) {
  if (wxMessage.getMsgId() != null) {
    messageId.append(wxMessage.getMsgId())
      .append("-").append(wxMessage.getCreateTime())
      .append("-").append(wxMessage.getFromUserName());
  } else {
      messageId.append(wxMessage.getMsgType())
      .append("-").append(wxMessage.getCreateTime())
      .append("-").append(wxMessage.getFromUserName())
      .append("-").append(StringUtils.trimToEmpty(wxMessage.getEvent()))
      .append("-").append(StringUtils.trimToEmpty(wxMessage.getEventKey()));

  }
}

return this.messageDuplicateChecker.isDuplicate(messageId.toString());

}`

image 在加好友回调中,InfoType为空,MsgID为空会进入到如图所示的逻辑中,此处createTime和FromUserName是相同的,而Event必定也是相同的,eventKey为空。所以会判定为重复消息,此处的messageId应加上ExternalUserID和userID作为唯一判定的key。

wayne-wei-q avatar Jun 17 '24 04:06 wayne-wei-q