Skip to content

Commit

Permalink
Merge pull request liuwons#147 from vivre90/patch-1
Browse files Browse the repository at this point in the history
更新心跳服务器获取方式,同时修复文件可能上传失败的问题! 在返回-1,-1时降低心跳获取频率!
  • Loading branch information
liuwons authored Oct 26, 2016
2 parents cda1b6d + bb44aca commit 181dee1
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions wxbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self):
self.DEBUG = False
self.uuid = ''
self.base_uri = ''
self.base_host = ''
self.redirect_uri = ''
self.uin = ''
self.sid = ''
Expand Down Expand Up @@ -641,6 +642,7 @@ def proc_msg(self):
self.handle_msg(r)
else:
print '[DEBUG] sync_check:', retcode, selector
time.sleep(10)
self.schedule()
except:
print '[ERROR] Except in proc_msg'
Expand Down Expand Up @@ -814,8 +816,8 @@ def upload_media(self, fpath, is_img=False):
if not os.path.exists(fpath):
print '[ERROR] File not exists.'
return None
url_1 = 'https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
url_2 = 'https://file2.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
url_1 = 'https://file.'+self.base_host+'/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
url_2 = 'https://file2.'+self.base_host+'/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
flen = str(os.path.getsize(fpath))
ftype = mimetypes.guess_type(fpath)[0] or 'application/octet-stream'
files = {
Expand Down Expand Up @@ -1057,6 +1059,8 @@ def wait4login(self):
redirect_uri = param.group(1) + '&fun=new'
self.redirect_uri = redirect_uri
self.base_uri = redirect_uri[:redirect_uri.rfind('/')]
temp_host = self.base_uri[8:]
self.base_host = temp_host[:host2.find("/")]
return code
elif code == TIMEOUT:
print '[ERROR] WeChat login timeout. retry in %s secs later...' % (try_later_secs,)
Expand Down Expand Up @@ -1135,14 +1139,13 @@ def status_notify(self):

def test_sync_check(self):
for host1 in ['webpush.', 'webpush2.']:
for host2 in ['weixin','weixin2','wx','wx2']:
self.sync_host = host1+host2
try:
retcode = self.sync_check()[0]
except:
retcode = -1
if retcode == '0':
return True
self.sync_host = host1+self.base_host
try:
retcode = self.sync_check()[0]
except:
retcode = -1
if retcode == '0':
return True
return False

def sync_check(self):
Expand All @@ -1155,7 +1158,7 @@ def sync_check(self):
'synckey': self.sync_key_str,
'_': int(time.time()),
}
url = 'https://' + self.sync_host + '.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params)
url = 'https://' + self.sync_host + '/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params)
try:
r = self.session.get(url, timeout=60)
r.encoding = 'utf-8'
Expand Down

0 comments on commit 181dee1

Please sign in to comment.