Micro-Letter (WeChat) is Tencent on January 21, 2011 launched a social networking software, micro-channel 8-year period do Nikkatsu 1 billion, Reuters amount of 45 billion. In the meantime micro letter also launched a number of functions such as: "Shake," "drift bottles", "circle of friends", "near" and "public platform", "applet" and so on, we covered every aspect of life, micro-channel is slowly practicing with their slogan: micro-channel is a way of life
I. Background
Update iterations inevitably accompanied by the introduction of products and off-line functions, and today we want to say is that micro-channel launched in 2014, a small new feature: the withdrawal of a message, use this function were refreshing, refreshing but is administered by it may be scratching your head, teeth want to know you in the end withdrew what, this is called curiosity killed the cat (curiosity kills the cat), today we have to use Python for anti-micro-channel message withdraw meet what we curiosity!
Second, the functional design
We hope that when there is a friend or someone in the group to withdraw the message, the original message can first time, sender information forwarded to the Assistant file (of course you can also send the message back to him, haha), so help us to see.
For everyone to demonstrate what functions implemented.
Third, the function realization
1. The principle micro-channel message withdrawal
Let's take a look at the principles of micro-channel withdraw message:
In fact, micro-channel withdraw messages principle is the operator clicks the withdrawal time, the client will automatically send a system message: "xxx withdrew message", then the other party app end after receiving the message parsing, replace the original message, change a display style to
Demo it for you 正常消息
and 撤回消息
the content in the end what is the difference:
a normal message: Content='你好骚啊
everyone look at
sgId='8784390488772995470'
revocation message: Content is the content of a string of xml format
we put it in the following format look
<revokemsg>
<session>xxx</session>
<oldmsgid>1090336364</oldmsgid>
<msgid>8784390488772995470</msgid>
<replacemsg><![CDATA["猪哥" 撤回了一条消息]]></replacemsg>
</revokemsg></sysmsg>
一号学习群已满 二号学习基地号 906407826 海量学习资料免费领取
The withdrawal of the above analysis Content field we find <msgid>8784390488772995470</msgid>
id id to send a message to us before is the same, but <replacemsg>
the label also confirms our conjecture is indeed replace the original message with a new message.
2. Locate the message is withdrawn
The grip 正常消息
and 撤回消息
the content of our discovery rules: the withdrawal of that message before the message will include the withdrawal of msgid
that before we just find that message on it, and wxpy
module default for us cache the most recent 200 messages, so As long as we traverse these historical messages and then compare msgid
to find that message is withdrawn it!
If you micro-channel messages too frequently, 2 minutes more than 200 the number of messages, you can max_history
set bigger.
3. forwarding messages to be withdrawn
Also get to know the principles, to be withdrawn also find news, and he sent the last step of forwarding the message, and if you played before wxpy
will certainly be it, as long as the line of code you can forward the message:
msg.forward(bot.file_helper)
4. Code
Principles and process finished, the code is posted for everyone to see, the comment is quite detailed, I do not know if you can ask in the study group.
IV Summary
Micro-channel anti-recall feature simple message, but the practicality is very good, the only drawback of the program is the ease of use is poor, it simply is we do not have to deploy the server project, each had to turn on the computer and then run have been open to use, consider the project later deployed on a cloud server or packaged into apk, so it is very convenient to use, but also the apk to a friend, let friends to experience this feature!