Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Wechat web Protocol

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the example analysis of Wechat web protocol, the article is very detailed, has a certain reference value, interested friends must read it!

Analysis of Wechat web Protocol (Wechat web version wx2.qq.com)

1. Open the home page and assign a random uuid

two。 The QR code picture is obtained according to the uuid.

3. The Wechat client scans the picture and confirms the login on the client.

4. The browser keeps calling an interface, and if the login is returned, the login interface will be called.

5. At this point, you can get the contact list and send messages. And then keep calling the synchronization interface.

6. If the synchronization interface returns, you can get the new message and continue to call the synchronization interface.

Source code address: github.com/biezhi/wechat-robot

Execution flow +-+ | | Get UUID | | Get Contact | | Status Notify | | | +-^-+-^-+ | +-+ +-+ | +-v talk + +-- +-- + | | | | Get QRCode | | Weixin Init +-> Sync Check Login +-> New Login Page | | Weixin Sync | | | +-+ | | QRCode Scaned | +-+ WebWechat API1. Get UUID (reference method getUUID) API get UUIDurl https://login.weixin.qq.com/jsloginmethodGETdataURL Encodeparamsappid: wx782c26e4c19acffb

Fun: new

Lang: zh_CN

_: timestamp

Return data (String):

Window.QRLogin.code = 200; window.QRLogin.uuid = "xxx" 2. Display QR code (reference method showQrCode) API display QR code urllogin.weixin.qq.com/qrcode/ {uuid} methodPOSTparamst: webwx _: timestamp

3. Waiting for login (refer to method waitForLogin) here is Wechat confirm login API QR code scan login urllogin.weixin.qq.com/cgi-bin/mmwebwx-bin/loginmethodGETparamstip: 1: not scanned 0: scanned

Uuid: the acquired uuid

_: timestamp

Return data (String):

Window.code=xxx;xxx: login timeout 2010200 scan confirmed login when 200 is returned, there will be window.redirect_uri= "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=xxx&uuid=xxx&lang=xxx&scan=xxx";4." Log in to get Cookie (refer to method login) APIwebwxnewloginpageurlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpagemethodGETparamsticket: xxx

Uuid: xxx

Lang: zh_CN

Scan: xxx

Fun: new

Return data (XML):

0 OK xxx 1

Get the skey, wxsid, wxuin, pass_ticket in xml in this step

5. Initialization of Wechat (see method wxInit) APIwebwxiniturlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxinitmethodPOSTdataJSONheaderContent-Type: application/json; charset=UTF-8params {

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}

In this step, get the SyncKey, which is used for message listening after the User.

6. Enable Wechat status notification (see method wxStatusNotify) APIwebwxstatusnotifyurlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotifymethodPOSTdataJSONheaderContent-Type: application/json; charset=UTF-8params {

BaseRequest: {Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx}

Code: 3

FromUserName: your own ID

ToUserName: your own ID

ClientMsgId: timestamp

}

Return data (JSON):

{"BaseResponse": {"Ret": 0, "ErrMsg": ""},...} 7. Get contact list (refer to method getContact) APIwebwxgetcontacturlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontactmethodPOSTdataJSONheaderContentType: application/json; charset=UTF-8params {

BaseRequest: {

Uin: xxx

Sid: xxx

Skey: xxx

DeviceID: xxx

}

}

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": "I am two eggs", "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} 8. Message check (refer to method syncCheck) APIsynccheckurlwebpush3.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheckmethodGETdataJSONheaderContentType: application/json; charset=UTF-8params {

BaseRequest: {

Uin: xxx

Sid: xxx

Skey: xxx

DeviceID: xxx

}

}

Return data (String):

Window.synccheck= {retcode: "xxx", selector: "xxx"} retcode: 0 normal 1100 failed / logout Wechat selector: 0 normal 2 New message 7 enter / leave chat interface 9. Get the latest news (refer to method webwxsync) APIwebwxsyncurlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=xxx&skey=xxx&pass_ticket=xxxmethodPOSTdataJSONheaderContentType: application/json; charset=UTF-8params {

BaseRequest: {Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx}

SyncKey: xxx

Rr: timestamp reverse

}

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,...} 10. Send a message (refer to method webwxsendmsg) APIwebwxsendmsgurlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?pass_ticket=xxxmethodPOSTdataJSONheaderContentType: application/json; charset=UTF-8params {

BaseRequest: {Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx}

Msg: {

Type: 1 text message

Content: message to be sent

FromUserName: your own ID

ToUserName: friend's ID

LocalID: same as clientMsgId

ClientMsgId: the timestamp is moved 4 digits to the left and then 4 random digits are added

}

}

Return data (JSON):

{"BaseResponse": {"Ret": 0, "ErrMsg": ""},...} above are all the contents of the article "sample Analysis of Wechat web Protocol". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report