fix(billing): 微信支付钉死「微信支付公钥」验签体系 —— 商户 2025-09 开户没有平台证书
用户拿旧项目代码对出来的真问题:我此前用 WithWechatPayAutoAuthCipher(平台证书 模式,APIv3 密钥自动下载平台证书验签),但 2024 起新注册商户只发「微信支付公钥」 (PUB_KEY_ID_ 开头)、没有平台证书——在该商户号上初始化/回调验签都会挂。 - 改 WithWechatPayPublicKeyAuthCipher(商户私钥+公钥ID+公钥文件);回调验签用 NewSHA256WithRSAPubkeyVerifier;平台证书模式不留双模式赘肉(YAGNI)。 - Config 增 public_key_path/public_key_id(必填,公钥文件同样只存路径); admin 卡片补两字段;env 兜底加 WECHAT_PUBLIC_KEY(_ID)。 - 顺手修 live 撞出的真 bug:sundynix_setting.value 是 varchar(255), 支付配置 JSON(含加密密钥)一条就超(SQLSTATE 22001)→ 改 text。 live:列类型已迁 text;缺公钥两项报「配置不全,缺: public_key_path, public_key_id」;GET 回显含新字段。go 6 包测试+tsc+41 vitest 全绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -231,6 +231,8 @@ export interface WechatPayConfig {
|
||||
mchid: string;
|
||||
cert_serial: string;
|
||||
private_key_path: string;
|
||||
public_key_path: string; // 微信支付公钥(2024 起新商户体系;本商户 2025-09 开户)
|
||||
public_key_id: string; // PUB_KEY_ID_ 开头
|
||||
appid: string;
|
||||
notify_url: string;
|
||||
has_apiv3_key: boolean;
|
||||
@@ -248,6 +250,8 @@ export async function saveWechatPay(body: {
|
||||
mchid: string;
|
||||
cert_serial: string;
|
||||
private_key_path: string;
|
||||
public_key_path: string;
|
||||
public_key_id: string;
|
||||
apiv3_key: string;
|
||||
appid: string;
|
||||
notify_url: string;
|
||||
|
||||
@@ -29,7 +29,7 @@ export function TopupChannels() {
|
||||
// APIv3 密钥只写不回显(密文入库,与模型 API Key 同一把密钥加密);
|
||||
// 商户证书私钥文件放服务器磁盘,这里只填路径。
|
||||
function WechatConfigBlock() {
|
||||
const empty: WechatPayConfig = { mchid: "", cert_serial: "", private_key_path: "", appid: "", notify_url: "", has_apiv3_key: false };
|
||||
const empty: WechatPayConfig = { mchid: "", cert_serial: "", private_key_path: "", public_key_path: "", public_key_id: "", appid: "", notify_url: "", has_apiv3_key: false };
|
||||
const [cfg, setCfg] = useState<WechatPayConfig>(empty);
|
||||
const [apiv3, setApiv3] = useState(""); // 留空=沿用已存
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
@@ -56,6 +56,8 @@ function WechatConfigBlock() {
|
||||
mchid: cfg.mchid,
|
||||
cert_serial: cfg.cert_serial,
|
||||
private_key_path: cfg.private_key_path,
|
||||
public_key_path: cfg.public_key_path,
|
||||
public_key_id: cfg.public_key_id,
|
||||
apiv3_key: apiv3, // 空串=后端沿用旧密钥
|
||||
appid: cfg.appid,
|
||||
notify_url: cfg.notify_url,
|
||||
@@ -102,6 +104,8 @@ function WechatConfigBlock() {
|
||||
{field("API 证书序列号", "cert_serial", "5157F09E…")}
|
||||
{field("appid(公众号/小程序)", "appid", "wx88888888")}
|
||||
{field("商户私钥文件路径(服务器磁盘)", "private_key_path", "/etc/sundynix/wechat/apiclient_key.pem", "md:col-span-2")}
|
||||
{field("公钥 ID(PUB_KEY_ID_ 开头)", "public_key_id", "PUB_KEY_ID_01…")}
|
||||
{field("微信支付公钥文件路径(服务器磁盘)", "public_key_path", "/etc/sundynix/wechat/pub_key.pem", "md:col-span-2")}
|
||||
<label className="text-xs text-gray-500">
|
||||
APIv3 密钥{cfg.has_apiv3_key && <span className="ml-1 text-emerald-600">已保存</span>}
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user