首頁 > 微信小程式 > 微信開發 > 微信協議詳解

微信協議詳解

Y2J
發布: 2017-05-06 10:27:26
原創
16868 人瀏覽過

微信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)

##data
API 取得UUID
url https ://login.weixin.qq.com/jslogin
method GET



URL Encodeappid : wx782c26e4c19acffb  : new lang : zh_CN  :
params
#fun
_時間戳
回傳資料(String) :
window.QRLogin.code = 200; window.QRLogin.uuid = "xxx"
登入後複製
2. 顯示QR碼(參考方法showQrCode)

#API

顯示二維碼


##urllogin.weixin.qq.com/qrcode/{uuid}#POSTt_
##method
params
 : webwx
 
 : 時間戳

3. 等待登入(參考方法waitForLogin)這裡是微信確認登入
API
二維碼掃描登入

url#login.weixin.qq.com/cgi-bin/mmwebwx-bin/login

methodGET#params

tip : 1:未掃描0 :已掃描 uuid :時間戳
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";
登入後複製
Cookie(參考方法login)APIwebwxnewloginpageurlwx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage## methodGET# : xxx lang
 : 取得的uuid _
#回傳資料(String ):4. 登入取得

params


ticket
 : xxx 

uuid
 : zh_CN ######scan### : xxx ######fun### : new#################返回資料(###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>
登入後複製
###在這一步驟取得xml中的 ###skey###, ###wxsid###, ####wxuin###, # ##pass_ticket#########5. 微信初始化(參考方法wxInit)###############API######webwxinit###### ############url######wx2.qq.com/cgi-bin/mmwebwx-bin/webwxinit############method### ###POST############data#########JSON###############header######Content -類型: application/json; charset=UTF-8#############params#####{ ###     BaseRequest: { ###   #  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
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 进入/离开聊天界面
登入後複製

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,
    ...
}
登入後複製

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": ""
    },
    ...
}
登入後複製

更多资料:
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. 阿狸子订单系统源码下载

以上是微信協議詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板