1. 程式人生 > 實用技巧 >Python_20行程式碼實現微信訊息防撤回(簡易版)

Python_20行程式碼實現微信訊息防撤回(簡易版)

學習了一下如何用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()