import itchat
from itchat.content import *
import os
import re
import time
# 文件临时存储页
rec_tmp_dir = os.path.join(os.getcwd(), 'F:\\py\\') # 存储数据的字典
rec_msg_dict = {} # 好友信息监听
@itchat.msg_register([TEXT, PICTURE, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True)
def handle_friend_msg(msg):
msg_id = msg['MsgId']
msg_from_user = msg['User']['NickName']
msg_content = ''
# 收到信息的时间
msg_time_rec = time.strftime("%Y-%m-%d %H:%M%S", time.localtime())
msg_create_time = msg['CreateTime']
msg_type = msg['Type']
if msg['Type'] == 'Text':
msg_content = msg['Content']
elif msg['Type'] == 'Picture'\
or msg['Type'] == 'Recording' \
or msg['Type'] == 'Video' \
or msg['Type'] == 'Attachment':
msg_content = r"" + msg['FileName']
msg['Text'](rec_tmp_dir + msg['FileName'])
rec_msg_dict.update({ msg_id: { 'msg_from_user': msg_from_user, 'msg_time_rec': msg_time_rec, 'msg_create_time': msg_create_time, 'msg_type': msg_type, 'msg_content': msg_content } })
print(msg) # 群聊信息监听
@itchat.msg_register([TEXT, PICTURE, RECORDING, ATTACHMENT, VIDEO], isGroupChat=True)
def information(msg):
msg_id = msg['MsgId']
msg_from_user = msg['ActualNickName']
msg_content = ''
# 收到信息的时间
msg_time_rec = time.strftime("%Y-%m-%d %H:%M%S", time.localtime())
msg_create_time = msg['CreateTime']
msg_type = msg['Type']
if msg['Type'] == 'Text': msg_content = msg['Content']
elif msg['Type'] == 'Picture' \
or msg['Type'] == 'Recording' \
or msg['Type'] == 'Video' \
or msg['Type'] == 'Attachment':
msg_content = r"" + msg['FileName']
msg['Text'](rec_tmp_dir + msg['FileName'])
rec_msg_dict.update({ msg_id: { 'msg_from_user': msg_from_user, 'msg_time_rec': msg_time_rec, 'msg_create_time': msg_create_time, 'msg_type': msg_type, 'msg_content': msg_content } })
print(msg) @itchat.msg_register([NOTE], isFriendChat=True, isGroupChat=True)
def revoke_msg(msg):
if re.search(r"\<\!\[CDATA\[.*撤回了一条消息\]\]\>", msg['Content']) is not None:
old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)
old_msg = rec_msg_dict.get(old_msg_id, {})
# 先发送一条文字信息
itchat.send_msg(str(str(old_msg.get('msg_from_user')) + "撤回了一条信息:"
+ str(old_msg.get('msg_content'))), toUserName="filehelper")
# 判断文msg_content是否存在,不存在说明可能是
if os.path.exists( os.path.join(rec_tmp_dir, str( old_msg.get('msg_content'))) ):
if old_msg.get('msg_type') == 'Picture': itchat.send_image(os.path.join(rec_tmp_dir, old_msg.get('msg_content')),
toUserName="filehelper")
elif old_msg.get('msg_type') == 'Video': itchat.send_video(os.path.join(rec_tmp_dir, old_msg.get('msg_content')),
toUserName="filehelper")
elif old_msg.get('msg_type') == 'Attachment' \
or old_msg.get('msg_type') == 'Recording': itchat.send_file(os.path.join(rec_tmp_dir, old_msg.get('msg_content')),
toUserName="filehelper") if __name__ == '__main__':
itchat.auto_login(hotReload=True)
itchat.run()

