Web version of WeChat API, including terminal version of WeChat and WeChat robot
To ensure that the sample scripts run properly, please install the required third-party packages.
pip install -r requirements.txt
Note: The pictures and functions demonstrated below may not be the latest, please see the source code for details.
Follow the instructions to scan the QR code on your mobile phone WeChat and log in. You can choose whether to turn on the automatic reply mode.
After turning on the automatic reply mode, if a text message is received, it will automatically reply, including group messages.
Business cards, links, animated emoticons and address location messages.
Basically all the functions on the web version are currently supported.
+--------------+ +---------------+ +---------------+
| | | | | |
| Get UUID | | Get Contact | | Status Notify |
| | | | | |
+-------+------+ +-------^-------+ +-------^-------+
| | |
| +-------+ +--------+
| | |
+-------v------+ +-----+--+------+ +--------------+
| | | | | |
| Get QRCode | | Weixin Init +------> Sync Check <----+
| | | | | | |
+-------+------+ +-------^-------+ +-------+------+ |
| | | |
| | +-----------+
| | |
+-------v------+ +-------+--------+ +-------v-------+
| | Confirm Login | | | |
+------> Login +---------------> New Login Page | | Weixin Sync |
| | | | | | |
| +------+-------+ +----------------+ +---------------+
| |
|QRCode Scaned|
+-------------+
API | Get UUID |
---|---|
url | https://login.weixin.qq.com/jslogin |
method | POST |
data | URL Encode |
params | appid :应用ID fun : new 应用类型 lang : zh_CN 语言 _ : 时间戳 |
Return data (String):
window.QRLogin.code = 200; window.QRLogin.uuid = "xxx"
Note: The appid here is the AppID of the application registered on the WeChat open platform. The web version of WeChat has two AppIDs. The early one was
wx782c26e4c19acffb
, and the application name was displayed asWeb微信
on the WeChat client; the current one iswxeb7ec651dd0aefa9
, and the displayed name is微信网页版
.
API | Bind login (webwxpushloginurl) |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxpushloginurl |
method | GET |
params | uin :xxx |
Return data (String):
{'msg': 'all ok', 'uuid': 'xxx', 'ret': '0'}
通过这种方式可以省掉扫二维码这步操作,更加方便
API | Generate QR code |
---|---|
url | https://login.weixin.qq.com/l/ uuid |
method | GET |
API | Scan QR code to log in |
---|---|
url | https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login |
method | GET |
params | tip : 1未扫描 0已扫描 uuid :xxx _ : 时间戳 |
Return data (String):
window.code=xxx;
xxx:
408 登陆超时
201 扫描成功
200 确认登录
当返回200时,还会有
window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=xxx&uuid=xxx&lang=xxx&scan=xxx";
API | webwxnewloginpage |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage |
method | GET |
params | ticket : xxx uuid :xxx lang : zh_CN 语言 scan :xxx fun : new |
Return data (XML):
<error>
<ret>0</ret>
<message>OK</message>
<skey>xxx</skey>
<wxsid>xxx</wxsid>
<wxuin>xxx</wxuin>
<pass_ticket>xxx</pass_ticket>
<isgrayscale>1</isgrayscale>
</error>
API | webwxinit |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?pass_ticket=xxx&skey=xxx&r=xxx |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
params | { BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx, } } |
Return data (JSON):
{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
},
"Count": 11,
"ContactList": [...],
"SyncKey": {
"Count": 4,
"List": [
{
"Key": 1,
"Val": 635705559
},
...
]
},
"User": {
"Uin": xxx,
"UserName": xxx,
"NickName": xxx,
"HeadImgUrl": xxx,
"RemarkName": "",
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"HideInputBarFlag": 0,
"StarFriend": 0,
"Sex": 1,
"Signature": "Apt-get install B",
"AppAccountFlag": 0,
"VerifyFlag": 0,
"ContactFlag": 0,
"WebWxPluginSwitch": 0,
"HeadImgFlag": 1,
"SnsFlag": 17
},
"ChatSet": xxx,
"SKey": xxx,
"ClientVersion": 369297683,
"SystemTime": 1453124908,
"GrayScale": 1,
"InviteStartCount": 40,
"MPSubscribeMsgCount": 2,
"MPSubscribeMsgList": [...],
"ClickReportInterval": 600000
}
API | webwxstatusnotify |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify?lang=zh_CN&pass_ticket=xxx |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
params | { BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx }, Code: 3, FromUserName: 自己ID ,ToUserName: 自己ID ,ClientMsgId: 时间戳 } |
Return data (JSON):
{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
},
...
}
API | webwxgetcontact |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin//webwxgetcontact?pass_ticket=xxx&skey=xxx&r=xxx |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
Return data (JSON):
{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
},
"MemberCount": 334,
"MemberList": [
{
"Uin": 0,
"UserName": xxx,
"NickName": "Urinx",
"HeadImgUrl": xxx,
"ContactFlag": 3,
"MemberCount": 0,
"MemberList": [],
"RemarkName": "",
"HideInputBarFlag": 0,
"Sex": 0,
"Signature": "你好,我们是地球三体组织。在这里,你将感受到不一样的思维模式,以及颠覆常规的世界观。而我们的目标,就是以三体人的智慧,引领人类未来科学技术500年。",
"VerifyFlag": 8,
"OwnerUin": 0,
"PYInitial": "URINX",
"PYQuanPin": "Urinx",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"StarFriend": 0,
"AppAccountFlag": 0,
"Statues": 0,
"AttrStatus": 0,
"Province": "",
"City": "",
"Alias": "Urinxs",
"SnsFlag": 0,
"UniFriend": 0,
"DisplayName": "",
"ChatRoomId": 0,
"KeyWord": "gh_",
"EncryChatRoomId": ""
},
...
],
"Seq": 0
}
API | webwxbatchgetcontact |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact?type=ex&r=xxx&pass_ticket=xxx |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
params | { BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx }, Count: 群数量 ,List: [ { UserName: 群ID , EncryChatRoomId: "" },... ], } |
Return data (JSON) same as above
API | synccheck |
---|---|
protocol | https |
host | webpush.weixin.qq.com webpush.wx2.qq.com webpush.wx8.qq.com webpush.wx.qq.com webpush.web2.wechat.com webpush.web.wechat.com |
path | /cgi-bin/mmwebwx-bin/synccheck |
method | GET |
data | URL Encode |
params | r :时间戳 sid :xxx uin :xxx skey : xxx deviceid :xxx synckey :xxx _ : 时间戳 |
Return data (String):
window.synccheck={retcode:"xxx",selector:"xxx"}
retcode:
0 正常
1100 失败/登出微信
selector:
0 正常
2 新的消息
7 进入/离开聊天界面
API | webwxsync |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=xxx&skey=xxx&pass_ticket=xxx |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
params | { BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx }, SyncKey: xxx, rr: 时间戳取反 } |
Return data (JSON):
{
'BaseResponse': {'ErrMsg': '', 'Ret': 0},
'SyncKey': {
'Count': 7,
'List': [
{'Val': 636214192, 'Key': 1},
...
]
},
'ContinueFlag': 0,
'AddMsgCount': 1,
'AddMsgList': [
{
'FromUserName': '',
'PlayLength': 0,
'RecommendInfo': {...},
'Content': "",
'StatusNotifyUserName': '',
'StatusNotifyCode': 5,
'Status': 3,
'VoiceLength': 0,
'ToUserName': '',
'ForwardFlag': 0,
'AppMsgType': 0,
'AppInfo': {'Type': 0, 'AppID': ''},
'Url': '',
'ImgStatus': 1,
'MsgType': 51,
'ImgHeight': 0,
'MediaId': '',
'FileName': '',
'FileSize': '',
...
},
...
],
'ModChatRoomMemberCount': 0,
'ModContactList': [],
'DelContactList': [],
'ModChatRoomMemberList': [],
'DelContactCount': 0,
...
}
API | webwxsendmsg |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?pass_ticket=xxx |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
params | { BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx }, Msg: { Type: 1 文字消息 ,Content: 要发送的消息 ,FromUserName: 自己ID ,ToUserName: 好友ID ,LocalID: 与clientMsgId相同 ,ClientMsgId: 时间戳左移4位随后补上4位随机数 } } |
Return data (JSON):
{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
},
...
}
API | webwxrevokemsg |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxrevokemsg |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
params | { BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx }, SvrMsgId: msg_id, ToUserName: user_id, ClientMsgId: local_msg_id } |
Return data (JSON):
{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
}
}
API | webwxsendmsgemotion |
---|---|
url | https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendemoticon?fun=sys&f=json&pass_ticket=xxx |
method | POST |
data | JSON |
header | ContentType: application/json; charset=UTF-8 |
params | { BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx }, Msg: { Type: 47 emoji消息 ,EmojiFlag: 2, MediaId: 表情上传后的媒体ID ,FromUserName: 自己ID ,ToUserName: 好友ID ,LocalID: 与clientMsgId相同 ,ClientMsgId: 时间戳左移4位随后补上4位随机数 } } |
API | webwxgeticon |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgeticon |
method | GET |
params | seq :数字,可为空 username : ID skey : xxx |
API | webwxgetheadimg |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetheadimg |
method | GET |
params | seq :数字,可为空 username : 群ID skey : xxx |
API | webwxgetmsgimg |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg |
method | GET |
params | MsgID :消息ID type : slave 略缩图 or为空时加载原图 skey : xxx |
API | webwxgetvideo |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetvideo |
method | GET |
params | msgid :消息ID skey : xxx |
API | webwxgetvoice |
---|---|
url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetvoice |
method | GET |
params | msgid :消息ID skey : xxx |
type | illustrate |
---|---|
Personal account | Start with @ , for example: @xxx |
group chat | Start with @@ , for example: @@xxx |
Public account/service account | Starts with @ but has VerifyFlag & 8 != 0VerifyFlag :General personal public account/service account: 8 General enterprise service number: 24 WeChat official account 微信团队 : 56 |
Special account | Accounts such as File Transfer Assistant have special IDs. The currently known ones are:filehelper , newsapp , fmessage , weibo , qqmail , tmessage , qmessage , qqsync , floatbottle , lbsapp , shakeapp , medianote , qqfriend , readerapp , blogapp , facebookapp , masssendapp , meishiapp , feedsapp , voip , blogappweixin , weixin , brandsessionholder , weixinreminder , officialaccounts , notification_messages , wxitil , userexperience_alarm , notification_messages |
General format of message:
{
"FromUserName": "",
"ToUserName": "",
"Content": "",
"StatusNotifyUserName": "",
"ImgWidth": 0,
"PlayLength": 0,
"RecommendInfo": {...},
"StatusNotifyCode": 4,
"NewMsgId": "",
"Status": 3,
"VoiceLength": 0,
"ForwardFlag": 0,
"AppMsgType": 0,
"Ticket": "",
"AppInfo": {...},
"Url": "",
"ImgStatus": 1,
"MsgType": 1,
"ImgHeight": 0,
"MediaId": "",
"MsgId": "",
"FileName": "",
"HasProductId": 0,
"FileSize": "",
"CreateTime": 1454602196,
"SubMsgType": 0
}
MsgType | illustrate |
---|---|
1 | text message |
3 | Picture message |
34 | voice message |
37 | Friend confirmation message |
40 | POSSIBLEFRIEND_MSG |
42 | Share business card |
43 | video message |
47 | animated emoticons |
48 | location message |
49 | share link |
50 | VOIPMSG |
51 | WeChat initialization message |
52 | VOIPNOTIFY |
53 | VOIPINVITE |
62 | short video |
9999 | SYSNOTICE |
10000 | System messages |
10002 | Withdraw message |
WeChat initialization message
MsgType: 51
FromUserName: 自己ID
ToUserName: 自己ID
StatusNotifyUserName: 最近联系的联系人ID
Content:
< msg >
< op id =' 4 ' >
< username >
// 最近联系的联系人
filehelper,xxx@chatroom,wxid_xxx,xxx,...
</ username >
< unreadchatlist >
< chat >
< username >
// 朋友圈
MomentsUnreadMsgStatus
</ username >
< lastreadtime >
1454502365
</ lastreadtime >
</ chat >
</ unreadchatlist >
< unreadfunctionlist >
// 未读的功能账号消息,群发助手,漂流瓶等
</ unreadfunctionlist >
</ op >
</ msg >
text message
MsgType: 1
FromUserName: 发送方ID
ToUserName: 接收方ID
Content: 消息内容
Picture message
MsgType: 3
FromUserName: 发送方ID
ToUserName: 接收方ID
MsgId: 用于获取图片
Content:
< msg >
< img length =" 6503 " hdlength =" 0 " />
< commenturl > </ commenturl >
</ msg >
Small video message
MsgType: 62
FromUserName: 发送方ID
ToUserName: 接收方ID
MsgId: 用于获取小视频
Content:
< msg >
< img length =" 6503 " hdlength =" 0 " />
< commenturl > </ commenturl >
</ msg >
geolocation message
MsgType: 1
FromUserName: 发送方ID
ToUserName: 接收方ID
Content: http://weixin.qq.com/cgi-bin/redirectforward?args=xxx
// 属于文本消息,只不过内容是一个跳转到地图的链接
business card message
MsgType: 42
FromUserName: 发送方ID
ToUserName: 接收方ID
Content :
< ? xml version = "1.0" ? >
< msg bigheadimgurl = "" smallheadimgurl = "" username = "" nickname = "" shortpy = "" alias = "" imagestatus = "3" scene = "17" province = "" city = "" sign = "" sex = "1" certflag = "0" certinfo = "" brandIconUrl = "" brandHomeUrl = "" brandSubscriptConfigUrl = "" brandFlags = "0" regionCode = "" />
RecommendInfo:
{
"UserName" : "xxx" , // ID
"Province" : "xxx" ,
"City" : "xxx" ,
"Scene" : 17 ,
"QQNum" : 0 ,
"Content" : "" ,
"Alias" : "xxx" , // 微信号
"OpCode" : 0 ,
"Signature" : "" ,
"Ticket" : "" ,
"Sex" : 0 , // 1:男, 2:女
"NickName" : "xxx" , // 昵称
"AttrStatus" : 4293221 ,
"VerifyFlag" : 0
}
voice message
MsgType: 34
FromUserName: 发送方ID
ToUserName: 接收方ID
MsgId: 用于获取语音
Content:
< msg >
< voicemsg endflag =" 1 " cancelflag =" 0 " forwardflag =" 0 " voiceformat =" 4 " voicelength =" 1580 " length =" 2026 " bufid =" 216825389722501519 " clientmsgid =" 49efec63a9774a65a932a4e5fcd4e923filehelper174_1454602489 " fromusername ="" />
</ msg >
animated emoticons
MsgType: 47
FromUserName: 发送方ID
ToUserName: 接收方ID
Content:
< msg >
< emoji fromusername = "" tousername = "" type =" 2 " idbuffer =" media:0_0 " md5 =" e68363487d8f0519c4e1047de403b2e7 " len = " 86235 " productid =" com.tencent.xin.emoticon.bilibili " androidmd5 =" e68363487d8f0519c4e1047de403b2e7 " androidlen =" 86235 " s60v3md5 = " e68363487d8f0519c4e1047de403b2e7 " s60v3len =" 86235 " s60v5md5 = " e68363487d8f0519c4e1047de403b2e7 " s60v5len =" 86235 " cdnurl = " http://emoji.qpic.cn/wx_emoji/eFygWtxcoMF8M0oCCsksMA0gplXAFQNpiaqsmOicbXl1OC4Tyx18SGsQ/ " designerid = "" thumburl = " http://mmbiz.qpic.cn/mmemoticon/dx4Y70y9XctRJf6tKsy7FwWosxd4DAtItSfhKS0Czr56A70p8U5O8g/0 " encrypturl = " http://emoji.qpic.cn/wx_emoji/UyYVK8GMlq5VnJ56a4GkKHAiaC266Y0me0KtW6JN2FAZcXiaFKccRevA/ " aeskey = " a911cc2ec96ddb781b5ca85d24143642 " > </ emoji >
< gameext type =" 0 " content =" 0 " > </ gameext >
</ msg >
Common link or application sharing message
MsgType: 49
AppMsgType: 5
FromUserName: 发送方ID
ToUserName: 接收方ID
Url: 链接地址
FileName: 链接标题
Content:
< msg >
< appmsg appid ="" sdkver =" 0 " >
< title > </ title >
< des > </ des >
< type > 5 </ type >
< content > </ content >
< url > </ url >
< thumburl > </ thumburl >
...
</ appmsg >
< appinfo >
< version > </ version >
< appname > </ appname >
</ appinfo >
</ msg >
music link message
MsgType: 49
AppMsgType: 3
FromUserName: 发送方ID
ToUserName: 接收方ID
Url: 链接地址
FileName: 音乐名
AppInfo: // 分享链接的应用
{
Type: 0,
AppID: wx485a97c844086dc9
}
Content:
< msg >
< appmsg appid =" wx485a97c844086dc9 " sdkver =" 0 " >
< title > </ title >
< des > </ des >
< action > </ action >
< type > 3 </ type >
< showtype > 0 </ showtype >
< mediatagname > </ mediatagname >
< messageext > </ messageext >
< messageaction > </ messageaction >
< content > </ content >
< contentattr > 0 </ contentattr >
< url > </ url >
< lowurl > </ lowurl >
< dataurl >
http://ws.stream.qqmusic.qq.com/C100003i9hMt1bgui0.m4a?vkey=6867EF99F3684&guid=ffffffffc104ea2964a111cf3ff3edaf&fromtag=46
</ dataurl >
< lowdataurl >
http://ws.stream.qqmusic.qq.com/C100003i9hMt1bgui0.m4a?vkey=6867EF99F3684&guid=ffffffffc104ea2964a111cf3ff3edaf&fromtag=46
</ lowdataurl >
< appattach >
< totallen > 0 </ totallen >
< attachid > </ attachid >
< emoticonmd5 > </ emoticonmd5 >
< fileext > </ fileext >
</ appattach >
< extinfo > </ extinfo >
< sourceusername > </ sourceusername >
< sourcedisplayname > </ sourcedisplayname >
< commenturl > </ commenturl >
< thumburl >
http://imgcache.qq.com/music/photo/album/63/180_albumpic_143163_0.jpg
</ thumburl >
< md5 > </ md5 >
</ appmsg >
< fromusername > </ fromusername >
< scene > 0 </ scene >
< appinfo >
< version > 29 </ version >
< appname >摇一摇搜歌</ appname >
</ appinfo >
< commenturl > </ commenturl >
</ msg >
Group message
MsgType: 1
FromUserName: @@xxx
ToUserName: @xxx
Content:
@xxx:<br/>xxx
Red envelope news
MsgType: 49
AppMsgType: 2001
FromUserName: 发送方ID
ToUserName: 接收方ID
Content: 未知
Note: According to the code of the web version, it can be seen that it may support viewing red envelope messages in the future, but currently it uses system messages, see below.
System messages
MsgType: 10000
FromUserName: 发送方ID
ToUserName: 自己ID
Content:
"你已添加了 xxx ,现在可以开始聊天了。"
"如果陌生人主动添加你为朋友,请谨慎核实对方身份。"
"收到红包,请在手机上查看"
If you want to communicate with other developers of WeixinBot, or have any questions or suggestions, you are welcome to join the WeChat group [Youth fed the dog] for discussion. Scan the QR code below to add the robot as a friend, and reply to [Aidog] to get the link to join the group.
Note: This is not the QR code of the group. It is a robot that pulls you into the group. Remember to reply to the robot [Aidog]~ (secret code: Aidog)