From 9d1278cb33b36f4cb873f9d9e917b815f477c27f Mon Sep 17 00:00:00 2001 From: marco Date: Sun, 31 May 2026 17:10:16 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B8=85=E7=90=86=E4=B8=A4=E5=A4=84?= =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - app/db/base.py: 删 MappedAsDataclass 的 import (没人继承用) - app/integrations/wxpay.py: 删 code_to_openid 函数 (code_to_userinfo 已覆盖能力, 18 行死代码) --- app/db/base.py | 2 +- app/integrations/wxpay.py | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/app/db/base.py b/app/db/base.py index f2696ab..d62f6c5 100644 --- a/app/db/base.py +++ b/app/db/base.py @@ -4,7 +4,7 @@ """ from __future__ import annotations -from sqlalchemy.orm import DeclarativeBase, MappedAsDataclass +from sqlalchemy.orm import DeclarativeBase class Base(DeclarativeBase): diff --git a/app/integrations/wxpay.py b/app/integrations/wxpay.py index 8c66f24..d52be17 100644 --- a/app/integrations/wxpay.py +++ b/app/integrations/wxpay.py @@ -162,24 +162,6 @@ def cancel_transfer(out_bill_no: str) -> dict: return {"status_code": resp.status_code, "data": resp.json()} -def code_to_openid(code: str) -> str: - """用微信授权 code 换 openid(开放平台移动应用 sns/oauth2)。失败抛 ValueError。""" - resp = httpx.get( - "https://api.weixin.qq.com/sns/oauth2/access_token", - params={ - "appid": settings.WECHAT_APP_ID, - "secret": settings.WECHAT_APP_SECRET, - "code": code, - "grant_type": "authorization_code", - }, - timeout=settings.WXPAY_REQUEST_TIMEOUT_SEC, - ) - data = resp.json() - if "openid" not in data: - raise ValueError(f"微信授权失败: {data.get('errmsg', data)}") - return data["openid"] - - def code_to_userinfo(code: str) -> dict: """code 换 access_token+openid,再拉 sns/userinfo 取昵称头像。 返回 {openid, nickname, avatar_url, raw}。失败抛 ValueError。