diff --git a/app/api/routers/auth.py b/app/api/routers/auth.py index 7fbc107..4ef7a74 100644 --- a/app/api/routers/auth.py +++ b/app/api/routers/auth.py @@ -743,10 +743,11 @@ async def mp_qr_start(request: Request, db: Database = Depends(get_db)): png = await wechat.get_wxacode(scene, page="pages/scan-login/index") b64 = base64.b64encode(png).decode("ascii") return {"scene": scene, "qr_image": f"data:image/png;base64,{b64}", "mp_enabled": True, "expires_in": wx_qr_store.TTL_SECONDS} - except wechat.WechatError: + except wechat.WechatError as exc: # 无凭据/失败兜底:返回可扫描的 URL,前端按 qr_url 渲染普通二维码 + # 同时返回错误详情,便于排查(服务器缺少 WECHAT_APPID/SECRET 或微信API调用失败) qr_url = f"https://opc.pinesound.cn/mp/login?scene={scene}" - return {"scene": scene, "qr_url": qr_url, "mp_enabled": False, "expires_in": wx_qr_store.TTL_SECONDS} + return {"scene": scene, "qr_url": qr_url, "mp_enabled": False, "error": str(exc), "expires_in": wx_qr_store.TTL_SECONDS} @router.get("/mp-qr/poll", summary="轮询小程序扫码登录状态") @@ -773,9 +774,9 @@ async def mp_qr_bind_start(request: Request, db: Database = Depends(get_db), use png = await wechat.get_wxacode(scene, page="pages/scan-login/index") b64 = base64.b64encode(png).decode("ascii") return {"scene": scene, "qr_image": f"data:image/png;base64,{b64}", "mp_enabled": True, "expires_in": wx_qr_store.TTL_SECONDS} - except wechat.WechatError: + except wechat.WechatError as exc: qr_url = f"https://opc.pinesound.cn/mp/bind?scene={scene}" - return {"scene": scene, "qr_url": qr_url, "mp_enabled": False, "expires_in": wx_qr_store.TTL_SECONDS} + return {"scene": scene, "qr_url": qr_url, "mp_enabled": False, "error": str(exc), "expires_in": wx_qr_store.TTL_SECONDS} @router.post("/mp-qr/confirm", summary="小程序内确认扫码登录/绑定")