Table of Contents
WeChat web protocol analysis (WeChat web version wx2.qq.com)
Execution process
WebWechat API
1. Get UUID (refer to method getUUID)
API
状态通知(参考方法 wxStatusNotify)" >6. 开启微信状态通知(参考方法 wxStatusNotify)
7. 获取联系人列表(参考方法 getContact)
8.消息检查(参考方法 syncCheck)
9. 获取最新消息(参考方法 webwxsync)
10. 发送消息(参考方法 webwxsendmsg)
Home WeChat Applet WeChat Development Detailed explanation of WeChat protocol

Detailed explanation of WeChat protocol

May 06, 2017 am 10:27 AM

WeChat web protocol analysis (WeChat web version wx2.qq.com)

1. Open the homepage and assign a random uuid,
2. Get the QR code image based on the uuid.
3. WeChat client scans the picture and confirms login on the client.
4. The browser keeps calling an interface. If the login is successful, it calls the login interface
5. At this time, you can get the contact list and send a message. Then continuously call the synchronization interface.
6. If the synchronization interface returns, you can obtain new messages and then continue to call the synchronization interface.

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

Execution process

       +--------------+     +---------------+   +---------------+
       |              |     |               |   |               |
       |   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|
+-------------+
Copy after login

WebWechat API

1. Get UUID (refer to method getUUID)

##dataURL Encodeparams##Return data (
API Get UUID
url https ://login.weixin.qq.com/jslogin
method GET
appid : wx782c26e4c19acffb
fun : new
lang : zh_CN
_ : Timestamp
String

) :

2. Display QR code (refer to method showQrCode)

##APIDisplay QR codeurllogin.weixin.qq.com/qrcode/{uuid}methodPOSTparams : webwx
3. Wait for login (refer to method waitForLogin) Here is WeChat confirmation login
t _ : Timestamp


##APIQR code scan loginurllogin.weixin.qq.com/cgi-bin/mmwebwx-bin/loginGETtip 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";
Copy after login
4. Log in to get
method
params
: 1: Not scanned 0 : Scanned uuid : Obtained uuid
_ : Timestamp
Cookie

(refer to method login)

APIwebwxnewloginpageurlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpageGETticketReturn Data (XML):
method
params
: xxx uuid : xxx
lang : zh_CN
scan : xxx
fun : new
<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>
Copy after login

In this step, get the skey,

wxsid

, wxuin, # in xml ##pass_ticket5. WeChat initialization (refer to method wxInit)

API

webwxiniturlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxinitmethodPOSTdataJSONContent -Type: application/json; charset=UTF-8params{ BaseRequest: { Uin: xxx, Skey: xxx,
header
Sid: 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
}
Copy after login

这一步中获取 SyncKey, User 后面的消息监听用。

6. 开启微信状态通知(参考方法 wxStatusNotify)

APIwebwxstatusnotify
urlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify
methodPOST
dataJSON
headerContent-Type: application/json; charset=UTF-8
params{
BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx },
Code: 3,
FromUserName: 自己的ID,
ToUserName: 自己的ID,
ClientMsgId: 时间戳
}

返回数据(JSON):

{
    "BaseResponse": {
        "Ret": 0,
        "ErrMsg": ""
    },
    ...
}
Copy after login

7. 获取联系人列表(参考方法 getContact)

APIwebwxgetcontact
urlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact
methodPOST
dataJSON
headerContentType: application/json; charset=UTF-8
params{
BaseRequest: {
Uin: xxx,
Sid: xxx,
Skey: xxx,
DeviceID: xxx,
}
}

返回数据(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": "我是二蛋",
            "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
}
Copy after login

8.消息检查(参考方法 syncCheck)

APIsynccheck
urlwebpush2.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck
methodGET
dataJSON
headerContentType: application/json; charset=UTF-8
params{
BaseRequest: {
Uin: xxx,
Sid: xxx,
Skey: xxx,
DeviceID: xxx,
}
}

返回数据(String):

window.synccheck={retcode:"xxx",selector:"xxx"}

retcode:
    0 正常
    1100 失败/登出微信
selector:
    0 正常
    2 新的消息
    7 进入/离开聊天界面
Copy after login

9. 获取最新消息(参考方法 webwxsync)

APIwebwxsync
urlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=xxx&skey=xxx&pass_ticket=xxx
methodPOST
dataJSON
headerContentType: application/json; charset=UTF-8
params{
BaseRequest: { Uin: xxx, Sid: xxx, Skey: xxx, DeviceID: xxx },
SyncKey: xxx,
rr: 时间戳取反
}

返回数据(JSON):

