微信作为我国最受欢迎的社交软件之一,其消息撤回功能在方便用户的同时,也带来了一些不便。比如,有时候我们可能会错过一些重要信息,因为对方已经将其撤回。那么,有没有办法能够查看微信撤回的消息呢?答案是肯定...
微信作为我国最受欢迎的社交软件之一,其消息撤回功能在方便用户的同时,也带来了一些不便。比如,有时候我们可能会错过一些重要信息,因为对方已经将其撤回。那么,有没有办法能够查看微信撤回的消息呢?答案是肯定的,Python可以帮助我们轻松追踪微信撤回的消息,不再错过重要信息。
itchat是一个开源的Python微信库,支持发送消息、图片、视频、地图、名片、文件等,还可以实现自动回复等多种功能。通过itchat库,我们可以实现对微信消息的监控,包括查看撤回的消息。
首先,我们需要安装itchat库。在命令行中执行以下命令:
pip install itchatimport itchat
from itchat.content import TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO@itchat.msgregister([TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True, isMpChat=True)
def handleRMsg(msg): global facepackage # 接收消息的时间 msgtime_receive = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # 发信人 try: msg_from = itchat.search_friends(userName=msg['FromUserName'])['NickName'] except: msg_from = 'WeChat Official Accounts' # 发信时间 msg_time_send = msg['CreateTime'] # 信息ID msg_id = msg['MsgId'] msg_content = None msg_link = None # 文本或者好友推荐 if msg['Type'] == TEXT: msg_content = msg['Text'] elif msg['Type'] == PICTURE: msg_content = msg['PicUrl'] elif msg['Type'] == VIDEO: msg_content = msg['VideoUrl'] elif msg['Type'] == RECORDING: msg_content = msg['FileName'] elif msg['Type'] == SHARING: msg_content = msg['Url'] elif msg['Type'] == MAP: msg_content = msg['Location'] elif msg['Type'] == ATTACHMENT: msg_content = msg['FileName'] elif msg['Type'] == CARD: msg_content = msg['Title'] elif msg['Type'] == FRIENDS: msg_content = msg['Text'] elif msg['Type'] == RECORDING: msg_content = msg['FileName'] elif msg['Type'] == ATTACHMENT: msg_content = msg['FileName'] elif msg['Type'] == VIDEO: msg_content = msg['VideoUrl'] # 存储消息 msg_dict = {'msg_from': msg_from, 'msg_time_send': msg_time_send, 'msg_id': msg_id, 'msg_content': msg_content, 'msg_link': msg_link} msg_dict['msg_time_receive'] = msgtime_receive msginfo.append(msg_dict) # 清理超时消息 for m in msginfo[:]: if m['msg_time_receive'] < (time.time() - 3600): msginfo.remove(m)运行以上代码,程序会自动登录微信,并监控消息。当检测到撤回的消息时,程序会将撤回消息的内容存储在msginfo列表中。
WechatPCAPI是一个微信PC版的API接口,通过调用该接口,我们可以实现对微信消息的监控,包括查看撤回的消息。
pip install WechatPCAPIfrom WechatPCAPI import WechatPCwechat = WechatPC()
wechat.login()
for message in wechat.get_messages(): if message['msg_type'] == '撤回': print(message['text'])运行以上代码,程序会自动登录微信,并监控消息。当检测到撤回的消息时,程序会打印出撤回消息的内容。
通过以上两种方法,我们可以轻松地追踪微信撤回的消息,不再错过重要信息。希望本文能对您有所帮助!