Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【已实现,见下方结论与代码】qrcode 能否发送到指定的地址。方便将应用容器化,并通过外部进行扫码登录。 #137

Open
mouyong opened this issue Mar 15, 2023 · 16 comments

Comments

@mouyong
Copy link
Contributor

mouyong commented Mar 15, 2023

littlecodersh/ItChat#686

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

增加一个配置项,然后设置 http 地址。然后登录的时候把二维码数据发给接口。接口保存数据。前端直接通过 api 显示二维码,就可以完成显示

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

qrCallback 的第一个参数是 uuid, 第三个参数是二维码数据。

可以通过 第一个参数完成二维码的获取:'https://login.weixin.qq.com/l/' + uuid

https://github.com/littlecodersh/ItChat/blob/master/itchat/components/login.py#L116

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

    def startup(self):
        # login by scan QRCode
        itchat.auto_login(enableCmdQR=2, hotReload=False, qrCallback=self.login)

        # start message listener
        itchat.run()

    def login(self, uuid=None, status='0', qrcode=None):
        print('https://login.weixin.qq.com/l/'+uuid)
        print(uuid, status)
        print(qrcode)

image

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

image

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

不知道 uuid 的url怎么变成二维码的。

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

通过将链接给草料二维码进行生成后,扫码登录,不知道为什么会400.二维码生成的时候和扫码时的uuid是对应的。

image

image

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

image

check 又是200

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

Log in time out, reloading QR code.

https://github.com/littlecodersh/ItChat/blob/master/itchat/components/login.py#L51-L67

看起来是这里的bug

image

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

解决了 408 状态码导致重新加载了二维码的原因。

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

登录时一直刷新二维码: littlecodersh/ItChat#983
408 状态码导致重新加载了二维码: littlecodersh/ItChat#829

@mouyong
Copy link
Contributor Author

mouyong commented Mar 15, 2023

最终代码:

config.json

"wechat": {
    "receive_qrcode_api": ""
}

channel/wechat/wechat_channel.py

...
class WechatChannel(Channel):
    def __init__(self):
        pass

    def startup(self):
        # login by scan QRCode
        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)
        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))
        ...

外部 api 接收到 url 后,需要将 url 转成二维码,再进行渲染展示。然后手机端再去扫码。
需要同步修改 itchat 的代码:echo pip3 show itchat-uos | grep "Location" | awk '{print $2}'/itchat/components/login.py

修改说明:littlecodersh/ItChat#983

@zhayujie 考虑集成到代码中不?

@mouyong mouyong changed the title qrcode 能否发送到指定的地址。方便讲应用容器化,并通过外部进行扫码登录。 qrcode 能否发送到指定的地址。方便将应用容器化,并通过外部进行扫码登录。 Mar 15, 2023
@Qzm6826
Copy link

Qzm6826 commented Mar 15, 2023

thanks

@mouyong mouyong changed the title qrcode 能否发送到指定的地址。方便将应用容器化,并通过外部进行扫码登录。 【已实现,见下方结论与代码】qrcode 能否发送到指定的地址。方便将应用容器化,并通过外部进行扫码登录。 Mar 15, 2023
@zhayujie
Copy link
Owner

@mouyong 很好的修改, 但现在itchat不接受合并了,比较麻烦

@mouyong
Copy link
Contributor Author

mouyong commented Mar 18, 2023

写个 shell 脚本,通过 sed 操作,放在 bot-on-anything 里面就可以啦。

@mouyong
Copy link
Contributor Author

mouyong commented Mar 18, 2023

启动项目的时候,先执行一下这个脚本。完成 itchat 的修改

@mouyong
Copy link
Contributor Author

mouyong commented Mar 18, 2023

我给你增加。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants