mirror of
https://gitee.com/yansongda/pay.git
synced 2024-11-29 18:58:38 +08:00
feat: 支付宝根证书配置支持直接配置证书内容 (#959)
Co-authored-by: yansongda <me@yansongda.cn>
This commit is contained in:
parent
ee235fe96a
commit
69b498af42
@ -1,3 +1,9 @@
|
||||
## v3.6.5
|
||||
|
||||
### added
|
||||
|
||||
- feat: 支付宝根证书配置支持直接配置内容(#959)
|
||||
|
||||
## v3.6.4
|
||||
|
||||
### fixed
|
||||
|
@ -112,7 +112,7 @@ class StartPlugin implements PluginInterface
|
||||
$ssl = openssl_x509_parse(get_public_cert($path));
|
||||
|
||||
if (false === $ssl) {
|
||||
throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, 'Parse `app_public_cert_path` Error');
|
||||
throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, '配置异常: 解析 `app_public_cert_path` 失败');
|
||||
}
|
||||
|
||||
$result = $this->getCertSn($ssl['issuer'] ?? [], $ssl['serialNumber'] ?? '');
|
||||
@ -136,11 +136,11 @@ class StartPlugin implements PluginInterface
|
||||
$path = $config['alipay_root_cert_path'] ?? null;
|
||||
|
||||
if (is_null($path)) {
|
||||
throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, 'Missing Alipay Config -- [alipay_root_cert_path]');
|
||||
throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, '配置异常: 缺少支付宝配置 -- [alipay_root_cert_path]');
|
||||
}
|
||||
|
||||
$sn = '';
|
||||
$exploded = explode('-----END CERTIFICATE-----', file_get_contents($path));
|
||||
$exploded = explode('-----END CERTIFICATE-----', get_public_cert($path));
|
||||
|
||||
foreach ($exploded as $cert) {
|
||||
if (empty(trim($cert))) {
|
||||
@ -150,7 +150,7 @@ class StartPlugin implements PluginInterface
|
||||
$ssl = openssl_x509_parse($cert.'-----END CERTIFICATE-----');
|
||||
|
||||
if (false === $ssl) {
|
||||
throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, 'Invalid alipay_root_cert');
|
||||
throw new InvalidConfigException(Exception::CONFIG_ALIPAY_INVALID, '配置异常: 解析 `alipay_root_cert` 失败');
|
||||
}
|
||||
|
||||
$detail = $this->formatCert($ssl);
|
||||
|
@ -119,7 +119,7 @@ class StartPluginTest extends TestCase
|
||||
|
||||
self::expectException(InvalidConfigException::class);
|
||||
self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID);
|
||||
self::expectExceptionMessage('Parse `app_public_cert_path` Error');
|
||||
self::expectExceptionMessage('配置异常: 解析 `app_public_cert_path` 失败');
|
||||
|
||||
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
@ -133,7 +133,7 @@ class StartPluginTest extends TestCase
|
||||
|
||||
self::expectException(InvalidConfigException::class);
|
||||
self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID);
|
||||
self::expectExceptionMessage('Missing Alipay Config -- [alipay_root_cert_path]');
|
||||
self::expectExceptionMessage('配置异常: 缺少支付宝配置 -- [alipay_root_cert_path]');
|
||||
|
||||
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
@ -147,7 +147,7 @@ class StartPluginTest extends TestCase
|
||||
|
||||
self::expectException(InvalidConfigException::class);
|
||||
self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID);
|
||||
self::expectExceptionMessage('Invalid alipay_root_cert');
|
||||
self::expectExceptionMessage('配置异常: 解析 `alipay_root_cert` 失败');
|
||||
|
||||
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
@ -183,4 +183,102 @@ class StartPluginTest extends TestCase
|
||||
|
||||
self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $payload->get('alipay_root_cert_sn'));
|
||||
}
|
||||
|
||||
public function testAlipayRootCertSnString()
|
||||
{
|
||||
$config = Pay::get(ConfigInterface::class);
|
||||
$config->set('alipay.default.alipay_root_cert_path', '-----BEGIN CERTIFICATE-----
|
||||
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Yf4Zr0fJsGuv
|
||||
-----END CERTIFICATE-----');
|
||||
|
||||
$result = $this->plugin->assembly(new Rocket(), function ($rocket) { return $rocket; });
|
||||
$payload = $result->getPayload();
|
||||
|
||||
self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $payload->get('alipay_root_cert_sn'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user