Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

接收小程序媒体检测回调消息时的消息去重判断逻辑有问题 #2705

Closed
fakebody opened this issue Jun 20, 2022 · 2 comments
Closed
Milestone

Comments

@fakebody
Copy link

fakebody commented Jun 20, 2022

简要描述

接收小程序媒体检测回调消息时,进入方法cn.binarywang.wx.miniapp.message.WxMaMessageRouter#isMsgDuplicated判断消息是否重复

private boolean isMsgDuplicated(WxMaMessage wxMessage) {
    StringBuilder messageId = new StringBuilder();
    if (wxMessage.getMsgId() == null) {
      messageId.append(wxMessage.getCreateTime())
        .append("-").append(wxMessage.getFromUser())
        .append("-").append(StringUtils.trimToEmpty(wxMessage.getEvent()));
    } else {
      messageId.append(wxMessage.getMsgId())
        .append("-").append(wxMessage.getCreateTime())
        .append("-").append(wxMessage.getFromUser());
    }
    if (StringUtils.isNotEmpty(wxMessage.getToUser())) {
      messageId.append("-").append(wxMessage.getToUser());
    }
    return this.messageDuplicateChecker.isDuplicate(messageId.toString());
  }

以下是同一个小程序、同一时间发起的2条媒体检测,解密后的回调数据:

{"ToUserName":"xx","FromUserName":"xx","CreateTime":1655747827,"MsgType":"event","Event":"wxa_media_check","isrisky":"0","extra_info_json":"","appid":"xx","trace_id":"db6a6eb16fd1c8afe425b1c76917cc0c","status_code":"0"}
{"ToUserName":"xx","FromUserName":"xx","CreateTime":1655747827,"MsgType":"event","Event":"wxa_media_check","isrisky":"0","extra_info_json":"","appid":"xx","trace_id":"fbef75edb40bd0b95ea0d138ca6d71f8","status_code":"0"}

只有trace_id不同,可见这种情况下根据CreateTime及ToUserName不足以作为唯一条件,导致消息丢失

模块版本情况

  • WxJava 模块名: 4.3.0
@fakebody
Copy link
Author

顺带提一嘴,me.chanjar.weixin.common.api.WxConsts.EventType枚举少了wxa_media_check事件类型

@binarywang
Copy link
Owner

欢迎直接提交PR修复代码,非常期待

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants