|
@@ -64,6 +64,21 @@ def _check(func): |
|
|
return func(self, cmsg) |
|
|
return func(self, cmsg) |
|
|
return wrapper |
|
|
return wrapper |
|
|
|
|
|
|
|
|
|
|
|
#可用的二维码生成接口 |
|
|
|
|
|
#https://api.qrserver.com/v1/create-qr-code/?size=400×400&data=https://www.abc.com |
|
|
|
|
|
#https://api.isoyu.com/qr/?m=1&e=L&p=20&url=https://www.abc.com |
|
|
|
|
|
def qrCallback(uuid,status,qrcode): |
|
|
|
|
|
# logger.debug("qrCallback: {} {}".format(uuid,status)) |
|
|
|
|
|
if status == '0': |
|
|
|
|
|
import qrcode |
|
|
|
|
|
url = f"https://login.weixin.qq.com/l/{uuid}" |
|
|
|
|
|
qr = qrcode.QRCode(border=1) |
|
|
|
|
|
qr.add_data(url) |
|
|
|
|
|
qr.make(fit=True) |
|
|
|
|
|
qr.print_ascii(invert=True) |
|
|
|
|
|
|
|
|
|
|
|
qr_api="https://api.isoyu.com/qr/?m=1&e=L&p=20&url={}".format(url) |
|
|
|
|
|
print("You can also scan QRCode in website below:\n{}".format(qr_api)) |
|
|
@singleton |
|
|
@singleton |
|
|
class WechatChannel(ChatChannel): |
|
|
class WechatChannel(ChatChannel): |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
@@ -76,13 +91,13 @@ class WechatChannel(ChatChannel): |
|
|
# login by scan QRCode |
|
|
# login by scan QRCode |
|
|
hotReload = conf().get('hot_reload', False) |
|
|
hotReload = conf().get('hot_reload', False) |
|
|
try: |
|
|
try: |
|
|
itchat.auto_login(enableCmdQR=2, hotReload=hotReload) |
|
|
|
|
|
|
|
|
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback) |
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
if hotReload: |
|
|
if hotReload: |
|
|
logger.error("Hot reload failed, try to login without hot reload") |
|
|
logger.error("Hot reload failed, try to login without hot reload") |
|
|
itchat.logout() |
|
|
itchat.logout() |
|
|
os.remove("itchat.pkl") |
|
|
os.remove("itchat.pkl") |
|
|
itchat.auto_login(enableCmdQR=2, hotReload=hotReload) |
|
|
|
|
|
|
|
|
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback) |
|
|
else: |
|
|
else: |
|
|
raise e |
|
|
raise e |
|
|
self.user_id = itchat.instance.storageClass.userName |
|
|
self.user_id = itchat.instance.storageClass.userName |
|
|