1
This commit is contained in:
@@ -111,9 +111,10 @@ async def wechat_callback(request: Request, db: AsyncSession = Depends(get_db)):
|
||||
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||
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, gateway)
|
||||
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
|
||||
if not client:
|
||||
logger.error("WeChat client not initialized for callback")
|
||||
return {"code": "SUCCESS", "message": "OK"}
|
||||
|
||||
@@ -280,6 +280,7 @@ async def create_recharge_order(
|
||||
raise ValueError("支付宝支付未完成配置,请联系管理员")
|
||||
elif method == "wechat":
|
||||
required_configs = [
|
||||
"payment_wechat_appid",
|
||||
"payment_wechat_mch_id",
|
||||
"payment_wechat_private_key",
|
||||
"payment_wechat_cert_serial_no",
|
||||
@@ -355,6 +356,7 @@ def _get_wechat_client(
|
||||
private_key: str,
|
||||
cert_serial_no: str,
|
||||
api_v3_key: str,
|
||||
appid: str,
|
||||
gateway: str = ""
|
||||
):
|
||||
"""Get or create a WeChat Pay client. Recreated if config changes."""
|
||||
@@ -384,7 +386,8 @@ def _get_wechat_client(
|
||||
mchid=mch_id,
|
||||
private_key=private_key_str,
|
||||
cert_serial_no=cert_serial_no,
|
||||
apiv3_private_key=api_v3_key,
|
||||
appid=appid,
|
||||
apiv3_key=api_v3_key,
|
||||
gateway=gateway or "https://api.mch.weixin.qq.com",
|
||||
)
|
||||
_wechat_mch_id = mch_id
|
||||
@@ -407,14 +410,15 @@ def _create_wechat_order(order: PaymentOrder, db_configs: dict[str, str]) -> str
|
||||
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||
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]):
|
||||
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, gateway)
|
||||
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
|
||||
if client is None:
|
||||
return None
|
||||
|
||||
@@ -456,9 +460,10 @@ async def _close_wechat_order(db: AsyncSession, order: PaymentOrder, db_configs:
|
||||
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||
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, gateway)
|
||||
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
|
||||
if client is None:
|
||||
return False
|
||||
|
||||
@@ -488,9 +493,10 @@ async def _query_wechat_order(db: AsyncSession, order: PaymentOrder, db_configs:
|
||||
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||
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, gateway)
|
||||
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
|
||||
if client is None:
|
||||
return None
|
||||
|
||||
@@ -530,9 +536,10 @@ async def _refund_wechat_order(
|
||||
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||
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, gateway)
|
||||
client = _get_wechat_client(mch_id, private_key, cert_serial_no, api_v3_key, appid, gateway)
|
||||
if client is None:
|
||||
return {"success": False, "message": "微信支付客户端初始化失败"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user