chore: prepare production release package

This commit is contained in:
wushumin
2026-06-05 16:12:56 +08:00
parent ed87ea1541
commit 995eae3969
15 changed files with 740 additions and 37 deletions

View File

@@ -78,6 +78,11 @@ class ShouqianbaConfigService
}
}
$this->assertPrivateKey($config['merchant_private_key']);
if ($requirePublicKey) {
$this->assertPublicKey($config['shouqianba_public_key']);
}
return $config;
}
@@ -148,7 +153,7 @@ class ShouqianbaConfigService
return '';
}
if (str_contains($value, '-----BEGIN')) {
return $value;
return $this->normalizePemNewlines($value);
}
if (is_file($value)) {
$content = file_get_contents($value);
@@ -167,6 +172,39 @@ class ShouqianbaConfigService
return $value;
}
private function assertPrivateKey(string $value): void
{
$key = openssl_pkey_get_private($value);
if ($key === false) {
$this->clearOpenSslErrors();
throw new \RuntimeException('收钱吧商户 RSA 私钥不可用,请在后台系统配置中填写有效 PEM 私钥或服务器可读取的 PEM 文件路径。');
}
$this->clearOpenSslErrors();
}
private function assertPublicKey(string $value): void
{
$key = openssl_pkey_get_public($value);
if ($key === false) {
$this->clearOpenSslErrors();
throw new \RuntimeException('收钱吧 RSA 公钥不可用,请在后台系统配置中填写有效 PEM 公钥或服务器可读取的 PEM 文件路径。');
}
$this->clearOpenSslErrors();
}
private function normalizePemNewlines(string $value): string
{
return str_replace(["\\r\\n", "\\n", "\\r"], ["\n", "\n", "\r"], $value);
}
private function clearOpenSslErrors(): void
{
while (openssl_error_string() !== false) {
}
}
private function looksLikeBase64KeyBody(string $value): bool
{
$body = preg_replace('/\s+/', '', trim($value));