diff --git a/README.md b/README.md index 79650fd9..6d3c0265 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,11 @@ pip3 install --upgrade openai ``` 注:`itchat-uos`使用指定版本1.5.0.dev0,`openai`使用最新版本,需高于0.27.0。 +**修复 itchat-uos bug** +··· +bash fix-itchat.sh +··· + **配置项说明:** @@ -475,3 +480,8 @@ pip3 install PyJWT flask 本地运行:`python3 app.py`运行后访问 `http://127.0.0.1:80` 服务器运行:部署后访问 `http://公网域名或IP:端口` + +**允许无密码访问** +``` +bash ./allow-http-nopassword.sh +``` diff --git a/allow-http-nopassword.sh b/allow-http-nopassword.sh new file mode 100644 index 00000000..7dcee0aa --- /dev/null +++ b/allow-http-nopassword.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -x + +# @see https://stackoverflow.com/questions/30003570/how-to-use-gnu-sed-on-mac-os-10-10-brew-install-default-names-no-longer-su +# @see https://www.cnblogs.com/fnlingnzb-learner/p/10657285.html +cmd=sed +if [ "$(uname)" == "Darwin" ];then + brew install gnu-sed + cmd=gsed +fi + +echo "current sed command is: $cmd" + +echo "allow http nopasword" +$cmd -i "s/\"http_auth_password\": \".*\"/\"http_auth_password\": \"\"/" config.json diff --git a/app.py b/app.py index d555e053..6a047a6d 100644 --- a/app.py +++ b/app.py @@ -3,12 +3,18 @@ import config from channel import channel_factory from common import log +import os if __name__ == '__main__': try: # load config config.load_config() + proxy = config.conf().get("model").get("openai").get("proxy") + if proxy: + os.environ['http_proxy'] = proxy + os.environ['https_proxy'] = proxy + model_type = config.conf().get("model").get("type") channel_type = config.conf().get("channel").get("type") diff --git a/channel/channel_factory.py b/channel/channel_factory.py index 186d4458..7b53e803 100644 --- a/channel/channel_factory.py +++ b/channel/channel_factory.py @@ -46,4 +46,4 @@ def create_channel(channel_type): return HttpChannel() else: - raise RuntimeError + raise RuntimeError("unknown channel_type in config.json: " + channel_type) diff --git a/channel/http/auth.py b/channel/http/auth.py index 67b2ec40..3e2756aa 100644 --- a/channel/http/auth.py +++ b/channel/http/auth.py @@ -83,6 +83,9 @@ def identify(request): :return: list """ try: + authPassword = channel_conf(const.HTTP).get('http_auth_password') + if (not authPassword): + return True if (request is None): return False authorization = request.cookies.get('Authorization') diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index f4a5585c..ac5cc2f1 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -40,11 +40,19 @@ def __init__(self): def startup(self): # login by scan QRCode - itchat.auto_login(enableCmdQR=2, hotReload=True) + if (channel_conf_val(const.WECHAT, 'receive_qrcode_api')): + itchat.auto_login(enableCmdQR=2, hotReload=True, qrCallback=self.login) + else: + itchat.auto_login(enableCmdQR=2, hotReload=True) # start message listener itchat.run() + def login(self, uuid=None, status='0', qrcode=None): + print('uuid:', uuid) + print('status:', status) + # 请将链接转发到外部接口,并在外部自行通过二维码生成库将链接转换为二维码后展示,例如:将下方的 qrcode_link 通过草料二维码进行处理后,再通过手机端扫码登录微信小号 + print('qrcode_link:', 'https://login.weixin.qq.com/l/'+uuid) def handle(self, msg): logger.debug("[WX]receive msg: " + json.dumps(msg, ensure_ascii=False)) diff --git a/config-template.json b/config-template.json index dba7214c..1517abbf 100644 --- a/config-template.json +++ b/config-template.json @@ -13,7 +13,7 @@ "cookie": "YOUR COOKIE" }, "bing":{ - "cookies":[] + "cookies":[] } }, "channel": { @@ -28,6 +28,7 @@ }, "wechat": { + "receive_qrcode_api": "" }, "wechat_mp": { diff --git a/fix-itchat.sh b/fix-itchat.sh new file mode 100755 index 00000000..3d02fe0c --- /dev/null +++ b/fix-itchat.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -x + +# @see https://stackoverflow.com/questions/30003570/how-to-use-gnu-sed-on-mac-os-10-10-brew-install-default-names-no-longer-su +# @see https://www.cnblogs.com/fnlingnzb-learner/p/10657285.html +cmd=sed +if [ "$(uname)" == "Darwin" ];then + brew install gnu-sed + cmd=gsed +fi + +echo "current sed command is: $cmd" + +pack_dir="$(pip3 show itchat-uos | grep "Location" | awk '{print $2}')" +file_name="${pack_dir}/itchat/components/login.py" + +sleep15Code="time.sleep(15)" + +cat $file_name | grep $sleep15Code + +if [ "$?" != "0" ];then + echo "fix $sleep15Code" + $cmd -i "/while not isLoggedIn/i\ $sleep15Code" $file_name +else + echo "already fix $sleep15Code" +fi + +sleep3Code="time.sleep(3)" + +cat $file_name | grep $sleep3Code + +if [ "$?" != "0" ];then + echo "fix $sleep3Code" + $cmd -i "s/elif status != '408'/elif status in ['408', '400']/" $file_name + $cmd -i "/if isLoggedIn:/i\ time.sleep(3)" $file_name +else + echo "already fix $sleep3Code" +fi