This commit is contained in:
2026-06-11 18:28:17 +08:00
parent bb5116ffd6
commit a637fdf213
4 changed files with 18 additions and 17 deletions
+1 -2
View File
@@ -112,9 +112,8 @@ async def wechat_callback(request: Request, db: AsyncSession = Depends(get_db)):
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
appid = db_configs.get("payment_wechat_appid", "")
gateway = db_configs.get("payment_wechat_gateway", "")
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid)
if not client:
logger.error("WeChat client not initialized for callback")
return {"code": "SUCCESS", "message": "OK"}
+8 -10
View File
@@ -357,7 +357,8 @@ def _get_wechat_client(
cert_serial_no: str,
api_v3_key: str,
appid: str,
gateway: str = ""
notify_url: str = "",
cert_dir: str | None = None
):
"""Get or create a WeChat Pay client. Recreated if config changes."""
global _wechat_client, _wechat_mch_id
@@ -388,7 +389,8 @@ def _get_wechat_client(
cert_serial_no=cert_serial_no,
appid=appid,
apiv3_key=api_v3_key,
gateway=gateway or "https://api.mch.weixin.qq.com",
notify_url=notify_url,
cert_dir=cert_dir,
)
_wechat_mch_id = mch_id
logger.info("WeChat Pay client initialized successfully")
@@ -411,14 +413,13 @@ def _create_wechat_order(order: PaymentOrder, db_configs: dict[str, str]) -> str
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
appid = db_configs.get("payment_wechat_appid", "")
gateway = db_configs.get("payment_wechat_gateway", "")
notify_url = db_configs.get("payment_wechat_notify_url", "")
if not all([mch_id, private_key, cert_serial_no, api_v3_key, appid]):
logger.warning("WeChat payment config missing in database")
return None
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, notify_url)
if client is None:
return None
@@ -461,9 +462,8 @@ async def _close_wechat_order(db: AsyncSession, order: PaymentOrder, db_configs:
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
appid = db_configs.get("payment_wechat_appid", "")
gateway = db_configs.get("payment_wechat_gateway", "")
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid)
if client is None:
return False
@@ -494,9 +494,8 @@ async def _query_wechat_order(db: AsyncSession, order: PaymentOrder, db_configs:
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
appid = db_configs.get("payment_wechat_appid", "")
gateway = db_configs.get("payment_wechat_gateway", "")
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid)
if client is None:
return None
@@ -537,9 +536,8 @@ async def _refund_wechat_order(
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
appid = db_configs.get("payment_wechat_appid", "")
gateway = db_configs.get("payment_wechat_gateway", "")
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid)
if client is None:
return {"success": False, "message": "微信支付客户端初始化失败"}
+9
View File
@@ -0,0 +1,9 @@
from wechatpayv3 import WeChatPay
import inspect
print("WeChatPay.__init__ signature:")
print(inspect.signature(WeChatPay.__init__))
print("\nWeChatPay.__init__ docstring:")
print(inspect.getdoc(WeChatPay.__init__))