diff --git a/README.md b/README.md index 296b453..f3a3162 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,7 @@ window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?tic | API | synccheck | | --- | --------- | -| url | https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck | +| url | https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck or
https://webpush2.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck | | method | GET | | data | URL Encode | | params | **r**: `时间戳`
**sid**: xxx
**uin**: xxx
**skey**: xxx
**deviceid**: xxx
**synckey**: xxx
**_**: `时间戳` | @@ -296,7 +296,7 @@ window.synccheck={retcode:"xxx",selector:"xxx"} retcode: 0 正常 - 1100 登出微信 + 1100 失败/登出微信 selector: 0 正常 2 新的消息 diff --git a/weixin.py b/weixin.py index 6b8d7a9..0db7c21 100755 --- a/weixin.py +++ b/weixin.py @@ -50,6 +50,7 @@ class WebWeixin(object): self.ContactList = [] self.GroupList = [] self.autoReplyMode = False + self.syncHost = '' opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) urllib2.install_opener(opener) @@ -179,6 +180,13 @@ class WebWeixin(object): # blabla ... return True + def testsynccheck(self): + for host in ['webpush', 'webpush2']: + self.syncHost = host + [retcode, selector] = self.synccheck() + if retcode == '0': return True + return False + def synccheck(self): params = { 'r': int(time.time()), @@ -189,7 +197,7 @@ class WebWeixin(object): 'synckey': self.synckey, '_': int(time.time()), } - url = 'https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) + url = 'https://' + self.syncHost + '.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) data = self._get(url) pm = re.search(r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}', data) retcode = pm.group(1) @@ -304,6 +312,7 @@ class WebWeixin(object): def listenMsgMode(self): print '[*] 进入消息监听模式 ... 成功' + self._run('[*] 进行同步线路测试 ... ', self.testsynccheck) playWeChat = 0 while True: [retcode, selector] = self.synccheck()