From 950f86325aa73ab1abeee27c4503a491d93b1313 Mon Sep 17 00:00:00 2001 From: WorkBuddy Date: Thu, 9 Jul 2026 21:29:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=AA=E4=BA=BA=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=94=B9=E4=B8=BA=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9C=9F=E6=AD=A3=E5=8F=AF=E6=89=AB=E7=9A=84?= =?UTF-8?q?=20PNG(=E5=89=8D=E7=AB=AF=20=20=E5=8E=9F=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=20HTML=20URL=20=E5=A4=B1=E6=95=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/python/app/api/im_bot_user.py | 17 ++++++++++++++++- frontend/src/pages/front/WechatBot.tsx | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/python/app/api/im_bot_user.py b/backend/python/app/api/im_bot_user.py index d0e86b3..b51826d 100644 --- a/backend/python/app/api/im_bot_user.py +++ b/backend/python/app/api/im_bot_user.py @@ -249,9 +249,24 @@ async def wechat_qrcode(user: User = Depends(get_current_user)): if not resp.ok: return {"success": False, "error": f"获取二维码失败 HTTP {resp.status_code}"} j = resp.json() if resp.content else {} + qr_url = j.get("qrcode_img_content") or "" + qr_img = None + try: + import io as _io + import qrcode as _qrcode + _buf = _io.BytesIO() + _q = _qrcode.QRCode(box_size=10, border=2) + _q.add_data(qr_url) + _q.make(fit=True) + _img = _q.make_image(fill_color="black", back_color="white") + _img.save(_buf, format="PNG") + qr_img = "data:image/png;base64," + base64.b64encode(_buf.getvalue()).decode() + except Exception: + qr_img = None return {"success": True, "data": { "qrcode": j.get("qrcode"), - "qrcode_img_content": j.get("qrcode_img_content"), + "qrcode_img_content": qr_url, + "qrcode_img": qr_img, }} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) diff --git a/frontend/src/pages/front/WechatBot.tsx b/frontend/src/pages/front/WechatBot.tsx index e7b0d08..6df4391 100644 --- a/frontend/src/pages/front/WechatBot.tsx +++ b/frontend/src/pages/front/WechatBot.tsx @@ -146,11 +146,11 @@ const WechatBot: React.FC = () => { ) : (
- {qrcode.qrcode_img_content ? ( - 微信扫码 + {qrcode.qrcode_img ? ( + 微信扫码 ) : (
- 二维码数据缺失,请重新获取。 + 二维码图片生成失败,请点击此处在新标签页打开。
)}