资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

微信web协议的示例分析-创新互联

这篇文章主要介绍微信web协议的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

专注于为中小企业提供网站设计、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业博兴免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

微信web协议分析(微信网页版 wx2.qq.com)

1.打开首页,分配一个随机uuid,
2.根据该uuid获取二维码图片。
3.微信客户端扫描该图片,在客户端确认登录。
4.浏览器不停的调用一个接口,如果返回登录成功,则调用登录接口
5.此时可以获取联系人列表,可以发送消息。然后不断调用同步接口。
6.如果同步接口有返回,则可以获取新消息,然后继续调用同步接口。

源码地址:github.com/biezhi/wechat-robot

执行流程

       +--------------+     +---------------+   +---------------+
       |              |     |               |   |               |
       |   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|
+-------------+

WebWechat API

1. 获取UUID(参考方法 getUUID)

API获取 UUID
url/tupian/20230522/tdtdURL Encode
paramsappid : wx782c26e4c19acffb
fun : new
lang: zh_CN
_ : 时间戳

返回数据(String):

window.QRLogin.code = 200; window.QRLogin.uuid = "xxx"

2. 显示二维码(参考方法 showQrCode)

API显示二维码
urllogin.weixin.qq.com/qrcode/{uuid}
methodPOST
paramst : webwx
_ : 时间戳


3. 等待登录(参考方法 waitForLogin)这里是微信确认登录

API二维码扫描登录
urllogin.weixin.qq.com/cgi-bin/mmwebwx-bin/login
methodGET
paramstip : 1:未扫描 0:已扫描
uuid : 获取到的uuid
_ : 时间戳

返回数据(String):

window.code=xxx;

xxx:    408 登陆超时    201 扫描成功    200 确认登录

当返回200时,还会有
window.redirect_uri="/tupian/20230522/webwxnewloginpage 登录获取Cookie(参考方法 login)
APIwebwxnewloginpage
urlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage
methodGET
paramsticket : xxx
uuid : xxx
lang : zh_CN
scan : xxx
fun : new

返回数据(XML):


    0
    OK
    xxx
    xxx
    xxx
    xxx
    1

在这一步获取xml中的skey,wxsid,wxuin,pass_ticket

5. 微信初始化(参考方法 wxInit)

APIwebwxinit
urlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxinit
methodPOST
dataJSON
headerContent-Type: 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
}

这一步中获取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": ""
    },
    ...
}

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
}

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

APIsynccheck
urlwebpush3.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 进入/离开聊天界面

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):

{
    '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. 发送消息(参考方法 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": ""
    },
    ...
}

以上是“微信web协议的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


文章题目:微信web协议的示例分析-创新互联
浏览路径:http://cdkjz.cn/article/sheid.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220