资讯专栏INFORMATION COLUMN

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

王陆宽 / 1516人阅读

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

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

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

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

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

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

源代码:

</>复制代码

  1. # Python查看微信撤回消息
  2. # 公众号: Charles的皮卡丘
  3. # 作者: Charles
  4. import re
  5. import os
  6. import time
  7. import itchat
  8. import platform
  9. from itchat.content import TEXT
  10. from itchat.content import *
  11. msg_info = {}
  12. face_package = None
  13. # 处理接收到的信息
  14. @itchat.msg_register([TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True, isMpChat=True)
  15. def handleRMsg(msg):
  16. global face_package
  17. # 接收消息的时间
  18. msg_time_receive = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  19. # 发信人
  20. try:
  21. msg_from = itchat.search_friends(userName=msg["FromUserName"])["NickName"]
  22. except:
  23. msg_from = "WeChat Official Accounts"
  24. # 发信时间
  25. msg_time_send = msg["CreateTime"]
  26. # 信息ID
  27. msg_id = msg["MsgId"]
  28. msg_content = None
  29. msg_link = None
  30. # 文本或者好友推荐
  31. if msg["Type"] == "Text" or msg["Type"] == "Friends":
  32. msg_content = msg["Text"]
  33. print("[Text/Friends]: %s" % msg_content)
  34. # 附件/视频/图片/语音
  35. elif msg["Type"] == "Attachment" or msg["Type"] == "Video" or msg["Type"] == "Picture" or msg["Type"] == "Recording":
  36. msg_content = msg["FileName"]
  37. msg["Text"](str(msg_content))
  38. print("[Attachment/Video/Picture/Recording]: %s" % msg_content)
  39. # 推荐名片
  40. elif msg["Type"] == "Card":
  41. msg_content = msg["RecommendInfo"]["NickName"] + "的推荐名片,"
  42. if msg["RecommendInfo"]["Sex"] == 1:
  43. msg_content += "性别男。"
  44. else:
  45. msg_content += "性别女。"
  46. print("[Card]: %s" % msg_content)
  47. # 位置信息
  48. elif msg["Type"] == "Map":
  49. x, y, location = re.search("(.*?)", msg["Content"]).group(1)
  50. recall_msg = msg_info.get(recall_msg_id)
  51. print("[Recall]: %s" % recall_msg)
  52. # 表情包
  53. if len(recall_msg_id) < 11:
  54. itchat.send_file(face_package, toUserName="filehelper")
  55. else:
  56. msg_prime = "---" + recall_msg.get("msg_from") + "撤回了一条消息---
  57. "
  58. "消息类型:" + recall_msg.get("msg_type") + "
  59. "
  60. "时间:" + recall_msg.get("msg_time_receive") + "
  61. "
  62. r"内容:" + recall_msg.get("msg_content")
  63. if recall_msg["msg_type"] == "Sharing":
  64. msg_prime += "
  65. 链接:" + recall_msg.get("msg_link")
  66. itchat.send_msg(msg_prime, toUserName="filehelper")
  67. if recall_msg["msg_type"] == "Attachment" or recall_msg["msg_type"] == "Video" or recall_msg["msg_type"] == "Picture" or recall_msg["msg_type"] == "Recording":
  68. file = "@fil@%s" % (recall_msg["msg_content"])
  69. itchat.send(msg=file, toUserName="filehelper")
  70. os.remove(recall_msg["msg_content"])
  71. msg_info.pop(recall_msg_id)
  72. if __name__ == "__main__":
  73. if platform.platform()[:7] == "Windows":
  74. itchat.auto_login(enableCmdQR=False, hotReload=True)
  75. else:
  76. itchat.auto_login(enableCmdQR=True, hotReload=True)
  77. 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元查看
<