/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { Trans } from 'react-i18next'; import React, { useState } from 'react'; import { Form, Button, Typography, Space, Divider } from '@/components/ui'; import { API, showError, showSuccess } from '../../../helpers'; import { useTranslation } from 'react-i18next'; const { Title, Text } = Typography; const SettingsPaymentWechat = ({ options, refresh }) => { const { t } = useTranslation(); const [loading, setLoading] = useState(false); const onSubmit = async (values) => { try { setLoading(true); // 保存微信支付配置 const configs = [ { key: 'WechatMchId', value: values.WechatMchId || '' }, { key: 'WechatAppId', value: values.WechatAppId || '' }, // 如果敏感字段未修改(仍然是空或占位符),则使用占位符让后端跳过更新 { key: 'WechatAPIv3Key', value: values.WechatAPIv3Key && values.WechatAPIv3Key.trim() !== '' ? values.WechatAPIv3Key : '***ALREADY_SET***', }, { key: 'WechatSerialNo', value: values.WechatSerialNo || '' }, { key: 'WechatPrivateKey', value: values.WechatPrivateKey && values.WechatPrivateKey.trim() !== '' ? values.WechatPrivateKey : '***ALREADY_SET***', }, { key: 'WechatNativeEnabled', value: values.WechatNativeEnabled ? 'true' : 'false', }, { key: 'WechatH5Enabled', value: values.WechatH5Enabled ? 'true' : 'false', }, { key: 'WechatNotifyUrl', value: values.WechatNotifyUrl || '' }, { key: 'WechatDescription', value: values.WechatDescription || '平台充值', }, { key: 'WechatExpireMinutes', value: String(values.WechatExpireMinutes || 30), }, // 公钥模式配置(2024年新商户) { key: 'WechatUsePublicKey', value: values.WechatUsePublicKey ? 'true' : 'false', }, { key: 'WechatPublicKeyID', value: values.WechatPublicKeyID || '' }, { key: 'WechatPublicKeyPEM', value: values.WechatPublicKeyPEM && values.WechatPublicKeyPEM.trim() !== '' ? values.WechatPublicKeyPEM : '***ALREADY_SET***', }, // 手动证书模式配置 { key: 'WechatUseManualCert', value: values.WechatUseManualCert ? 'true' : 'false', }, { key: 'WechatPlatformCertPath', value: values.WechatPlatformCertPath || '', }, { key: 'WechatPlatformCertPEM', value: values.WechatPlatformCertPEM && values.WechatPlatformCertPEM.trim() !== '' ? values.WechatPlatformCertPEM : '***ALREADY_SET***', }, ]; for (const config of configs) { const res = await API.put('/api/option/', config); if (!res.data.success) { throw new Error( t('保存 {{key}} 失败:{{message}}', { key: config.key, message: res.data.message, }), ); } } showSuccess(t('微信支付配置保存成功')); if (refresh) refresh(); } catch (error) { showError(error.message || t('保存失败')); } finally { setLoading(false); } }; return ( <> {t('微信支付配置')} ), }} />
{t('公钥模式(2024年新商户必选)')} {t( '2024年后注册的微信支付商户默认使用公钥模式。如果初始化失败提示"无可用的平台证书",请从商户平台下载微信支付公钥并启用此模式。', )} {t('高级配置:手动平台证书模式(可选)')} {t( '默认情况下,SDK 会自动下载微信平台证书,无需手动配置。仅在离线环境或网络受限时启用此选项。', )} ); }; export default SettingsPaymentWechat;