1
This commit is contained in:
@@ -21,6 +21,7 @@ const AdminPaymentConfig: React.FC = () => {
|
|||||||
const map: Record<string, string> = {};
|
const map: Record<string, string> = {};
|
||||||
data.forEach((c: any) => { map[c.key] = c.value; });
|
data.forEach((c: any) => { map[c.key] = c.value; });
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
|
wechat_appid: map['payment_wechat_appid'] || '',
|
||||||
wechat_mch_id: map['payment_wechat_mch_id'] || '',
|
wechat_mch_id: map['payment_wechat_mch_id'] || '',
|
||||||
wechat_private_key: map['payment_wechat_private_key'] || '',
|
wechat_private_key: map['payment_wechat_private_key'] || '',
|
||||||
wechat_cert_serial_no: map['payment_wechat_cert_serial_no'] || '',
|
wechat_cert_serial_no: map['payment_wechat_cert_serial_no'] || '',
|
||||||
@@ -52,6 +53,7 @@ const AdminPaymentConfig: React.FC = () => {
|
|||||||
await batchUpdatePaymentConfigs({
|
await batchUpdatePaymentConfigs({
|
||||||
payment_mock: String(mockMode),
|
payment_mock: String(mockMode),
|
||||||
payment_wechat_enabled: String(wechatEnabled),
|
payment_wechat_enabled: String(wechatEnabled),
|
||||||
|
payment_wechat_appid: values.wechat_appid || '',
|
||||||
payment_wechat_mch_id: values.wechat_mch_id || '',
|
payment_wechat_mch_id: values.wechat_mch_id || '',
|
||||||
payment_wechat_private_key: values.wechat_private_key || '',
|
payment_wechat_private_key: values.wechat_private_key || '',
|
||||||
payment_wechat_cert_serial_no: values.wechat_cert_serial_no || '',
|
payment_wechat_cert_serial_no: values.wechat_cert_serial_no || '',
|
||||||
@@ -151,6 +153,9 @@ const AdminPaymentConfig: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Form form={form} layout="vertical">
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="wechat_appid" label="AppID">
|
||||||
|
<Input placeholder="微信支付 AppID" size="large" disabled={!wechatEnabled} />
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="wechat_mch_id" label="商户号 (MchID)">
|
<Form.Item name="wechat_mch_id" label="商户号 (MchID)">
|
||||||
<Input placeholder="微信支付商户号" size="large" disabled={!wechatEnabled} />
|
<Input placeholder="微信支付商户号" size="large" disabled={!wechatEnabled} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
@@ -111,9 +111,10 @@ async def wechat_callback(request: Request, db: AsyncSession = Depends(get_db)):
|
|||||||
private_key = db_configs.get("payment_wechat_private_key", "")
|
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||||
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
||||||
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
|
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", "")
|
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:
|
if not client:
|
||||||
logger.error("WeChat client not initialized for callback")
|
logger.error("WeChat client not initialized for callback")
|
||||||
return {"code": "SUCCESS", "message": "OK"}
|
return {"code": "SUCCESS", "message": "OK"}
|
||||||
|
|||||||
@@ -280,6 +280,7 @@ async def create_recharge_order(
|
|||||||
raise ValueError("支付宝支付未完成配置,请联系管理员")
|
raise ValueError("支付宝支付未完成配置,请联系管理员")
|
||||||
elif method == "wechat":
|
elif method == "wechat":
|
||||||
required_configs = [
|
required_configs = [
|
||||||
|
"payment_wechat_appid",
|
||||||
"payment_wechat_mch_id",
|
"payment_wechat_mch_id",
|
||||||
"payment_wechat_private_key",
|
"payment_wechat_private_key",
|
||||||
"payment_wechat_cert_serial_no",
|
"payment_wechat_cert_serial_no",
|
||||||
@@ -355,6 +356,7 @@ def _get_wechat_client(
|
|||||||
private_key: str,
|
private_key: str,
|
||||||
cert_serial_no: str,
|
cert_serial_no: str,
|
||||||
api_v3_key: str,
|
api_v3_key: str,
|
||||||
|
appid: str,
|
||||||
gateway: str = ""
|
gateway: str = ""
|
||||||
):
|
):
|
||||||
"""Get or create a WeChat Pay client. Recreated if config changes."""
|
"""Get or create a WeChat Pay client. Recreated if config changes."""
|
||||||
@@ -384,7 +386,8 @@ def _get_wechat_client(
|
|||||||
mchid=mch_id,
|
mchid=mch_id,
|
||||||
private_key=private_key_str,
|
private_key=private_key_str,
|
||||||
cert_serial_no=cert_serial_no,
|
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",
|
gateway=gateway or "https://api.mch.weixin.qq.com",
|
||||||
)
|
)
|
||||||
_wechat_mch_id = mch_id
|
_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", "")
|
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||||
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
||||||
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
|
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", "")
|
gateway = db_configs.get("payment_wechat_gateway", "")
|
||||||
notify_url = db_configs.get("payment_wechat_notify_url", "")
|
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")
|
logger.warning("WeChat payment config missing in database")
|
||||||
return None
|
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:
|
if client is None:
|
||||||
return 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", "")
|
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||||
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
||||||
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
|
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", "")
|
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:
|
if client is None:
|
||||||
return False
|
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", "")
|
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||||
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
||||||
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
|
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", "")
|
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:
|
if client is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -530,9 +536,10 @@ async def _refund_wechat_order(
|
|||||||
private_key = db_configs.get("payment_wechat_private_key", "")
|
private_key = db_configs.get("payment_wechat_private_key", "")
|
||||||
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
cert_serial_no = db_configs.get("payment_wechat_cert_serial_no", "")
|
||||||
api_v3_key = db_configs.get("payment_wechat_api_v3_key", "")
|
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", "")
|
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:
|
if client is None:
|
||||||
return {"success": False, "message": "微信支付客户端初始化失败"}
|
return {"success": False, "message": "微信支付客户端初始化失败"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user