python 微信撤回消息的更多相关文章

  1. 一支烟的时间导致他错失女神,Python查看撤回消息,力挽狂澜!

    2011年1月21日 微信(WeChat) 是腾讯公司于2011年1月21日推出的一个为智能终端提供即时通讯服务的免费应用程序,由张小龙所带领的腾讯广州研发中心产品团队打造 .在互联网飞速发展的下.民 ...

  2. Windows下用python来获取微信撤回消息

    转自:https://blog.csdn.net/sunzhibin1/article/details/83348304 娱乐(windows系统) 安装itchat itchat是一个开源的pyth ...

  3. python-----实现微信撤回消息还原

    有时候用微信聊天,好友会撤回一些聊天记录,我们好奇,但又没法看,以下代码就可以满足大家的好奇心. #!/usr/bin/env python # -*- coding: utf-8 -*- # @Ti ...

  4. itchat监听微信撤回消息

    import itchat from itchat.content import * import re msg_infomation = {} # 监听发送消息 @itchat.msg_regist ...

  5. 微信电脑版微信1.1 for Windows更新 可@人/转发撤回消息/可播小视频

    微信电脑版微信1.1 for Windows发布更新了,版本号为1.1.0.18,群聊可@人/可转发撤回消息/可播小视频,功能越来越接近微信手机版了. 本次更新的一些新特点: 群聊中可以@人. 消息可 ...

  6. python实现通过企业微信发送消息

    实现了通过企业微信发送消息,平时用于运维的告警还是不错的,相对于邮件来说,实时性更高,不过就是企业微信比较麻烦,此处不做过多解释. 企业微信api的详细请看:http://work.weixin.qq ...

  7. python微信库 --- itchat

    python实现微信接口——itchat模块 安装 pip install itchat 登录 itchat.auto_login() # 这种方法将会通过微信扫描二维码登录,但是这种登录的方式确实短 ...

  8. 前后端分离djangorestframework—— 接入微信模板消息推送

    微信 什么是微信也不多说,跟前面的支付宝一样的 微信支付 微信支付也有个沙箱环境,沙箱环境官方文档 由文档中那句很显眼的话所得,即使是测试环境也需要真实的商户号,所以这个就没法想支付宝那样用沙箱账号来 ...

  9. zabbix python 微信告警脚本

    测试zabbix的微信告警耗费了大量时间,使用了开源工具(OneOaaS weixin-alert).shell脚本工具(手动执行正常,服务器调用失败),均没有实现相关功能以下是自己优化过的Pytho ...

随机推荐

  1. VUE中v-on:click事件中获取当前dom元素

    在开发中总是忘记, 特意在此记录 关键字:   $event     <div class="bed" v-on:click="updateBed(index,$e ...

  2. SELECT查询结果集INSERT到数据表

    简介 将查询语句查询的结果集作为数据插入到数据表中. 一.通过INSERT SELECT语句形式向表中添加数据 例如,创建一张新表AddressList来存储班级学生的通讯录信息,然后这些信息恰好存在 ...

  3. MySQL 8.0.2: Introducing Window Functions

    July 18, 2017MySQL, SQLDag Wanvik MySQL 8.0.2 introduces SQL window functions, or analytic functions ...

  4. Linux系统之TroubleShooting(启动故障排除)

    尽管Linux系统非常强大,稳定,但是我们在使用过程当中,如果人为操作不当,仍然会影响系统,甚至可能使得系统无法开机,无法运行服务等等各种问题.那么这篇博文就总结一下一些常见的故障排除方法,但是不可能 ...

  5. Linux 补丁生成与使用

    我们在升级Linux 内核的时候,难免会接触到补丁的知识.下面对如何生成补丁和如何打补丁作讲解. 生成补丁: 制作 hello.c 和 hello_new.c 两个文件如如下所示. ➜ diff ls ...

  6. crontab 命令使用

    什么是crontab? crontab命令常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行. ...

  7. 1-100求和 sum(range(101))

    print(sum(range(101))) s = 0for i in range(101): s += iprint(s)  

  8. T4学习- 3、创建运行时模板

    使用 Visual Studio 预处理过的文本模板,可以在运行时在应用程序中生成文本字符串. 执行应用程序的计算机不必具有 Visual Studio. 预处理过的模板有时称为"运行时文本 ...

  9. mac下idea 13 在tomcat 7控制台乱码

    在mac或linux下idea 13(可能其它版本也会出现乱码) tomcat 7在输出到控制台的日志中文乱码,解决方式 加一个environment variable, 在如图绿色位置添加   JA ...

  10. postMessage 消息传递

    点击查看demo 前言 web开发了,除了前台与服务器交换数据,还有可能前台页面间需要进行数据传递,比如窗口间,页面和嵌套的iframe间.这些问题之前都有解决办法,但是现在html5引入的messa ...