itchat

"FromUserName": "",
"ToUserName": "",
"Content": "",
"StatusNotifyUserName": "",
"ImgWidth": 0,
"PlayLength": 0,
"RecommendInfo": {},
"StatusNotifyCode": 0,
"NewMsgId": "",
"Status": 0,
"VoiceLength": 0,
"ForwardFlag": 0,
"AppMsgType": 0,
"Ticket": "",
"AppInfo": {},
"Url": "",
"ImgStatus": 0,
"MsgType": 0,
"ImgHeight": 0,
"MediaId": "",
"MsgId": "",
"FileName": "",
"HasProductId": 0,
"FileSize": "",
"CreateTime": 0,
"SubMsgType": 0

send_msg

语法:send_msg(msg = "Text", toUserName = "XXX")
参数:msg是要发送的文本,toUserName是发送对象, 如果留空, 将发送给自己,返回值为True或者False

send_file

语法:send_file(fileDir, toUserName=None)
参数:fileDir是文件路径,返回值为True或者False

send_image

语法:send_image(fileDir, toUserName=None)
参数:fileDir是文件路径,返回值为True或者False

send_video

语法:send_video(fileDir, toUserName=None) 
参数:fileDir是文件路径,返回值为True或者False

回复消息

1
2
3
4
5
6
import itchat
from itchat.content import TEXT

@itchat.msg_register(TEXT) #这里的TEXT表示如果有人发送文本消息,那么就会调用下面的方法
def text_reply(msg):
itchat.send_msg('已经收到了文本消息,消息内容为%s'%msg['Text'],toUserName=msg['FromUserName'])

带对象参数注册, 对应消息对象将调用该方法,其中isFriendChat表示好友之间,isGroupChat表示群聊,isMapChat表示公众号

对于群消息中添加了三个键:
isAt 判断是否 @ 本号
ActualNickName : 实际 NickName(昵称)
Content : 实际 Content

1
2
3
def text_reply(msg):
if(msg.isAt):
itchat.send_msg('已经收到来自{0}@我的消息,内容为:{1}'.format(msg['ActualNickName'],msg['Test']),toUserName = msg['FromUserName'])

消息类型

参数 类型 Text 键值
TEXT 文本 文本内容(文字消息)
MAP 地图 位置文本(位置分享)
CARD 名片 推荐人字典(推荐人的名片)
SHARING 分享 分享名称(分享的音乐或者文章等)
PICTURE 下载方法 图片/表情
RECORDING 语音 下载方法
ATTACHMENT 附件 下载方法
VIDEO 小视频 下载方法
FRIENDS 好友邀请 添加好友所需参数
SYSTEM 系统消息 更新内容的用户或群聊的UserName组成的列表
NOTE 通知 通知文本(消息撤回等)

红包消息

MsgType: 49
AppMsgType: 2001
FromUserName: 发送方ID
ToUserName: 接收方ID
Content: 未知

安利一波:https://chenjiabing666.github.io/

Donate comment here
-------------本文结束感谢您的阅读-------------
Fork me on GitHub