网页版微信API,包含终端版微信及微信机器人
网页版微信API,包含终端版微信及微信机器人
为了确保能正常运行示例脚本,请安装所需的第三方包。
pip install -r requirements.txt
注:下面演示的图片与功能可能不是最新的,具体请看源码。
按照操作指示在手机微信上扫描二维码然后登录,你可以选择是否开启自动回复模式。
开启自动回复模式后,如果接收到的是文字消息就会自动回复,包括群消息。
名片,链接,动画表情和地址位置消息。
网页版上有的功能目前基本上都能支持。
+--------------+ +---------------+ +---------------+ | | | | | | | Get UUID | | Get Contact | | Status Notify | | | | | | | +-------+------+ +-------^-------+ +-------^-------+ | | | | +-------+ +--------+ | | | +-------v------+ +-----+--+------+ +--------------+ | | | | | | | Get QRCode | | Weixin Init +------> Sync Check Login +---------------> New Login Page | | Weixin Sync | | | | | | | | | +------+-------+ +----------------+ +---------------+ | | |QRCode Scaned| +-------------+
| API | 获取 UUID | | --- | --------- | | url | https://login.weixin.qq.com/jslogin | | method | POST | | data | URL Encode | | params | appid:
应用ID
应用类型
语言
时间戳|
返回数据(String):
window.QRLogin.code = 200; window.QRLogin.uuid = "xxx"
注:这里的appid就是在微信开放平台注册的应用的AppID。网页版微信有两个AppID,早期的是
wx782c26e4c19acffb,在微信客户端上显示为应用名称为Web微信;现在用的是wxeb7ec651dd0aefa9,显示名称为微信网页版。
| API | 绑定登陆(webwxpushloginurl) | | --- | --------- | | url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxpushloginurl | | method | GET | | params | uin: xxx |
返回数据(String): ``` {'msg': 'all ok', 'uuid': 'xxx', 'ret': '0'}
通过这种方式可以省掉扫二维码这步操作,更加方便
```
| API | 生成二维码 | | --- | --------- | | url | https://login.weixin.qq.com/l/
uuid| | method | GET |
| API | 二维码扫描登录 | | --- | --------- | | url | https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login | | method | GET | | params | tip: 1
未扫描0
已扫描
时间戳|
返回数据(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
语言
返回数据(XML):
0 OK xxx xxx xxx xxx 1
| 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,
}
} |
返回数据(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=zhCN&passticket=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,
自己ID,
时间戳
返回数据(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 |
返回数据(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:
群数量,
群ID, EncryChatRoomId: "" },
返回数据(JSON)同上
| 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:
时间戳
时间戳|
返回数据(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:
时间戳取反
返回数据(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
文字消息,
要发送的消息,
自己ID,
好友ID,
与clientMsgId相同,
时间戳左移4位随后补上4位随机数
返回数据(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: msgid,
ToUserName: userid,
ClientMsgId: localmsgid
} |
返回数据(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消息,
表情上传后的媒体ID,
自己ID,
好友ID,
与clientMsgId相同,
时间戳左移4位随后补上4位随机数
| API | webwxgeticon | | --- | ------------ | | url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgeticon | | method | GET | | params | seq:
数字,可为空
ID
| API | webwxgetheadimg | | --- | --------------- | | url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetheadimg | | method | GET | | params | seq:
数字,可为空
群ID
| API | webwxgetmsgimg | | --- | --------------- | | url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg | | method | GET | | params | MsgID:
消息ID
略缩图or
为空时加载原图
| API | webwxgetvideo | | --- | --------------- | | url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetvideo | | method | GET | | params | msgid:
消息ID
| API | webwxgetvoice | | --- | --------------- | | url | https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetvoice | | method | GET | | params | msgid:
消息ID
| 类型 | 说明 | | :--: | --- | | 个人账号 | 以
@开头,例如:
@xxx| | 群聊 | 以
@@开头,例如:
@@xxx| | 公众号/服务号 | 以
@开头,但其
VerifyFlag& 8 != 0
VerifyFlag:
微信团队:56 | | 特殊账号 | 像文件传输助手之类的账号,有特殊的ID,目前已知的有:
filehelper,
newsapp,
fmessage,
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|
消息一般格式:
{ "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 | 说明 |
| ------- | --- |
| 1 | 文本消息 |
| 3 | 图片消息 |
| 34 | 语音消息 |
| 37 | 好友确认消息 |
| 40 | POSSIBLEFRIEND_MSG |
| 42 | 共享名片 |
| 43 | 视频消息 |
| 47 | 动画表情 |
| 48 | 位置消息 |
| 49 | 分享链接 |
| 50 | VOIPMSG |
| 51 | 微信初始化消息 |
| 52 | VOIPNOTIFY |
| 53 | VOIPINVITE |
| 62 | 小视频 |
| 9999 | SYSNOTICE |
| 10000 | 系统消息 |
| 10002 | 撤回消息 |
微信初始化消息
html MsgType: 51 FromUserName: 自己ID ToUserName: 自己ID StatusNotifyUserName: 最近联系的联系人ID Content: // 最近联系的联系人 filehelper,[email protected],wxid_xxx,xxx,... // 朋友圈 MomentsUnreadMsgStatus 1454502365 // 未读的功能账号消息,群发助手,漂流瓶等
文本消息
MsgType: 1 FromUserName: 发送方ID ToUserName: 接收方ID Content: 消息内容
图片消息
html MsgType: 3 FromUserName: 发送方ID ToUserName: 接收方ID MsgId: 用于获取图片 Content:![]()
小视频消息
html MsgType: 62 FromUserName: 发送方ID ToUserName: 接收方ID MsgId: 用于获取小视频 Content:![]()
地理位置消息
MsgType: 1 FromUserName: 发送方ID ToUserName: 接收方ID Content: http://weixin.qq.com/cgi-bin/redirectforward?args=xxx // 属于文本消息,只不过内容是一个跳转到地图的链接
名片消息 ```js MsgType: 42 FromUserName: 发送方ID ToUserName: 接收方ID Content: <?xml version="1.0"?>
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 } ```
语音消息
html MsgType: 34 FromUserName: 发送方ID ToUserName: 接收方ID MsgId: 用于获取语音 Content:
动画表情
html MsgType: 47 FromUserName: 发送方ID ToUserName: 接收方ID Content:
普通链接或应用分享消息
html MsgType: 49 AppMsgType: 5 FromUserName: 发送方ID ToUserName: 接收方ID Url: 链接地址 FileName: 链接标题 Content: 5 ...
音乐链接消息 ```html MsgType: 49 AppMsgType: 3 FromUserName: 发送方ID ToUserName: 接收方ID Url: 链接地址 FileName: 音乐名
AppInfo: // 分享链接的应用 { Type: 0, AppID: wx485a97c844086dc9 }
Content: 3 0 0 http://ws.stream.qqmusic.qq.com/C100003i9hMt1bgui0.m4a?vkey=6867EF99F3684&guid=ffffffffc104ea2964a111cf3ff3edaf&fromtag=46 http://ws.stream.qqmusic.qq.com/C100003i9hMt1bgui0.m4a?vkey=6867EF99F3684&guid=ffffffffc104ea2964a111cf3ff3edaf&fromtag=46 0 http://imgcache.qq.com/music/photo/album/63/180albumpic143163_0.jpg 0 29 摇一摇搜歌 ```
群消息
MsgType: 1 FromUserName: @@xxx ToUserName: @xxx Content: @xxx:
xxx
红包消息
MsgType: 49 AppMsgType: 2001 FromUserName: 发送方ID ToUserName: 接收方ID Content: 未知注:根据网页版的代码可以看到未来可能支持查看红包消息,但目前走的是系统消息,见下。
系统消息
MsgType: 10000 FromUserName: 发送方ID ToUserName: 自己ID Content: "你已添加了 xxx ,现在可以开始聊天了。" "如果陌生人主动添加你为朋友,请谨慎核实对方身份。" "收到红包,请在手机上查看"
如果你希望和 WeixinBot 的其他开发者交流,或者有什么问题和建议,欢迎大家加入微信群【Youth fed the dog】一起讨论。扫描下面的二维码添加机器人为好友,并回复【Aidog】获取入群链接。
注:这个不是群的二维码,是机器人拉你入群,记得回复机器人【Aidog】哦~ (secret code: Aidog)