


In order to ensure the arrival rate of information request messages, the WeChat server will send the same request message (RequestMessage) multiple times if it does not receive the response message (ResponseMessage) in time. All text content including MsgId, etc. are consistent.
This mechanism ensures the success rate of message reply in situations such as poor network conditions. However, sometimes due to server load and the request process itself taking several seconds to complete, multiple repeated messages Instead, it becomes a burden on the server and may even affect business and data.
In response to this situation, the SDK has added a deduplication setting. You only need to add a sentence when using MessageHandler:
messageHandler.OmitRepeatedMessage = true;//启用消息去重功能
/// <summary> /// 最简化的处理流程(不加密) /// </summary> [HttpPost] [ActionName("MiniPost")] public ActionResult MiniPost(string signature, string timestamp, string nonce, string echostr) { if (!CheckSignature.Check(signature, timestamp, nonce, Token)) { return new WeixinResult("参数错误!");//v0.8+ } var messageHandler = new CustomMessageHandler(Request.InputStream, null, 10); messageHandler.OmitRepeatedMessage = true;//启用消息去重功能 messageHandler.Execute();//执行微信处理过程 return new FixWeixinBugWeixinResult(messageHandler); }
The principle of deduplication is through the context of the current user. Determine whether the MsgId of the current request message and the previous request message are consistent. If they are consistent, the downward execution will be terminated.
File: Senparc.Weixin.MessageHandlers.MessageHandler.cs
public virtual void OnExecuting() { if (OmitRepeatedMessage && CurrentMessageContext.RequestMessages.Count > 1) { var lastMessage = CurrentMessageContext.RequestMessages[CurrentMessageContext.RequestMessages.Count - 2]; if (lastMessage.MsgId != 0 && lastMessage.MsgId == RequestMessage.MsgId) { CancelExcute = true;//重复消息,取消执行 } } }
For more WeChat public platform development: Request message deduplication related articles, please pay attention to PHP Chinese net!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
