转自:https://blog.csdn.net/sunzhibin1/article/details/83348304

娱乐(windows系统)

安装itchat

itchat是一个开源的python微信库,支持发送消息、图片、视频、地图、名片、文件等,还可以实现自动回复等多种功能。
看到的一个文档还不错 https://segmentfault.com/a/1190000009420701

1.安装python3.6

2.安装成功之后,进入pip3.exe所在的目录

一般在安装目录的script目录下:C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts

安装itchat:pip3.exe install itchat 下图我的已经安装过了(注意:使用3以及以上版本执行)。

代码

新建一个wx.py,编辑以下内容

  1. # -*-encoding:utf--*-
  2. import os
  3. import re
  4. import shutil
  5. import time
  6. import itchat
  7. from itchat.content import *
  8.  
  9. # 说明:可以撤回的有文本文字、语音、视频、图片、位置、名片、分享、附件
  10.  
  11. # {msg_id:(msg_from,msg_to,msg_time,msg_time_rec,msg_type,msg_content,msg_share_url)}
  12. msg_dict = {}
  13.  
  14. # 文件存储临时目录
  15. rev_tmp_dir = "/RevDir/"
  16. if not os.path.exists(rev_tmp_dir): os.mkdir(rev_tmp_dir)
  17.  
  18. # 表情有一个问题 | 接受信息和接受note的msg_id不一致 巧合解决方案
  19. face_bug = None
  20.  
  21. # 将接收到的消息存放在字典中,当接收到新消息时对字典中超时的消息进行清理 | 不接受不具有撤回功能的信息
  22. # [TEXT, PICTURE, MAP, CARD, SHARING, RECORDING, ATTACHMENT, VIDEO, FRIENDS, NOTE]
  23. @itchat.msg_register([TEXT, PICTURE, MAP, CARD, SHARING, RECORDING, ATTACHMENT, VIDEO])
  24. def handler_receive_msg(msg):
  25. global face_bug
  26. # 获取的是本地时间戳并格式化本地时间戳 e: -- ::
  27. msg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  28. # 消息ID
  29. msg_id = msg['MsgId']
  30. # 消息时间
  31. msg_time = msg['CreateTime']
  32. # 消息发送人昵称 | 这里也可以使用RemarkName备注 但是自己或者没有备注的人为None
  33. msg_from = (itchat.search_friends(userName=msg['FromUserName']))["NickName"]
  34. # 消息内容
  35. msg_content = None
  36. # 分享的链接
  37. msg_share_url = None
  38. if msg['Type'] == 'Text' \
  39. or msg['Type'] == 'Friends':
  40. msg_content = msg['Text']
  41. elif msg['Type'] == 'Recording' \
  42. or msg['Type'] == 'Attachment' \
  43. or msg['Type'] == 'Video' \
  44. or msg['Type'] == 'Picture':
  45. msg_content = r"" + msg['FileName']
  46. # 保存文件
  47. msg['Text'](rev_tmp_dir + msg['FileName'])
  48. elif msg['Type'] == 'Card':
  49. msg_content = msg['RecommendInfo']['NickName'] + r" 的名片"
  50. elif msg['Type'] == 'Map':
  51. x, y, location = re.search(
  52. "<location x=\"(.*?)\" y=\"(.*?)\".*label=\"(.*?)\".*", msg['OriContent']).group(, , )
  53. if location is None:
  54. msg_content = r"纬度->" + x.__str__() + " 经度->" + y.__str__()
  55. else:
  56. msg_content = r"" + location
  57. elif msg['Type'] == 'Sharing':
  58. msg_content = msg['Text']
  59. msg_share_url = msg['Url']
  60. face_bug = msg_content
  61. # 更新字典
  62. msg_dict.update(
  63. {
  64. msg_id: {
  65. "msg_from": msg_from, "msg_time": msg_time, "msg_time_rec": msg_time_rec,
  66. "msg_type": msg["Type"],
  67. "msg_content": msg_content, "msg_share_url": msg_share_url
  68. }
  69. }
  70. )
  71.  
  72. # 收到note通知类消息,判断是不是撤回并进行相应操作
  73. @itchat.msg_register([NOTE])
  74. def send_msg_helper(msg):
  75. global face_bug
  76. if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) is not None:
  77. # 获取消息的id
  78. old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group()
  79. old_msg = msg_dict.get(old_msg_id, {})
  80. if len(old_msg_id) < :
  81. itchat.send_file(rev_tmp_dir + face_bug, toUserName='filehelper')
  82. os.remove(rev_tmp_dir + face_bug)
  83. else:
  84. msg_body = "告诉你一个秘密: ⇣" + "\n" \
  85. + old_msg.get('msg_from') + " 撤回了 " + old_msg.get("msg_type") + " 消息" + "\n" \
  86. + old_msg.get('msg_time_rec') + "\n" \
  87. + "内容 ⇣" + "\n" \
  88. + r"" + old_msg.get('msg_content')
  89. # 如果是分享存在链接
  90. if old_msg['msg_type'] == "Sharing": msg_body += "\n就是这个链接➣ " + old_msg.get('msg_share_url')
  91.  
  92. # 将撤回消息发送到文件助手
  93. itchat.send(msg_body, toUserName='filehelper')
  94. # 有文件的话也要将文件发送回去
  95. if old_msg["msg_type"] == "Picture" \
  96. or old_msg["msg_type"] == "Recording" \
  97. or old_msg["msg_type"] == "Video" \
  98. or old_msg["msg_type"] == "Attachment":
  99. file = '@fil@%s' % (rev_tmp_dir + old_msg['msg_content'])
  100. itchat.send(msg=file, toUserName='filehelper')
  101. os.remove(rev_tmp_dir + old_msg['msg_content'])
  102. # 删除字典旧消息
  103. msg_dict.pop(old_msg_id)
  104.  
  105. if __name__ == '__main__':
  106. itchat.auto_login(hotReload=True,enableCmdQR=)
  107. itchat.run()

