调用itchat模块
话不多说上代码
import itchat
from itchat.content import *
import time,os,re
rec_tmp_dir = os.path.join(os.getcwd(), 'tmp/')
rec_msg_dict = {
}
# 好友信息监听
@itchat.msg_register([TEXT, PICTURE, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True)
def handle_friend_msg(msg):
#pprint(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[