浏览代码

feat: new itchat qrcode generator

master
lanvent 1年前
父节点
当前提交
e71c600d10
共有 4 个文件被更改,包括 19 次插入5 次删除
  1. +17
    -2
      channel/wechat/wechat_channel.py
  2. +1
    -1
      docker/build.latest.sh
  3. +1
    -0
      requirements.txt
  4. +0
    -2
      voice/azure/azure_voice.py

+ 17
- 2
channel/wechat/wechat_channel.py 查看文件

@@ -64,6 +64,21 @@ def _check(func):
return func(self, cmsg)
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
class WechatChannel(ChatChannel):
def __init__(self):
@@ -76,13 +91,13 @@ class WechatChannel(ChatChannel):
# login by scan QRCode
hotReload = conf().get('hot_reload', False)
try:
itchat.auto_login(enableCmdQR=2, hotReload=hotReload)
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback)
except Exception as e:
if hotReload:
logger.error("Hot reload failed, try to login without hot reload")
itchat.logout()
os.remove("itchat.pkl")
itchat.auto_login(enableCmdQR=2, hotReload=hotReload)
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback)
else:
raise e
self.user_id = itchat.instance.storageClass.userName


+ 1
- 1
docker/build.latest.sh 查看文件

@@ -1,4 +1,4 @@
#!/bin/bash

cd .. && docker build -f Dockerfile \
cd .. && docker build -f docker/Dockerfile.latest \
-t zhayujie/chatgpt-on-wechat .

+ 1
- 0
requirements.txt 查看文件

@@ -7,6 +7,7 @@ PyQRCode>=1.2.1
pysilk>=0.0.1
pysilk_mod>=1.6.0
pyttsx3>=2.90
qrcode>=7.4.2
requests>=2.28.2
webuiapi>=0.6.2
wechaty>=0.10.7


+ 0
- 2
voice/azure/azure_voice.py 查看文件

@@ -6,12 +6,10 @@ import json
import os
import time
import azure.cognitiveservices.speech as speechsdk
from aip import AipSpeech
from bridge.reply import Reply, ReplyType
from common.log import logger
from common.tmp_dir import TmpDir
from voice.voice import Voice
from voice.audio_convert import get_pcm_from_wav
from config import conf
"""
Azure voice


正在加载...
取消
保存