Python之微信消息防撤回
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'jiangwenwen'
import itchat
from itchat.content import *
import time
import re
import os
msg_information = {}
# 针对表情包的内容
face_bug = None
@itchat.msg_register([TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True, isMpChat=True)
def handle_receive_msg(msg):
global face_bug
# 接收消息的时间
msg_time_rec = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 在好友列表列表中查询发送信息的好友昵称
msg_from = itchat.search_friends(userName=msg['FromUserName'])['NickName']
# 信息发送的时间
msg_time = msg['CreateTime']
# 每条信息的ID
msg_id = msg['MsgId']
# 储存信息的内容
msg_content = None
# 储存分享的连接,比如分享的文章和音乐
msg_share_url = None
# 如果发送的消息是文本或者好友推荐
if msg['Type'] == 'Text' or msg['Type'] == 'Friends':
msg_content = msg['Text']
print(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))
# 如果消息是推荐的名片
elif msg['Type'] == 'Card':
# 内容是推荐人的昵称和性别
msg_content = msg['RecommendInfo']['NickName'] + '的名片'
if msg['RecommendInfo']['Sex'] == 1:
msg_content += '性别为男'
else:
msg_content += '性别为女'
print(msg_content)
# 如果消息为分享的位置信息
elif msg['Type'] == 'Map':
x, y, location = re.search(
"<location x=\"(.*?)\" y=\"(.*?)\".*label=\"(.*?)\".*", msg['OriContent']).group(1, 2, 3)
if location is None:
# 内容为详细地址
msg_content = r'纬度->' + x.__str__() + "经度->" + y.__str__()
else:
msg_content = r"" + location
# 如果消息是分享的音乐或者文章,详细的内容为文章的标题或者分享的名字
elif msg['Type'] == 'Sharing':
msg_content = msg['Text']
msg_share_url = msg['Url']
print(msg_share_url)
face_bug = msg_content
# 将信息存储在字典中,每一个msg_id对应一条消息
msg_information.update(
{
msg_id: {
"msg_from": msg_from, "msg_time": msg_time, "msg_time_rec": msg_time_rec,
"msg_type": msg['Type'],
"msg_content": msg_content, "msg_share_url": msg_share_url
}
}
)
#这个是用于监听是否有friend消息撤回
@itchat.msg_register(NOTE, isFriendChat=True, isGroupChat=True, isMpChat=True)
def information(msg):
# 这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
if '撤回了一条消息' in msg['Content']:
old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)
# 得到消息
old_msg = msg_information.get(old_msg_id)
print(old_msg)
# 如果发送的是表情
if len(old_msg_id)<11:
itchat.send_file(face_bug, toUserName='filehelper')
# 发送撤回的提示给文件助手
else:
msg_body = "【"\
+ old_msg.get('msg_from') + "撤回了】\n"\
+ old_msg.get("msg_type") + "消息:" + "\n"\
+ old_msg.get("msg_time_rec") + "\n"\
+ r"" + old_msg.get("msg_content")
# 如果分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
if old_msg['msg_type'] == "Sharing":
msg_body += "\n就是这个链接>" + old_msg.get('msg_share_url')
# 将撤回消息发送到文件助手
itchat.send_msg(msg_body, toUserName="filehelper")
# 有文件的话也要将文件发送回去
if old_msg["msg_type"] == "Picture"\
or old_msg["msg_type"] == "Recording"\
or old_msg["msg_type"] == "Video"\
or old_msg["msg_type"] == "Attachment":
file = "@fil@%s" % (old_msg['msg_content'])
itchat.send(msg=file, toUserName='filehelper')
os.remove(old_msg['msg_content'])
# 删除字典旧信息
msg_information.pop(old_msg_id)
itchat.auto_login(hotReload=True)
itchat.run()
Python之微信消息防撤回的更多相关文章
- Python实现微信消息防撤回
微信(WeChat)是腾讯公司于2011年1月21日推出的一款社交软件,8年时间微信做到日活10亿,日消息量450亿.在此期间微信也推出了不少的功能如:“摇一摇”.“漂流瓶”.“朋友圈”.“附近的人” ...
- Python_20行代码实现微信消息防撤回(简易版)
学习了一下如何用python实现微信消息的防撤回, 主要思路就是: 时时监控微信,将对方发送的消息缓存下来 如果对方撤回了消息,就将该缓存信息发送给文件传输助手 但其实这功能,基本上毫无意义,看到别人 ...
- PC微信逆向--实现消息防撤回
自从聊天软件消息撤回功能问世后,对于撤回的消息,我们对它一直有种强烈的好奇感."Ta刚撤回了什么?是骂我的话?还是说喜欢我?还是把发给其他人的消息误发给了我?好气呀,都看不到了...&quo ...
- [软件逆向]实战Mac系统下的软件分析+Mac QQ和微信的防撤回
0x00 一点废话 最近因为Mac软件收费的比较多,所以买了几款正版软件,但是有的软件卖的有点贵,买了感觉不值,不买吧,又觉得不方便,用别人的吧,又怕不安全.于是我就买了正版的Hopper Di ...
- python查看微信消息撤回
准备环境 python语言环境 python解释器-pycharm itchat介绍 itchat是一个开源的微信个人号接口,通过itchat可以实现微信(好友或微信群)的信息处理,包括文本.图片.小 ...
- Python发送微信消息
针对此 需要安装itchat第三方模块 采用pip安装就可以了 pip install itchat import itchatimport time#引入时间函数进行测试time_format= ...
- macOS 版微信小助手,支持微信多开、防撤回、远程控制mac、自动回复等等
微信小助手 GitHub大牛提供的微信小助手是一款插件,该插件具备多开.防撤回.免手机认证登录.自动回复.远程控制自己的 macOS.群发等众多功能 GitHub网址:https://github.c ...
- 电脑微信电脑PC 多开/防撤回 补丁
简介 经常使用微信电脑版的用户都会发现一个蛋疼的事情,那就是微信PC版不支持多开,也就是不能同时登陆多个账号,这对于需要在电脑上登陆多个微信账号的朋友来说肯定是极其的不方便.另外有的时候别人撤回了一些 ...
- 记录实践PC端微信防撤回实现过程(基于3.1.0.67版本)
利用OD实现对PC端微信防撤回功能的实现 文章最后有一键补丁工具哦~ 准备工具 1.OD 2.PC微信客户端(3.1.0.67) 过程 1.运行微信客户端,不需要登录 2.运行OD,左上角选择附加进程 ...
随机推荐
- 07-js数据类型
# JavaScript 基本数据类型 typeof函数获取一个变量的类型: ```angularjs* boolean - 如果变量是 Boolean 类型的* number - 如果变量是 Num ...
- 动态规划—triangle
题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...
- php 调用远程url
// ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. // ; http://php.net/a ...
- thinkphp 模板
一. 模板函数 教程https://www.kancloud.cn/manual/thinkphp5/125005 我们往往需要对模板输出变量使用函数,可以使用: {$data.name|md5} ...
- 前端每日实战:25# 视频演示如何用纯 CSS 创作一个慧星拖尾效果的 loader 动画
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/YLRLaM 可交互视频教程 此视频 ...
- windows下如何安装pip
在安装pip前,请确认win系统中已经安装好了python,和easy_install工具 Python完成后 配置环境变量 在环境变量中添加Python目录 (1) 右键点击"计算机&qu ...
- Python---基础-小游戏用户猜数字2
一.使用int()将小数转换成整数,结果是向上取数还是向下取数 int(3,4) print(int(3,4)) ####写一个程序,判断给定年份是否为闰年 - 闰年的定义,能够被4整除的年份就叫闰年 ...
- Python3-unittest测试框架之DDT数据驱动
unittest测试框架之DDT数据驱动 ddt的使用 DDT数据驱动 DDT:Data Driver Test(数据驱动测试) 数据驱动思想:数据和用例进行分离,通过外部数据去生成测试用例 安装 p ...
- 算法-python
选择排序:一个列表被分为无序列表和有序列表,选择排序就是拿无序列表的第一个和后面的每一个相比较,每一趟选择出最小的一个,添加进有序列表. def select_sort(list): for i in ...
- 【2019 Multi-University Training Contest 7】
01:https://www.cnblogs.com/myx12345/p/11653845.html 02: 03: 04: 05: 06:https://www.cnblogs.com/myx12 ...