python實現檢視微信訊息撤回

2021-08-29 20:42:21 字數 3790 閱讀 7122

娛樂(windows系統)

2.安裝成功之後,進入pip3.exe所在的目錄

安裝itchat:pip3.exe install itchat 下圖我的已經安裝過了(注意:使用3以及以上版本執行)。

3.開啟cmd拖入按回車就好了

建乙個wx.py檔案,以下**匯入

# -*-encoding:utf-8-*-

import os

import re

import shutil

import time

import itchat

from itchat.content import *

# msg_dict = {}

# 檔案儲存臨時目錄

rev_tmp_dir = "/revdir/"

if not os.path.exists(rev_tmp_dir): os.mkdir(rev_tmp_dir)

# 表情有乙個問題 | 接受資訊和接受note的msg_id不一致 巧合解決方案

face_bug = none

# 將接收到的訊息存放在字典中,當接收到新訊息時對字典中超時的訊息進行清理 | 不接受不具有撤回功能的資訊

# [text, picture, map, card, sharing, recording, attachment, video, friends, note]

@itchat.msg_register([text, picture, map, card, sharing, recording, attachment, video])

def handler_receive_msg(msg):

global face_bug

# 獲取的是本地時間戳並格式化本地時間戳 e: 2017-04-21 21:30:08

msg_time_rec = time.strftime("%y-%m-%d %h:%m:%s", time.localtime())

# 訊息id

msg_id = msg['msgid']

# 訊息時間

msg_time = msg['createtime']

# 訊息傳送人暱稱 | 這裡也可以使用remarkname備註 但是自己或者沒有備註的人為none

msg_from = (itchat.search_friends(username=msg['fromusername']))["nickname"]

# 訊息內容

msg_content = none

# 分享的鏈結

msg_share_url = none

if msg['type'] == 'text' \

or msg['type'] == 'friends':

msg_content = msg['text']

elif msg['type'] == 'recording' \

or msg['type'] == 'attachment' \

or msg['type'] == 'video' \

or msg['type'] == 'picture':

msg_content = r"" + msg['filename']

# 儲存檔案

msg['text'](rev_tmp_dir + msg['filename'])

elif msg['type'] == 'card':

msg_content = msg['recommendinfo']['nickname'] + r" 的名片"

elif msg['type'] == 'map':

x, y, location = re.search(

"" + x.__str__() + " 經度->" + y.__str__()

else:

msg_content = r"" + location

elif msg['type'] == 'sharing':

msg_content = msg['text']

msg_share_url = msg['url']

face_bug = msg_content

# 更新字典

msg_dict.update(})

# 收到note通知類訊息,判斷是不是撤回並進行相應操作

@itchat.msg_register([note])

def send_msg_helper(msg):

global face_bug

if re.search(r"\", msg['content']) is not none:

# 獲取訊息的id

old_msg_id = re.search("\(.*?)\", msg['content']).group(1)

old_msg = msg_dict.get(old_msg_id, {})

if len(old_msg_id) < 11:

itchat.send_file(rev_tmp_dir + face_bug, tousername='filehelper')

os.remove(rev_tmp_dir + face_bug)

else:

msg_body = "愛你蕾蕾 ⇣" + "\n" \

+ old_msg.get('msg_from') + " 撤回了 " + old_msg.get("msg_type") + " 訊息" + "\n" \

+ old_msg.get('msg_time_rec') + "\n" \

+ "內容 ⇣" + "\n" \

+ r"" + old_msg.get('msg_content')

# 如果是分享存在鏈結

if old_msg['msg_type'] == "sharing": msg_body += "\n就是這個鏈結➣ " + old_msg.get('msg_share_url')

# 將撤回訊息傳送到檔案助手

itchat.send(msg_body, tousername='filehelper')

# 有檔案的話也要將檔案傳送回去

if old_msg["msg_type"] == "picture" \

or old_msg["msg_type"] == "recording" \

or old_msg["msg_type"] == "video" \

or old_msg["msg_type"] == "attachment":

file = '@fil@%s' % (rev_tmp_dir + old_msg['msg_content'])

itchat.send(msg=file, tousername='filehelper')

os.remove(rev_tmp_dir + old_msg['msg_content'])

# 刪除字典舊訊息

msg_dict.pop(old_msg_id)

if __name__ == '__main__':

itchat.auto_login(hotreload=true,enablecmdqr=1)

itchat.run()

開啟cmd,將檔案拖入即

python使用wxpy輕鬆實現微信防撤回的方法

最近比較閒就隨便瞎看,看到了微信防撤回就順便跟著學著實現一下 使用的是wxpy,安裝方法pip install wxpy 我使用的是python2.7 這樣實現起來比較快,反正也只是練手 首現看了兩個別人實現的 然後看了看wxpy的文件 萌新,順便鍛鍊下看文件 我實現的 import wxpy im...

用Python實現微信定時傳送訊息

注意 該作者部落格已遷移至 所需模組 可用pip安裝 apscheduler 定時任務框架 官方文件 定時傳送群訊息 import itchat from apscheduler.schedulers.blocking import blockingscheduler defsend news 更新...

uni app實現微信推送訊息

2.建立移動應用 params,string signature 引數 是否必須 說明grant type 是獲取access token直接填寫client credential 是secret 是https請求方式 get 引數 是否必須 說明access token 是呼叫介面憑證 next ...