导语:
哈喽吖铁汁萌~不知道大家在wei信上突然看到“XXX撤回一条消息”的时候,心里痒不痒?现在就教你如何实现消息防撤回的功能。不限手机型号、手机无需root,只要微信号可以登上网页版就可以了(部分不常用和新申请的账号会登不上网页版)。
环境
Centos7
python2.7
itchat
源码
# coding:utf-8
import itchat
from itchat.content import TEXT
from itchat.content import *
import sys
import time
import re
reload(sys)
sys.setdefaultencoding('utf8')
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'] # 信息发送的时间
msg_id = msg['MsgId'] # 每条信息的id
msg_content = None # 储存信息的内容
msg_share_url = None # 储存分享的链接,比如分享的文章和音乐
print msg['Type']
print msg['MsgId']
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)) # 下载文件
# print 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__