打開首頁,配置設定一個随機uuid,
根據該uuid擷取二維碼圖檔。
微信用戶端掃描該圖檔,在用戶端确認登入。
浏覽器不停的調用一個接口,如果傳回登入成功,則調用登入接口
此時可以擷取聯系人清單,可以發送消息。然後不斷調用同步接口。
如果同步接口有傳回,則可以擷取新消息,然後繼續調用同步接口。
java版實作源碼:https://github.com/biezhi/wechat-robot
python實作:https://github.com/urinx/weixinbot
c#實作:https://github.com/sherlockchou86/wechat.net
qt實作:https://github.com/xiangzhai/qwx
| api | 擷取 uuid |
| --- | --------- |
| url | https://login.weixin.qq.com/jslogin |
| method | get |
| data | url encode |
| params | appid : wx782c26e4c19acffb
fun : new
lang: zh_cn
**_** : 時間戳 |
傳回資料(string):
| api | 顯示二維碼 |
| url | https://login.weixin.qq.com/qrcode/{uuid} |
| method | post |
| params | t : webwx
**_** : 時間戳|
| api | 二維碼掃描登入 |
| url | https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login |
| params | tip : 1:未掃描 0:已掃描
uuid : 擷取到的uuid
| api | webwxnewloginpage |
| url | https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage |
| params | ticket : xxx
uuid : xxx
lang : zh_cn
scan : xxx
fun : new |
傳回資料(xml):
在這一步擷取xml中的 <code>skey</code>, <code>wxsid</code>, <code>wxuin</code>, <code>pass_ticket</code>
| api | webwxinit |
| url | https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxinit |
| data | json |
| header | content-type: application/json; charset=utf-8 |
| params | {
baserequest: {
uin: xxx,
sid: xxx,
skey: xxx,
deviceid: xxx,
}
} |
傳回資料(json):
這一步中擷取 <code>synckey</code>, <code>user</code> 後面的消息監聽用。
| api | webwxstatusnotify |
| url | https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify |
baserequest: { uin: xxx, sid: xxx, skey: xxx, deviceid: xxx },
code: 3,
fromusername: 自己的id,
tousername: 自己的id,
clientmsgid: 時間戳
| api | webwxgetcontact |
| url | https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact |
| header | contenttype: application/json; charset=utf-8 |
| api | synccheck |
| url | https://webpush2.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck |
| api | webwxsync |
| url | https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=xxx&skey=xxx&pass_ticket=xxx |
synckey: xxx,
rr: <code>時間戳取反</code>
| api | webwxsendmsg |
| --- | ------------ |
| url | https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?pass_ticket=xxx |
msg: {
type: 1 文字消息,
content: 要發送的消息,
fromusername: 自己的id,
tousername: 好友的id,
localid: 與clientmsgid相同,
clientmsgid: 時間戳左移4位随後補上4位随機數
更多資料:
https://github.com/xiangzhai/qwx
https://github.com/urinx/weixinbot
http://www.07net01.com/2016/01/1201188.html
http://www.cnblogs.com/xiaozhi_5638/p/4923811.html