@@ -62,6 +62,7 @@ def __init__(self):
6262 self .DEBUG = False
6363 self .uuid = ''
6464 self .base_uri = ''
65+ self .base_host = ''
6566 self .redirect_uri = ''
6667 self .uin = ''
6768 self .sid = ''
@@ -641,6 +642,7 @@ def proc_msg(self):
641642 self .handle_msg (r )
642643 else :
643644 print '[DEBUG] sync_check:' , retcode , selector
645+ time .sleep (10 )
644646 self .schedule ()
645647 except :
646648 print '[ERROR] Except in proc_msg'
@@ -814,8 +816,8 @@ def upload_media(self, fpath, is_img=False):
814816 if not os .path .exists (fpath ):
815817 print '[ERROR] File not exists.'
816818 return None
817- url_1 = 'https://file.wx2.qq.com /cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
818- url_2 = 'https://file2.wx2.qq.com /cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
819+ url_1 = 'https://file.' + self . base_host + ' /cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
820+ url_2 = 'https://file2.' + self . base_host + ' /cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'
819821 flen = str (os .path .getsize (fpath ))
820822 ftype = mimetypes .guess_type (fpath )[0 ] or 'application/octet-stream'
821823 files = {
@@ -1057,6 +1059,8 @@ def wait4login(self):
10571059 redirect_uri = param .group (1 ) + '&fun=new'
10581060 self .redirect_uri = redirect_uri
10591061 self .base_uri = redirect_uri [:redirect_uri .rfind ('/' )]
1062+ temp_host = self .base_uri [8 :]
1063+ self .base_host = temp_host [:host2 .find ("/" )]
10601064 return code
10611065 elif code == TIMEOUT :
10621066 print '[ERROR] WeChat login timeout. retry in %s secs later...' % (try_later_secs ,)
@@ -1135,14 +1139,13 @@ def status_notify(self):
11351139
11361140 def test_sync_check (self ):
11371141 for host1 in ['webpush.' , 'webpush2.' ]:
1138- for host2 in ['weixin' ,'weixin2' ,'wx' ,'wx2' ]:
1139- self .sync_host = host1 + host2
1140- try :
1141- retcode = self .sync_check ()[0 ]
1142- except :
1143- retcode = - 1
1144- if retcode == '0' :
1145- return True
1142+ self .sync_host = host1 + self .base_host
1143+ try :
1144+ retcode = self .sync_check ()[0 ]
1145+ except :
1146+ retcode = - 1
1147+ if retcode == '0' :
1148+ return True
11461149 return False
11471150
11481151 def sync_check (self ):
@@ -1155,7 +1158,7 @@ def sync_check(self):
11551158 'synckey' : self .sync_key_str ,
11561159 '_' : int (time .time ()),
11571160 }
1158- url = 'https://' + self .sync_host + '.qq.com /cgi-bin/mmwebwx-bin/synccheck?' + urllib .urlencode (params )
1161+ url = 'https://' + self .sync_host + '/cgi-bin/mmwebwx-bin/synccheck?' + urllib .urlencode (params )
11591162 try :
11601163 r = self .session .get (url , timeout = 60 )
11611164 r .encoding = 'utf-8'
0 commit comments