|
@@ -9,7 +9,7 @@ import urllib
|
|
|
import time
|
|
|
import re
|
|
|
import random
|
|
|
-import webbrowser
|
|
|
+from PIL import Image
|
|
|
from requests.exceptions import ConnectionError, ReadTimeout
|
|
|
import HTMLParser
|
|
|
|
|
@@ -676,12 +676,12 @@ class WXBot:
|
|
|
self.get_uuid()
|
|
|
self.gen_qr_code('qr.png')
|
|
|
print '[INFO] Please use WeChat to scan the QR code .'
|
|
|
-
|
|
|
+
|
|
|
result = self.wait4login()
|
|
|
if result != SUCCESS:
|
|
|
print '[ERROR] Web WeChat login failed. failed code=%s'%(result, )
|
|
|
return
|
|
|
-
|
|
|
+
|
|
|
if self.login():
|
|
|
print '[INFO] Web WeChat login succeed .'
|
|
|
else:
|
|
@@ -723,7 +723,8 @@ class WXBot:
|
|
|
qr = pyqrcode.create(string)
|
|
|
if self.conf['qr'] == 'png':
|
|
|
qr.png(qr_file_path, scale=8)
|
|
|
- webbrowser.open(qr_file_path)
|
|
|
+ img = Image.open(qr_file_path)
|
|
|
+ img.show()
|
|
|
elif self.conf['qr'] == 'tty':
|
|
|
print(qr.terminal(quiet_zone=1))
|
|
|
|
|
@@ -738,10 +739,10 @@ class WXBot:
|
|
|
def wait4login(self):
|
|
|
'''
|
|
|
http comet:
|
|
|
- tip=1, the request wait for user to scan the qr,
|
|
|
+ tip=1, the request wait for user to scan the qr,
|
|
|
201: scaned
|
|
|
408: timeout
|
|
|
- tip=0, the request wait for user confirm,
|
|
|
+ tip=0, the request wait for user confirm,
|
|
|
200: confirmed
|
|
|
'''
|
|
|
LOGIN_TEMPLATE = 'https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s'
|
|
@@ -749,9 +750,9 @@ class WXBot:
|
|
|
|
|
|
try_later_secs = 1
|
|
|
MAX_RETRY_TIMES = 10
|
|
|
-
|
|
|
+
|
|
|
code = UNKONWN
|
|
|
-
|
|
|
+
|
|
|
retry_time = MAX_RETRY_TIMES
|
|
|
while retry_time > 0:
|
|
|
url = LOGIN_TEMPLATE % (tip, self.uuid, int(time.time()))
|
|
@@ -772,12 +773,12 @@ class WXBot:
|
|
|
retry_time -= 1
|
|
|
time.sleep(try_later_secs)
|
|
|
else:
|
|
|
- print ('[ERROR] WeChat login exception return_code=%s. retry in %s secs later...' %
|
|
|
+ print ('[ERROR] WeChat login exception return_code=%s. retry in %s secs later...' %
|
|
|
(code, try_later_secs))
|
|
|
tip = 1
|
|
|
retry_time -= 1
|
|
|
time.sleep(try_later_secs)
|
|
|
-
|
|
|
+
|
|
|
return code
|
|
|
|
|
|
def login(self):
|