python 微信撤回消息
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 微信撤回消息的更多相关文章
- 一支烟的时间导致他错失女神,Python查看撤回消息,力挽狂澜!
2011年1月21日 微信(WeChat) 是腾讯公司于2011年1月21日推出的一个为智能终端提供即时通讯服务的免费应用程序,由张小龙所带领的腾讯广州研发中心产品团队打造 .在互联网飞速发展的下.民 ...
- Windows下用python来获取微信撤回消息
转自:https://blog.csdn.net/sunzhibin1/article/details/83348304 娱乐(windows系统) 安装itchat itchat是一个开源的pyth ...
- python-----实现微信撤回消息还原
有时候用微信聊天,好友会撤回一些聊天记录,我们好奇,但又没法看,以下代码就可以满足大家的好奇心. #!/usr/bin/env python # -*- coding: utf-8 -*- # @Ti ...
- itchat监听微信撤回消息
import itchat from itchat.content import * import re msg_infomation = {} # 监听发送消息 @itchat.msg_regist ...
- 微信电脑版微信1.1 for Windows更新 可@人/转发撤回消息/可播小视频
微信电脑版微信1.1 for Windows发布更新了,版本号为1.1.0.18,群聊可@人/可转发撤回消息/可播小视频,功能越来越接近微信手机版了. 本次更新的一些新特点: 群聊中可以@人. 消息可 ...
- python实现通过企业微信发送消息
实现了通过企业微信发送消息,平时用于运维的告警还是不错的,相对于邮件来说,实时性更高,不过就是企业微信比较麻烦,此处不做过多解释. 企业微信api的详细请看:http://work.weixin.qq ...
- python微信库 --- itchat
python实现微信接口——itchat模块 安装 pip install itchat 登录 itchat.auto_login() # 这种方法将会通过微信扫描二维码登录,但是这种登录的方式确实短 ...
- 前后端分离djangorestframework—— 接入微信模板消息推送
微信 什么是微信也不多说,跟前面的支付宝一样的 微信支付 微信支付也有个沙箱环境,沙箱环境官方文档 由文档中那句很显眼的话所得,即使是测试环境也需要真实的商户号,所以这个就没法想支付宝那样用沙箱账号来 ...
- zabbix python 微信告警脚本
测试zabbix的微信告警耗费了大量时间,使用了开源工具(OneOaaS weixin-alert).shell脚本工具(手动执行正常,服务器调用失败),均没有实现相关功能以下是自己优化过的Pytho ...
随机推荐
- 俩表之间的添加Sql
insert into 表3(字段1,字段2) select 表1.UserName,表2.GroupName from 表1,表2 where ...
- MySQL 8.0.2: Introducing Window Functions
July 18, 2017MySQL, SQLDag Wanvik MySQL 8.0.2 introduces SQL window functions, or analytic functions ...
- apache 允许 访问软链接 ( Apache won't follow symlinks (403 Forbidden) )
当我们在 apache 中 进行访问 www 文件夹之外的目录的时候,我们可以使用软链接的方式来进行协助访问. 我在 html 文件夹 下面创建 了 如下软链接 link: [root@dhcp-- ...
- PXE 和 计算机网络启动
1. 什么是PXE PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网 ...
- 【转】Java学习---快速掌握RPC原理及实现
[原文]https://www.toutiao.com/i6592365493435236872/ RPC概述 RPC(Remote Procedure Call)即远程过程调用,也就是说两台服务器 ...
- 乘风破浪:LeetCode真题_028_Implement strStr()
乘风破浪:LeetCode真题_028_Implement strStr() 一.前言 这次是字符串匹配问题,找到最开始匹配的位置,并返回. 二.Implement strStr() 2.1 ...
- Docker容器学习与分享08
Docker容器网络 Docker除了默认创建的三种网络外,还可以自定义网络. 首先创建一个bridge类型的网络,使用docker network create命令. [root@promote ~ ...
- ArcGIS Earth1.9最新版安装和使用教程
1.下载ArcGIS Earth 官网下载地址:https://www.esri.com/en-us/arcgis/products/arcgis-earth 在这个网页的最下面填上信息,就可以下载了 ...
- 浅析Java虚拟机结构与机制[转]
本文旨在给所有希望了解JVM(Java Virtual Machine)的同学一个概念性的入门,主要介绍了JVM的组成部分以及它们内部工作的机制和原理.当然本文只是一个简单的入门,不会涉及过多繁杂的参 ...
- react native环境搭建(含错误处理)
1. Python 2 注意,不要选择3.0及以上的,还不成熟 安装过程中一直 next就可以了,但是注意下图,勾选添加到系统环境变量 安装完之后cmd输入 python 查看是否安装成功. 补充 ...