這是一個建立於
的文章,其中的資訊可能已經有所發展或是發生改變。
主要模組
- 擷取UUID
- 根據UUID擷取二維碼
- 顯示二維碼
- 掃碼登陸
- 初始化資訊
- 開啟狀態同步通知
- 擷取通訊錄
- 發送資訊
- 同步資訊
- 擷取自動回複內容
源碼地址
https://github.com/qianlnk/gobot
網頁版API
擷取UUID
window.QRLogin.code = 200; window.QRLogin.uuid = "xxx";
擷取二維碼
登入
- 介面地址
https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip={1,0}&uuid=(UUID}&_={Timestamp}
tip: 1 未掃碼 0 已掃碼
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";
通過正則擷取後面需要的URL, 後面統一用BASE_URL表示。
BASE_URL = https://wx.qq.com
-
實現
參考Login方法
-
跳轉
擷取使用者的登入資訊
Skey string `xml:"skey"` Wxsid string `xml:"wxsid"` Wxuin string `xml:"wxuin"` PassTicket string `xml:"pass_ticket"`
初始化
type InitResult struct { BaseResponse BaseResponse `json:"BaseResponse"` Count int `json:"Count"` ContactList []Contact `json:"ContactList"` SyncKey SyncKey `json:"SyncKey"` User User `json:"User"` ChatSet string `json:"ChatSet"` SKey string `json:"SKey"` ClientVersion int `json:"ClientVersion"` SystemTime int `json:"SystemTime"` GrayScale int `json:"GrayScale"` InviteStartCount int `json:"InviteStartCount"` MPSubscribeMsgCount int `json:"MPSubscribeMsgCount"` MPSubscribeMsgList []MPSubscribeMsg `json:"MPSubscribeMsgList"` ClickReportInterval int `json:"ClickReportInterval"`}
狀態通知
params := make(map[string]interface{}) params["BaseRequest"] = w.baseRequest params["Code"] = 3 params["FromUserName"] = w.user.UserName params["ToUserName"] = w.user.UserName params["ClientMsgId"] = int(time.Now().Unix())
-實現
參考StatusNotify方法
擷取通訊錄
params := make(map[string]interface{}) params["BaseRequest"] = w.baseRequest
-方法
POST
同步資訊
- 介面地址
https://host/cgi-bin/mmwebwx-bin/synccheck
host:
Hosts = []string{ "webpush.wx.qq.com", "webpush2.wx.qq.com", "webpush.wechat.com", "webpush1.wechat.com", "webpush2.wechat.com", "webpush1.wechatapp.com", }
-參數
v := url.Values{} v.Add("r", w.timestamp()) v.Add("sid", w.loginRes.Wxsid) v.Add("uin", w.loginRes.Wxuin) v.Add("skey", w.loginRes.Skey) v.Add("deviceid", w.deviceID) v.Add("synckey", w.strSyncKey()) v.Add("_", w.timestamp())
window.synccheck={retcode:"xxx",selector:"xxx"}retcode: 0 正常 1100 手機上退出網頁版 1101在其他地方登入網頁版selector: 0 正常 2 新的訊息 7 進入/離開聊天介面
當selector=2時讀取新的資訊
params := make(map[string]interface{}) params["BaseRequest"] = w.baseRequest params["SyncKey"] = w.syncKey params["rr"] = ^int(time.Now().Unix())
修改synckey,重要
if msg.BaseResponse.Ret == 0 { w.syncKey = msg.SyncKey }
發送資訊
params := make(map[string]interface{}) params["BaseRequest"] = w.baseRequest msg := make(map[string]interface{}) msg["Type"] = 1 msg["Content"] = message msg["FromUserName"] = w.user.UserName msg["ToUserName"] = to msg["LocalID"] = clientMsgID msg["ClientMsgId"] = clientMsgID params["Msg"] = msg
-
方法
POST
-
實現
參考SendMessage方法
圖靈API
擷取自動回複內容
params := make(map[string]interface{}) params["userid"] = uid params["key"] = w.cfg.Tuling.Keys[w.user.NickName].Key params["info"] = msg
Code int `json:"code"` Text string `json:"text"` //100000 URL string `json:"url"` //200000 List interface{} `json:"list"` //302000 []News 308000 []Menu
run.png