1
This commit is contained in:
@@ -26,7 +26,6 @@ const AdminPaymentConfig: React.FC = () => {
|
||||
wechat_private_key: map['payment_wechat_private_key'] || '',
|
||||
wechat_cert_serial_no: map['payment_wechat_cert_serial_no'] || '',
|
||||
wechat_api_v3_key: map['payment_wechat_api_v3_key'] || '',
|
||||
wechat_gateway: map['payment_wechat_gateway'] || '',
|
||||
wechat_notify_url: map['payment_wechat_notify_url'] || '',
|
||||
alipay_app_id: map['payment_alipay_app_id'] || '',
|
||||
alipay_private_key: map['payment_alipay_private_key'] || '',
|
||||
@@ -58,7 +57,6 @@ const AdminPaymentConfig: React.FC = () => {
|
||||
payment_wechat_private_key: values.wechat_private_key || '',
|
||||
payment_wechat_cert_serial_no: values.wechat_cert_serial_no || '',
|
||||
payment_wechat_api_v3_key: values.wechat_api_v3_key || '',
|
||||
payment_wechat_gateway: values.wechat_gateway || '',
|
||||
payment_wechat_notify_url: values.wechat_notify_url || '',
|
||||
payment_alipay_enabled: String(alipayEnabled),
|
||||
payment_alipay_app_id: values.alipay_app_id || '',
|
||||
@@ -168,9 +166,6 @@ const AdminPaymentConfig: React.FC = () => {
|
||||
<Form.Item name="wechat_api_v3_key" label="API v3 密钥">
|
||||
<Input.Password placeholder="API v3 密钥" size="large" disabled={!wechatEnabled} />
|
||||
</Form.Item>
|
||||
<Form.Item name="wechat_gateway" label="网关地址" extra="正式环境: https://api.mch.weixin.qq.com 沙箱环境(如适用)">
|
||||
<Input placeholder="https://api.mch.weixin.qq.com" size="large" disabled={!wechatEnabled} />
|
||||
</Form.Item>
|
||||
<Form.Item name="wechat_notify_url" label="回调地址" extra="用户支付成功后,微信会主动通知此地址,服务器收到通知后给用户加积分">
|
||||
<Input placeholder="https://yourdomain.com/api/payments/wechat/callback" size="large" disabled={!wechatEnabled} />
|
||||
</Form.Item>
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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": "微信支付客户端初始化失败"}
|
||||
|
||||
|
||||
@@ -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__))
|
||||
Reference in New Issue
Block a user