天天看点

微信协议分析和机器人实现

打开首页,分配一个随机uuid,

根据该uuid获取二维码图片。

微信客户端扫描该图片,在客户端确认登录。

浏览器不停的调用一个接口,如果返回登录成功,则调用登录接口

此时可以获取联系人列表,可以发送消息。然后不断调用同步接口。

如果同步接口有返回,则可以获取新消息,然后继续调用同步接口。

api

获取 uuid

url

<a href="https://login.weixin.qq.com/jslogin">https://login.weixin.qq.com/jslogin</a>

method

get

data

url encode

params

appid : wx782c26e4c19acffb &lt;br&gt; fun : new &lt;br&gt; lang: zh_cn &lt;br&gt; _ : 时间戳

返回数据(string):

显示二维码

<a href="https://login.weixin.qq.com/qrcode/%7buuid%7d">https://login.weixin.qq.com/qrcode/{uuid}</a>

post

t : webwx &lt;br/&gt; _ : 时间戳

&lt;br&gt;

二维码扫描登录

<a href="https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login">https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login</a>

tip : 1:未扫描 0:已扫描 &lt;br&gt; uuid : 获取到的uuid &lt;br&gt; _ : 时间戳

webwxnewloginpage

<a href="https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage">https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage</a>

ticket : xxx &lt;br&gt; uuid : xxx &lt;br&gt; lang : zh_cn &lt;br&gt; scan : xxx &lt;br&gt; fun : new

返回数据(xml):

在这一步获取xml中的 <code>skey</code>, <code>wxsid</code>, <code>wxuin</code>, <code>pass_ticket</code>

webwxinit

<a href="https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxinit">https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxinit</a>

json

header

content-type: application/json; charset=utf-8

{ &lt;br&gt;      baserequest: { &lt;br&gt;          uin: xxx, &lt;br&gt;          sid: xxx, &lt;br&gt;          skey: xxx, &lt;br&gt;          deviceid: xxx, &lt;br&gt;      } &lt;br&gt; }

返回数据(json):

这一步中获取 <code>synckey</code>, <code>user</code> 后面的消息监听用。

webwxstatusnotify

<a href="https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify">https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify</a>

{ &lt;br&gt;      baserequest: { uin: xxx, sid: xxx, skey: xxx, deviceid: xxx }, &lt;br&gt;      code: 3, &lt;br&gt;      fromusername: 自己的id, &lt;br&gt;      tousername: 自己的id, &lt;br&gt;      clientmsgid: 时间戳 &lt;br&gt; }

webwxgetcontact

<a href="https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact">https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact</a>

contenttype: application/json; charset=utf-8

synccheck

<a href="https://webpush2.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck">https://webpush2.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck</a>

webwxsync

<a href="https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=xxx&amp;skey=xxx&amp;pass_ticket=xxx">https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=xxx&amp;skey=xxx&amp;pass_ticket=xxx</a>

{ &lt;br&gt;      baserequest: { uin: xxx, sid: xxx, skey: xxx, deviceid: xxx }, &lt;br&gt;      synckey: xxx, &lt;br&gt;      rr: <code>时间戳取反</code> &lt;br&gt; }

webwxsendmsg

<a href="https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?pass_ticket=xxx">https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?pass_ticket=xxx</a>

{ &lt;br&gt;      baserequest: { uin: xxx, sid: xxx, skey: xxx, deviceid: xxx }, &lt;br&gt;      msg: { &lt;br&gt;          type: 1 文字消息, &lt;br&gt;          content: 要发送的消息, &lt;br&gt;          fromusername: 自己的id, &lt;br&gt;          tousername: 好友的id, &lt;br&gt;          localid: 与clientmsgid相同, &lt;br&gt;          clientmsgid: 时间戳左移4位随后补上4位随机数 &lt;br&gt;      } &lt;br&gt; }