Initial MultiPay project

This commit is contained in:
Alex committed 2026-11-02 09:50:37 +08:00
commit 91abad4066
488 files changed
+76727

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import { createHash, createPrivateKey, createPublicKey } from "node:crypto";
import { mkdirSync, writeFileSync } from "node:fs";
import { db } from "../src/db";
import { decryptJson } from "../src/security";
const gatewayId = process.argv[2] || "alipay";
const row = db.query("SELECT config_encrypted FROM gateways WHERE id=? AND channel='alipay'").get(gatewayId) as { config_encrypted: string } | null;
if (!row) throw new Error(`找不到支付宝网关:${gatewayId}`);
const config = decryptJson<Record<string, string>>(row.config_encrypted);
const raw = config.privateKey?.trim();
if (!raw) throw new Error("网关没有配置应用私钥");
const privatePem = raw.includes("-----BEGIN")
? raw.replace(/\\n/g, "\n")
: `-----BEGIN PRIVATE KEY-----\n${raw.replace(/\s+/g, "").match(/.{1,64}/g)?.join("\n")}\n-----END PRIVATE KEY-----`;
const privateKey = createPrivateKey(privatePem);
const publicPem = createPublicKey(privateKey).export({ type: "spki", format: "pem" }).toString();
const publicText = publicPem.replace(/-----BEGIN PUBLIC KEY-----|-----END PUBLIC KEY-----|\s+/g, "");
const fingerprint = createHash("sha256").update(Buffer.from(publicText, "base64")).digest("hex");
mkdirSync("data", { recursive: true });
writeFileSync("data/alipay_app_public_key.pem", publicPem, "utf8");
writeFileSync("data/alipay_app_public_key.txt", publicText, "utf8");
console.log(JSON.stringify({
gatewayId,
appIdConfigured: Boolean(config.appId),
pemFile: "data/alipay_app_public_key.pem",
textFile: "data/alipay_app_public_key.txt",
sha256Fingerprint: fingerprint
}, null, 2));
+33
View File
@@ -0,0 +1,33 @@
import { db } from "../src/db";
import { decryptJson } from "../src/security";
const rows = db.query(`
SELECT id, name, channel, subject_type, mode, enabled, config_encrypted, updated_at
FROM gateways
ORDER BY channel, id
`).all() as Array<Record<string, any>>;
const safe = rows.map((row) => {
const config = decryptJson<Record<string, string>>(row.config_encrypted || "");
let notifyHost = "";
try { notifyHost = config.notifyUrl ? new URL(config.notifyUrl).host : ""; } catch { notifyHost = "INVALID_URL"; }
return {
id: row.id,
name: row.name,
channel: row.channel,
subjectType: row.subject_type,
mode: row.mode,
enabled: Boolean(row.enabled),
updatedAt: row.updated_at,
configured: row.channel === "alipay" ? {
appId: Boolean(config.appId),
merchantPid: Boolean(config.merchantPid),
privateKey: Boolean(config.privateKey),
alipayPublicKey: Boolean(config.alipayPublicKey)
} : undefined,
notifyHost,
customGateway: Boolean(config.gatewayUrl)
};
});
console.log(JSON.stringify(safe, null, 2));
+13
View File
@@ -0,0 +1,13 @@
import { db } from "../src/db";
import { decryptJson, encryptJson } from "../src/security";
const gatewayId = process.argv[2] || "alipay";
const product = process.argv[3] || "page";
if (!['page', 'precreate'].includes(product)) throw new Error("产品必须是 page 或 precreate");
const row = db.query("SELECT config_encrypted FROM gateways WHERE id=? AND channel='alipay'").get(gatewayId) as { config_encrypted: string } | null;
if (!row) throw new Error(`找不到支付宝网关:${gatewayId}`);
const config = decryptJson<Record<string, string>>(row.config_encrypted || "");
config.paymentProduct = product;
db.query("UPDATE gateways SET config_encrypted=?, updated_at=? WHERE id=?")
.run(encryptJson(config), new Date().toISOString(), gatewayId);
console.log(JSON.stringify({ gatewayId, paymentProduct: product, updated: true }));