From 86fb8be1a5640bf14ef23cde900d570c24ea2eed Mon Sep 17 00:00:00 2001 From: sharpdeep <1713715949@qq.com> Date: Tue, 16 Feb 2016 14:30:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwin=E4=B8=8BCMD=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=89=93=E5=8D=B0=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98,=E4=B8=BAUnicodeStreamFilter=E9=87=8D?= =?UTF-8?q?=E5=86=99flush=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/weixin.py b/weixin.py index 49a1eef..723ab2e 100755 --- a/weixin.py +++ b/weixin.py @@ -101,7 +101,24 @@ class WebWeixin(object): return False def genQRCode(self): - self._str2qr('https://login.weixin.qq.com/l/' + self.uuid) + if sys.platform.find('win') >= 0: + self._showQRCodeImg() + else: + self._str2qr('https://login.weixin.qq.com/l/' + self.uuid) + + def _showQRCodeImg(self): + QRCODE_PATH = os.path.join(os.getcwd(),'qrcode.jpg') + url = 'https://login.weixin.qq.com/qrcode/' + self.uuid + params = { + 't' : 'webwx', + '_' : int(time.time()) + } + + data = self._post(url,params,False) + with open(QRCODE_PATH, 'wb') as f: + f.write(data) + + os.startfile(QRCODE_PATH) def waitForLogin(self, tip = 1): time.sleep(tip) @@ -589,6 +606,9 @@ class UnicodeStreamFilter: s = s.encode(self.encode_to, self.errors).decode(self.encode_to) self.target.write(s) + def flush(self): + self.target.flush() + if __name__ == '__main__': if sys.stdout.encoding == 'cp936': sys.stdout = UnicodeStreamFilter(sys.stdout) From ae5a5076de8196f86c59c4128363994424719876 Mon Sep 17 00:00:00 2001 From: sharpdeep <1713715949@qq.com> Date: Tue, 16 Feb 2016 15:06:11 +0800 Subject: [PATCH 2/2] bugfix:fix ListenMsgMode process encoding problem --- weixin.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/weixin.py b/weixin.py index 723ab2e..ea1172c 100755 --- a/weixin.py +++ b/weixin.py @@ -232,8 +232,8 @@ class WebWeixin(object): 'webpush.wechat.com', 'webpush1.wechat.com', 'webpush2.wechat.com', - 'webpush.wechatapp.com', - 'webpush1.wechatapp.com' + 'webpush1.wechatapp.com', + # 'webpush.wechatapp.com' ] for host in SyncHost: self.syncHost = host @@ -501,7 +501,8 @@ class WebWeixin(object): text = raw_input('') if text == 'quit': listenProcess.terminate() - exit('[*] 退出微信') + print('[*] 退出微信') + exit() elif text[:2] == '->': [name, word] = text[2:].split(':') if name == 'all': self.sendMsgToAll(word) @@ -523,7 +524,7 @@ class WebWeixin(object): def _run(self, str, func, *args): self._echo(str) if func(*args): print '成功' - else: exit('失败\n[*] 退出程序') + else: print('失败\n[*] 退出程序');exit() def _echo(self, str): sys.stdout.write(str) @@ -609,9 +610,10 @@ class UnicodeStreamFilter: def flush(self): self.target.flush() -if __name__ == '__main__': - if sys.stdout.encoding == 'cp936': - sys.stdout = UnicodeStreamFilter(sys.stdout) +if sys.stdout.encoding == 'cp936': + sys.stdout = UnicodeStreamFilter(sys.stdout) + +if __name__ == '__main__': webwx = WebWeixin() webwx.start()