学习了一下如何用python实现微信消息的防撤回,
主要思路就是:
- 时时监控微信,将对方发送的消息缓存下来
- 如果对方撤回了消息,就将该缓存信息发送给文件传输助手
但其实这功能,基本上毫无意义,看到别人错发的消息除了满足一下猎奇心,而且还是短暂的猎奇心,真的没什么卵用,除非你有其他目的。学习这个也基本上是浪费时间。
所以我也只是把最常见的文字类消息实现了一下防撤回,其余的类型基本如法炮制即可。
代码如下:
1 import itchat
2 from itchat.content import TEXT, NOTE
3
4
5 itchat.auto_login(hotReload=True)
6
7 types = None
8 info = None
9 name = None
10
11
12 @itchat.msg_register([TEXT])
13 def receive_info(msg):
14 global types
15 global info
16 global name
17 name = msg['FileName']
18 types = msg["Type"]
19 info = msg["Text"]
20
21
22 @itchat.msg_register(NOTE)
23 def withdraw_info(withdraw_msg):
24 if "撤回了一条消息" in withdraw_msg["Text"]:
25 if types == "Text":
26 itchat.send(msg=withdraw_msg["Text"] +
27 ':' + info, toUserName="filehelper")
28
29
30 itchat.run()