执行

扫码登录

你就可以在文件传输助手中查看到撤回的微信了

Windows下用python来获取微信撤回消息的更多相关文章

  1. Windows下使用python库 curses遇到错误消息的解决方案

    在Windows系统下执行python应用时,有时会遇到错误信息: ModuleNotFoundError: No module named '_curses'. 然而查看Windows系统里pyth ...

  2. 【转】linux和windows下安装python集成开发环境及其python包

    本系列分为两篇: 1.[转]windows和linux中搭建python集成开发环境IDE 2.[转]linux和windows下安装python集成开发环境及其python包 3.windows和l ...

  3. windows下安装python模块

    如何在windows下安装python模块 1. 官网下载安装包,比如(pip : https://pypi.python.org/pypi/pip#downloads) pip-9.0.1.tar. ...

  4. windows下安装python和依赖包的利器——Anaconda

    在windows下安装python和很多依赖包,安装起来略为痛苦,可以使用python的大整合包——Anaconda Anaconda下载地址: http://continuum.io/downloa ...

  5. 详细介绍windows下使用python pylot进行网站压力测试

    windows下使用python进行网站压力测试,有两个必不可少的程序需要安装,一个是python,另一个是pylot.python是一个安装软件,用来运行python程序,而pylot则是pytho ...

  6. windows下创建Python虚拟环境

    windows下创建Python虚拟环境 说明 由于Python的版本众多,还有Python2和Python3的争论,因此有些软件包或第三方库就容易出现版本不兼容的问题. 通过 virtualenv ...

  7. Windows下的Python安装与环境变量的配置

    Windows下的Python安装与环境变量的配置 第一步:python下载: Python安装包下载地址:http://www.python.org/ 第二步:python安装: 双击下载包,进入P ...

  8. Windows下安装Python虚拟环境

    Windows下安装Python虚拟环境 虚拟环境安装 需求概要 "虚拟环境"是从电脑独立开辟出来的环境.就好比我们生活中的橱柜中,会把酱油放在一个瓶子里,把醋放在另外一个瓶子里, ...

  9. Windows下安装python的scipy等科学计算包(转)

    如果要使用python进行科学计算.数据分析等,一定要安装scipy.seaborn.numpy等等包. 但Windows下安装python的第三方库经常会出现问题.此前,已介绍过Windows下如何 ...

随机推荐

  1. 小tip: transition与visibility

    一.transition与visibility 这里的transition指的就是CSS3中的那个过渡动画属性transition. 如果我们仔细查看其支持的CSS属性值,会发现竟然有一个visibi ...

  2. iTextSharpH

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. awt多线程聊天

    public class ChatServer { boolean started = false; ServerSocket serverSocket = null; public void sta ...

  4. PE、PB、PEG三大估值法的正确使用方法!

    目前市面上的估值方法有很多,比如PE估值法.PB估值法.PEG估值法,但是我相信,真正会用的人并不多,比如说目前动态市盈率121倍的比亚迪真的高估吗?比如目前市净率为0.63倍的众泰汽车真的是破净股吗 ...

  5. 【转】前端框架天下三分:Angular React 和 Vue的比较

    前端框架天下三分:Angular React 和 Vue的比较 原文链接:http://blog.csdn.net/haoshidai/article/details/52346865 前端这几年的技 ...

  6. c语言实现wc功能

    本随笔对网站http://blog.chinaunix.net/uid-22566367-id-381958.html有所借鉴 #include <stdio.h> #define BEG ...

  7. office 2016密钥

    Office 2016 Pro Plus Retail 版激活密钥:[Key]:3XJTG-YNBMY-TBH9M-CWB2Y-YWRHH[Key]:6TCQ3-NBBJ2-RTJCM-HFRKV-G ...

  8. android从IIS/asp.net下载apk文件

    解决步骤: 1.web.config中 <configuration>  <configSections> ...    <section name="rewr ...

  9. File 文件

    1 File 概述 文件:file目录:directory路径:path File类静态成员变量: pathSeparator:与系统有关的路径分隔符,为了方便,它被表示为一个字符串separator ...

  10. pwn学习日记Day4 基础知识积累

    知识杂项 *:字符串重复 空指令NOP:\x90 cmp:是比较指令,cmp的功能相当于减法指令.它不保存结果,只是影响相应的标志位. xor:将两个操作数进行异或运算,并将结果存放到操作数1中. s ...