{
    &#39;BaseResponse&#39;: {&#39;ErrMsg&#39;: &#39;&#39;, &#39;Ret&#39;: 0},
    &#39;SyncKey&#39;: {
        &#39;Count&#39;: 7,
        &#39;List&#39;: [
            {&#39;Val&#39;: 636214192, &#39;Key&#39;: 1},
            ...
        ]
    },
    &#39;ContinueFlag&#39;: 0,
    &#39;AddMsgCount&#39;: 1,
    &#39;AddMsgList&#39;: [
        {
            &#39;FromUserName&#39;: &#39;&#39;,
            &#39;PlayLength&#39;: 0,
            &#39;RecommendInfo&#39;: {...},
            &#39;Content&#39;: "", 
            &#39;StatusNotifyUserName&#39;: &#39;&#39;,
            &#39;StatusNotifyCode&#39;: 5,
            &#39;Status&#39;: 3,
            &#39;VoiceLength&#39;: 0,
            &#39;ToUserName&#39;: &#39;&#39;,
            &#39;ForwardFlag&#39;: 0,
            &#39;AppMsgType&#39;: 0,
            &#39;AppInfo&#39;: {&#39;Type&#39;: 0, &#39;AppID&#39;: &#39;&#39;},
            &#39;Url&#39;: &#39;&#39;,
            &#39;ImgStatus&#39;: 1,
            &#39;MsgType&#39;: 51,
            &#39;ImgHeight&#39;: 0,
            &#39;MediaId&#39;: &#39;&#39;, 
            &#39;FileName&#39;: &#39;&#39;,
            &#39;FileSize&#39;: &#39;&#39;,
            ...
        },
        ...
    ],
    &#39;ModChatRoomMemberCount&#39;: 0,
    &#39;ModContactList&#39;: [],
    &#39;DelContactList&#39;: [],
    &#39;ModChatRoomMemberList&#39;: [],
    &#39;DelContactCount&#39;: 0,
    ...
}
Copy after login

10. 发送消息(参考方法 webwxsendmsg)

APIwebwxsendmsg
urlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?pass_ticket=xxx
methodPOST
dataJSON
headerContentType: 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位随机数
}
}

返回数据(JSON):

{
    "BaseResponse": {
        "Ret": 0,
        "ErrMsg": ""
    },
    ...
}
Copy after login

更多资料:
github.com/xiangzhai/qwx
github.com/Urinx/WeixinBot
www.07net01.com/2016/01/1201188.html
www.cnblogs.com/xiaozhi_5638/p/4923811.html

【相关推荐】

1. 微信公众号源码下载

2. 阿狸子订单系统源码下载

The above is the detailed content of Detailed explanation of WeChat protocol. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Ouyi Exchange app domestic download tutorial Ouyi Exchange app domestic download tutorial Mar 21, 2025 pm 05:42 PM

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

The difference between H5 and mini-programs and APPs The difference between H5 and mini-programs and APPs Apr 06, 2025 am 10:42 AM

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

What should I do if the company's security software conflicts with applications? How to troubleshoot HUES security software causes common software to fail to open? What should I do if the company's security software conflicts with applications? How to troubleshoot HUES security software causes common software to fail to open? Apr 01, 2025 pm 10:48 PM

Compatibility issues and troubleshooting methods for company security software and application. Many companies will install security software in order to ensure intranet security. However, security software sometimes...

What is the difference between H5 page production and WeChat applets What is the difference between H5 page production and WeChat applets Apr 05, 2025 pm 11:51 PM

H5 is more flexible and customizable, but requires skilled technology; mini programs are quick to get started and easy to maintain, but are limited by the WeChat framework.

How to solve the problem of JS resource caching in enterprise WeChat? How to solve the problem of JS resource caching in enterprise WeChat? Apr 04, 2025 pm 05:06 PM

Discussion on the JS resource caching issue of Enterprise WeChat. When upgrading project functions, some users often encounter situations where they fail to successfully upgrade, especially in the enterprise...

How to choose H5 and applets How to choose H5 and applets Apr 06, 2025 am 10:51 AM

The choice of H5 and applet depends on the requirements. For applications with cross-platform, rapid development and high scalability, choose H5; for applications with native experience, rich functions and platform dependencies, choose applets.

Detailed tutorial on how to buy and sell Binance virtual currency Detailed tutorial on how to buy and sell Binance virtual currency Mar 18, 2025 pm 01:36 PM

This article provides a brief guide to buying and selling of Binance virtual currency updated in 2025, and explains in detail the operation steps of virtual currency transactions on the Binance platform. The guide covers fiat currency purchase USDT, currency transaction purchase of other currencies (such as BTC), and selling operations, including market trading and limit trading. In addition, the guide also specifically reminds key risks such as payment security and network selection for fiat currency transactions, helping users to conduct Binance transactions safely and efficiently. Through this article, you can quickly master the skills of buying and selling virtual currencies on the Binance platform and reduce transaction risks.

The first dual-core cultural and tourism digital hominid in the country! Tencent Cloud helps Huaguoshan Scenic Area connect to DeepSeek, making the 'Sage Monkey King' smarter and warmer The first dual-core cultural and tourism digital hominid in the country! Tencent Cloud helps Huaguoshan Scenic Area connect to DeepSeek, making the 'Sage Monkey King' smarter and warmer Mar 12, 2025 pm 12:57 PM

Lianyungang Huaguoshan Scenic Area joins hands with Tencent Cloud to launch the first "dual-core brain" Digital Homo sapiens in the cultural and tourism industry - Monkey King! On March 1, the scenic spot officially connected the Monkey King to the DeepSeek platform, so that it has the two AI model capabilities of Tencent Hunyuan and DeepSeek, bringing tourists a smarter and more considerate service experience. Huaguoshan Scenic Area has previously launched the Monkey King of the Digital Homo sapiens based on Tencent Hunyuan model. This time, Tencent Cloud further utilizes technologies such as the big model knowledge engine to connect it to DeepSeek to achieve a "dual-core" upgrade. This makes the Monkey King's interactive ability to a higher level, faster response speed, stronger understanding ability, and more warmth. Monkey King has strong natural language processing capabilities and can understand various ways of asking questions from tourists.

See all articles