资讯专栏INFORMATION COLUMN

Python查看微信好友撤回的消息

王陆宽 / 1334人阅读

摘要:视频演示源代码查看微信撤回消息公众号的皮卡丘作者处理接收到的信息接收消息的时间发信人发信时间信息文本或者好友推荐附件视频图片语音推荐名片的推荐名片,性别男。

公众号:Charles的皮卡丘
作者:Charles

开发工具:
Python版本:3.6.4
相关模块:
itchat模块;
以及一些Python自带的模块。

环境搭建:
安装Python并添加到环境变量,pip安装需要的相关模块即可。

原理简介:
思路比较简单,利用itchat模块登录网页版微信,将自己微信收到的所有消息都缓存下来,当检测到有消息撤回时,将撤回消息的缓存版本通过文件传输助手发送到自己的手机上。
因此,你必须保证脚本24小时运行才可以一直监视别人有没有撤回消息。
具体实现过程详见源代码。

视频演示:
https://mp.weixin.qq.com/s/Ch...

源代码:

# Python查看微信撤回消息
# 公众号: Charles的皮卡丘
# 作者: Charles
import re
import os
import time
import itchat
import platform
from itchat.content import TEXT
from itchat.content import *


msg_info = {}
face_package = None


# 处理接收到的信息
@itchat.msg_register([TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True, isMpChat=True)
def handleRMsg(msg):
    global face_package
    # 接收消息的时间
    msg_time_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" or msg["Type"] == "Friends":
        msg_content = msg["Text"]
        print("[Text/Friends]: %s" % msg_content)
    # 附件/视频/图片/语音
    elif msg["Type"] == "Attachment" or msg["Type"] == "Video" or msg["Type"] == "Picture" or msg["Type"] == "Recording":
        msg_content = msg["FileName"]
        msg["Text"](str(msg_content))
        print("[Attachment/Video/Picture/Recording]: %s" % msg_content)
    # 推荐名片
    elif msg["Type"] == "Card":
        msg_content = msg["RecommendInfo"]["NickName"] + "的推荐名片,"
        if msg["RecommendInfo"]["Sex"] == 1:
            msg_content += "性别男。"
        else:
            msg_content += "性别女。"
        print("[Card]: %s" % msg_content)
    # 位置信息
    elif msg["Type"] == "Map":
        x, y, location = re.search("(.*?)", msg["Content"]).group(1)
        recall_msg = msg_info.get(recall_msg_id)
        print("[Recall]: %s" % recall_msg)
        # 表情包
        if len(recall_msg_id) < 11:
            itchat.send_file(face_package, toUserName="filehelper")
        else:
            msg_prime = "---" + recall_msg.get("msg_from") + "撤回了一条消息---
" 
                        "消息类型:" + recall_msg.get("msg_type") + "
" 
                        "时间:" + recall_msg.get("msg_time_receive") + "
" 
                        r"内容:" + recall_msg.get("msg_content")
            if recall_msg["msg_type"] == "Sharing":
                msg_prime += "
链接:" + recall_msg.get("msg_link")
            itchat.send_msg(msg_prime, toUserName="filehelper")
            if recall_msg["msg_type"] == "Attachment" or recall_msg["msg_type"] == "Video" or recall_msg["msg_type"] == "Picture" or recall_msg["msg_type"] == "Recording":
                file = "@fil@%s" % (recall_msg["msg_content"])
                itchat.send(msg=file, toUserName="filehelper")
                os.remove(recall_msg["msg_content"])
            msg_info.pop(recall_msg_id)


if __name__ == "__main__":
    if platform.platform()[:7] == "Windows":
        itchat.auto_login(enableCmdQR=False, hotReload=True)
    else:
        itchat.auto_login(enableCmdQR=True, hotReload=True)
    itchat.run()

欢迎关注我的个人公众号:Charles的皮卡丘

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/41923.html

相关文章

  • Python微信撤回,基于itchat模块

    摘要:有时候,女神发来一条消息,说约你看电影,她考虑了一下,又撤回了,不约你了而你又想知道她究竟发了什么,该怎么办微信防撤回了解一下。 有时候,女神发来一条消息,说约你看电影,她考虑了一下,又撤回了,不约你了...而你又想知道她究竟发了什么,该怎么办?微信防撤回了解一下。 环境要求 Python3 电脑 安装itchat pip install itchat 使用代码 新建chehui.py...

    xfee 评论0 收藏0
  • Python 骚操作,自动拷贝U盘

    摘要:今天的骚操作,分享的是一个自动拷贝电脑盘内容的程序。当别人的盘插入到你的电脑上时,脚本会自动把盘所有的内容,全部拷贝到你的电脑上。骚源码程序主要是由三个函数组成,。每个操作都会记录到日志中,以便日后查看相应的拷贝信息。 showImg(https://segmentfault.com/img/remote/1460000016794520); 阅读文本大概需要 6 分钟。 Python...

    zgbgx 评论0 收藏0
  • Python清理微信僵尸粉,基于itchat模块

    摘要:按键继续微信,用自己账户给所有好友发送消息,当添加自己为好友时,只有自己能收到此信息,如果没添加自己为好友没有人能收到此信息,笔者此刻日期为,到目前为止微信还没修复。检测到第位好友发送信息速度过快会被微信检测到异常行为。 showImg(https://segmentfault.com/img/bVbqjcJ?w=765&h=742); 原理 通过Pyhton调用itchat模块登录网...

    Yumenokanata 评论0 收藏0
  • Python自制微信机器人:群发消息、自动接收好友

    摘要:所以就想着自己写一个干脆,经过一周漫长的开发主要是时间太零散了,把第一版定制化微信机器人给完成了,第一版里实现了几个功能自动添加好友,并同时根据附加信息打备注。 showImg(https://segmentfault.com/img/remote/1460000018578411?w=1080&h=719); 运营公众号也有半年了,今年5月份开始的,之前一直用一款windows工具来...

    wmui 评论0 收藏0

发表评论

0条评论

王陆宽

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<