fix: 未配置微信证书时,自动获取证书后仍然使用之前的微信配置 (#1026)

* 修复自动获取微信平台公钥证书相关接口提示 参数异常: 微信公钥序列号为找到 错误

* 优化代码,增加单测

---------

Co-authored-by: yansongda <me@yansongda.cn>
This commit is contained in:
小新 2024-09-11 11:25:00 +08:00 committed by GitHub
parent 2ea20b79f1
commit 0aea5b2ddc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 287 additions and 0 deletions

View File

@ -1,3 +1,9 @@
## v3.7.10
### fixed
- fix: 未配置微信证书时,自动获取证书后仍然使用之前的微信配置(#1026)
## v3.7.9
### added

View File

@ -123,6 +123,8 @@ class AddReceiverPlugin implements PluginInterface
protected function encryptSensitiveData(array $params, array $config, Collection $payload): array
{
$data['_serial_no'] = get_wechat_serial_no($params);
$config = get_provider_config('wechat', $params);
$publicKey = get_wechat_public_key($config, $data['_serial_no']);
$data['name'] = encrypt_wechat_contents($payload->get('name'), $publicKey);

View File

@ -123,6 +123,8 @@ class CreatePlugin implements PluginInterface
protected function encryptSensitiveData(array $params, array $config, Collection $payload): array
{
$data['_serial_no'] = get_wechat_serial_no($params);
$config = get_provider_config('wechat', $params);
$publicKey = get_wechat_public_key($config, $data['_serial_no']);
foreach ($payload->get('receivers', []) as $key => $list) {

View File

@ -60,6 +60,8 @@ class CreatePlugin implements PluginInterface
protected function encryptSensitiveData(?Collection $payload, array $params, array $config): array
{
$data['_serial_no'] = get_wechat_serial_no($params);
$config = get_provider_config('wechat', $params);
$publicKey = get_wechat_public_key($config, $data['_serial_no']);
$phone = $payload?->get('buyer_information.phone') ?? null;

View File

@ -92,6 +92,8 @@ class CreatePlugin implements PluginInterface
{
$data['transfer_detail_list'] = $payload->get('transfer_detail_list', []);
$data['_serial_no'] = get_wechat_serial_no($params);
$config = get_provider_config('wechat', $params);
$publicKey = get_wechat_public_key($config, $data['_serial_no']);
foreach ($data['transfer_detail_list'] as $key => $list) {

View File

@ -105,6 +105,8 @@ class RefundAbnormalPlugin implements PluginInterface
{
if ($payload->has('bank_account') && $payload->has('real_name')) {
$data['_serial_no'] = get_wechat_serial_no($params);
$config = get_provider_config('wechat', $params);
$publicKey = get_wechat_public_key($config, $data['_serial_no']);
$data['real_name'] = encrypt_wechat_contents($payload->get('real_name'), $publicKey);

View File

@ -2,8 +2,13 @@
namespace Yansongda\Pay\Tests\Plugin\Wechat\V3\Extend\ProfitSharing;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Mockery;
use Yansongda\Artful\Contract\HttpClientInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Artful\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\AddReceiverPlugin;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Tests\TestCase;
@ -151,4 +156,50 @@ class AddReceiverPluginTest extends TestCase
'type' => 'PERSONAL_SUB_OPENID',
], $result->getPayload()->all());
}
public function testServiceWithNameEmptyWechatCert()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'empty_wechat_public_cert'])->setPayload(new Collection([
"name" => "yansongda",
]));
$response = new Response(
200,
[],
json_encode([
'data' => [
[
'effective_time' => '2021-07-16T17:51:10+08:00',
'encrypt_certificate' => [
'algorithm' => 'AEAD_AES_256_GCM',
'associated_data' => 'certificate',
'ciphertext' => 'kbbHAUhBwdjYZkHPW149MW/8WNpxQo1Gyp4kVNVjd+zrXnyOFhgZic2U2+tobFAgfdr93zr0JZF3FdbxgkaOAV2NAeCfU8jsUYXSfn7fM8487jXMVXKKEneGiiv1/bDLkz7KFsTfu2y5Rv+igWQ+bvCUQAwoNzjupTXnnDR5hBiofZcFLHL45govyYE2o0qD5SLiJHcFS4pg/IOx8SIqUFNepr3piKXUxKowU8/kNxXyRzL8yp7XnhrzAzclupvjveNwZyiw3TqlLZdR5TbEFLCogWaRHZRqz3vKEfgRaUYUtXCtQVrm+adbSDBFIq34v+XfeIHMz9pKhH/m80N5Hx69hPzbvId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VTb3pmriUbXfg/ThHF/y0THyrM6bVDNOwNWZOpMYPPNaVmOTX39JdYayWl2HX0n8AsIRmevXzD4N9iDh2HGwie4gh92Qdcogwua++uhkhSsLFuWBpJiaPdxVtzz3E3jHfy+yryfh6msaXc/jmhwqBm/ii3j76lDP5YaRv4+JWZmom72+pmZuKD8qPKrPRxI2/aGiKEqgs25knpLLnbAhWAEYeIzVK1sQkjc5JFss1Std8FdDrHeM6agAB+MWncK1LloXZmiwz/6WmlwSDepnGHqLEciXThAZq6FwunJZTcHY9LamJgIY81c9t/KHlSFqlc/9mW4OZHM4BOZQ5sTj5PWE+OP2Aq9CKdJqoK3OmphBg2ewjrZt5/tSn9jpk6NlVrHD7MsJcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==',
'nonce' => '4196a5b75276',
],
'expire_time' => '2026-07-15T17:51:10+08:00',
'serial_no' => 'test-45F59D4DABF31918AFCEC556D5D2C6E376675D57',
]
]
])
);
$http = Mockery::mock(Client::class);
$http->shouldReceive('sendRequest')->andReturn($response);
Pay::set(HttpClientInterface::class, $http);
$result = $this->plugin->assembly($rocket, function ($rocket) {
return $rocket;
});
$payload = $result->getPayload()->all();
self::assertEquals('POST', $payload['_method']);
self::assertEquals('v3/profitsharing/receivers/add', $payload['_url']);
self::assertEquals('v3/profitsharing/receivers/add', $payload['_service_url']);
self::assertEquals('wx55955316af4ef13', $payload['appid']);
self::assertArrayHasKey('_serial_no', $payload);
self::assertArrayHasKey('name', $payload);
self::assertNotEquals('yansongda', $payload['name']);
}
}

View File

@ -2,8 +2,13 @@
namespace Yansongda\Pay\Tests\Plugin\Wechat\V3\Extend\ProfitSharing;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Mockery;
use Yansongda\Artful\Contract\HttpClientInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Artful\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\CreatePlugin;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Tests\TestCase;
@ -167,4 +172,54 @@ class CreatePluginTest extends TestCase
],
], $result->getPayload()->all());
}
public function testServiceWithNameEmptyWechatCert()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'empty_wechat_public_cert'])->setPayload(new Collection([
'receivers' => [
[
'name' => 'yansongda',
],
],
]));
$response = new Response(
200,
[],
json_encode([
'data' => [
[
'effective_time' => '2021-07-16T17:51:10+08:00',
'encrypt_certificate' => [
'algorithm' => 'AEAD_AES_256_GCM',
'associated_data' => 'certificate',
'ciphertext' => 'kbbHAUhBwdjYZkHPW149MW/8WNpxQo1Gyp4kVNVjd+zrXnyOFhgZic2U2+tobFAgfdr93zr0JZF3FdbxgkaOAV2NAeCfU8jsUYXSfn7fM8487jXMVXKKEneGiiv1/bDLkz7KFsTfu2y5Rv+igWQ+bvCUQAwoNzjupTXnnDR5hBiofZcFLHL45govyYE2o0qD5SLiJHcFS4pg/IOx8SIqUFNepr3piKXUxKowU8/kNxXyRzL8yp7XnhrzAzclupvjveNwZyiw3TqlLZdR5TbEFLCogWaRHZRqz3vKEfgRaUYUtXCtQVrm+adbSDBFIq34v+XfeIHMz9pKhH/m80N5Hx69hPzbvIdBhzwaEDyN3h8gaeYKFyW9xIAs5jCrzzUEkKyMzOKzx7XA+1HRakSyvs6RlkRTa/ztBy6aZL0nxK6XMZ9tA7zdf2VnBX/7WPQYRzoky0cVyH1KRZxI7In2hfvpjSvl6P7Adzp+EZXYM/dINTrrg+RQRe60tPy7vgE8PZZf+SAWzSZPWIm7Lx6GksJX0vnT4gOeTAPw6EeFsYU/ZD7fYslJOEbA14yHBrJFkwDpSI8aSHp2nZYbruM0y8IKr0p3vjN80Ko3jiRPxj4uNdJliR9WDCV22b9JeadAaJhO9+oSNbbtFnFTCZjXbf8rMz5KCGVrGRvUyB70zhRxYIOdTYKAEkmbU7jcMLd0aufuQqIw0WviQHB+ztrkjBCF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JcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==',
'nonce' => '4196a5b75276',
],
'expire_time' => '2026-07-15T17:51:10+08:00',
'serial_no' => 'test-45F59D4DABF31918AFCEC556D5D2C6E376675D57',
]
]
])
);
$http = Mockery::mock(Client::class);
$http->shouldReceive('sendRequest')->andReturn($response);
Pay::set(HttpClientInterface::class, $http);
$result = $this->plugin->assembly($rocket, function ($rocket) {
return $rocket;
});
$payload = $result->getPayload()->all();
self::assertEquals('POST', $payload['_method']);
self::assertEquals('v3/profitsharing/orders', $payload['_url']);
self::assertEquals('v3/profitsharing/orders', $payload['_service_url']);
self::assertEquals('wx55955316af4ef13', $payload['appid']);
self::assertArrayHasKey('_serial_no', $payload);
self::assertArrayHasKey('name', $payload['receivers'][0]);
self::assertNotEquals('yansongda', $payload['receivers'][0]['name']);
}
}

View File

@ -2,7 +2,12 @@
namespace Yansongda\Pay\Tests\Plugin\Wechat\V3\Marketing\Fapiao\Blockchain;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Mockery;
use Yansongda\Artful\Contract\HttpClientInterface;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\V3\Marketing\Fapiao\Blockchain\CreatePlugin;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
@ -55,4 +60,51 @@ class CreatePluginTest extends TestCase
self::assertNotEquals('123', $payload['buyer_information']['phone']);
self::assertNotEquals('456', $payload['buyer_information']['email']);
}
public function testNormalWithSensitiveDataEmptyWechatCert()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'empty_wechat_public_cert'])->setPayload(new Collection( [
"test" => "yansongda",
'buyer_information' => [
'phone' => '123',
'email' => '456',
]
]));
$response = new Response(
200,
[],
json_encode([
'data' => [
[
'effective_time' => '2021-07-16T17:51:10+08:00',
'encrypt_certificate' => [
'algorithm' => 'AEAD_AES_256_GCM',
'associated_data' => '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EQqc12yANTvdq7cFVllWqMHBsXPCjpHWIHcS5BMkImoD7s6WItq60yJA8ioGJf3Rba+Yb/YeBBNxjDnXtAmX/2hJIsxEFLTYGUvdmFC5jeb5ifrOuxnLciKM8y4nLZ28dDsvVsaBBAMAFYfWb5NymKUDhhngR5bDuW4sKccZ6DmYQeStHT1fn2yoSneGA70HctQSWZ2roTdNihPTCs7rYD0dFeQ+SfLOJzMN4c5GbJ6n5tdCjERcLGIaXEKacfySo7e4VZtHeHowvlvBclS9pooZqzHd+EFlJEYywEs9jURgsJY2yHJt2zTZeIdsvM8KK5v0NkH8FiPbWqFG8LaRmUrqhJGLuLLRTcJnt6YVYESxUVTb3pmriUbXfg/ThHF/y0THyrM6bVDNOwNWZOpMYPPNaVmOTX39JdYayWl2HX0n8AsIRmevXzD4N9iDh2HGwie4gh92Qdcogwua++uhkhSsLFuWBpJiaPdxVtzz3E3jHfy+yryfh6msaXc/jmhwqBm/ii3j76lDP5YaRv4+JWZmom72+pmZuKD8qPKrPRxI2/aGiKEqgs25knpLLnbAhWAEYeIzVK1sQkjc5JFss1Std8FdDrHeM6agAB+MWncK1LloXZmiwz/6WmlwSDepnGHqLEciXThAZq6FwunJZTcHY9LamJgIY81c9t/KHlSFqlc/9mW4OZHM4BOZQ5sTj5PWE+OP2Aq9CKdJqoK3OmphBg2ewjrZt5/tSn9jpk6NlVrHD7MsJcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==',
'nonce' => '4196a5b75276',
],
'expire_time' => '2026-07-15T17:51:10+08:00',
'serial_no' => 'test-45F59D4DABF31918AFCEC556D5D2C6E376675D57',
]
]
])
);
$http = Mockery::mock(Client::class);
$http->shouldReceive('sendRequest')->andReturn($response);
Pay::set(HttpClientInterface::class, $http);
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload()->all();
self::assertEquals('POST', $payload['_method']);
self::assertEquals('v3/new-tax-control-fapiao/fapiao-applications', $payload['_url']);
self::assertEquals('yansongda', $payload['test']);
self::assertArrayHasKey('_serial_no', $payload);
self::assertNotEquals('123', $payload['buyer_information']['phone']);
self::assertNotEquals('456', $payload['buyer_information']['email']);
}
}

View File

@ -2,8 +2,13 @@
namespace Yansongda\Pay\Tests\Plugin\Wechat\V3\Marketing\Transfer;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Mockery;
use Yansongda\Artful\Contract\HttpClientInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Artful\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\V3\Marketing\Transfer\CreatePlugin;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Tests\TestCase;
@ -105,4 +110,57 @@ class CreatePluginTest extends TestCase
self::assertNotEquals('yansongda', $payload['transfer_detail_list'][0]['user_name']);
self::assertEquals('bar', $payload['transfer_detail_list'][0]['foo']);
}
public function testNormalWithNameEmptyWechatCer()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'empty_wechat_public_cert'])->setPayload(new Collection([
"test" => "111",
'transfer_detail_list' => [
[
'user_name' => 'yansongda',
'foo' => 'bar',
]
]
]));
$response = new Response(
200,
[],
json_encode([
'data' => [
[
'effective_time' => '2021-07-16T17:51:10+08:00',
'encrypt_certificate' => [
'algorithm' => 'AEAD_AES_256_GCM',
'associated_data' => 'certificate',
'ciphertext' => 'kbbHAUhBwdjYZkHPW149MW/8WNpxQo1Gyp4kVNVjd+zrXnyOFhgZic2U2+tobFAgfdr93zr0JZF3FdbxgkaOAV2NAeCfU8jsUYXSfn7fM8487jXMVXKKEneGiiv1/bDLkz7KFsTfu2y5Rv+igWQ+bvCUQAwoNzjupTXnnDR5hBiofZcFLHL45govyYE2o0qD5SLiJHcFS4pg/IOx8SIqUFNepr3piKXUxKowU8/kNxXyRzL8yp7XnhrzAzclupvjveNwZyiw3TqlLZdR5TbEFLCogWaRHZRqz3vKEfgRaUYUtXCtQVrm+adbS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FiPbWqFG8LaRmUrqhJGLuLLRTcJnt6YVYESxUVTb3pmriUbXfg/ThHF/y0THyrM6bVDNOwNWZOpMYPPNaVmOTX39JdYayWl2HX0n8AsIRmevXzD4N9iDh2HGwie4gh92Qdcogwua++uhkhSsLFuWBpJiaPdxVtzz3E3jHfy+yryfh6msaXc/jmhwqBm/ii3j76lDP5YaRv4+JWZmom72+pmZuKD8qPKrPRxI2/aGiKEqgs25knpLLnbAhWAEYeIzVK1sQkjc5JFss1Std8FdDrHeM6agAB+MWncK1LloXZmiwz/6WmlwSDepnGHqLEciXThAZq6FwunJZTcHY9LamJgIY81c9t/KHlSFqlc/9mW4OZHM4BOZQ5sTj5PWE+OP2Aq9CKdJqoK3OmphBg2ewjrZt5/tSn9jpk6NlVrHD7MsJcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==',
'nonce' => '4196a5b75276',
],
'expire_time' => '2026-07-15T17:51:10+08:00',
'serial_no' => 'test-45F59D4DABF31918AFCEC556D5D2C6E376675D57',
]
]
])
);
$http = Mockery::mock(Client::class);
$http->shouldReceive('sendRequest')->andReturn($response);
Pay::set(HttpClientInterface::class, $http);
$result = $this->plugin->assembly($rocket, function ($rocket) {
return $rocket;
});
$payload = $result->getPayload()->all();
self::assertEquals('POST', $payload['_method']);
self::assertEquals('v3/transfer/batches', $payload['_url']);
self::assertEquals('wx55955316af4ef13', $payload['appid']);
self::assertEquals('111', $payload['test']);
self::assertArrayHasKey('_serial_no', $payload);
self::assertArrayHasKey('user_name', $payload['transfer_detail_list'][0]);
self::assertNotEquals('yansongda', $payload['transfer_detail_list'][0]['user_name']);
self::assertEquals('bar', $payload['transfer_detail_list'][0]['foo']);
}
}

View File

@ -2,8 +2,13 @@
namespace Yansongda\Pay\Tests\Plugin\Wechat\V3\Pay\Refund;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Mockery;
use Yansongda\Artful\Contract\HttpClientInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Artful\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Refund\RefundAbnormalPlugin;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Tests\TestCase;
@ -138,4 +143,54 @@ class RefundAbnormalPluginTest extends TestCase
self::assertNotEquals('333', $payload['real_name']);
self::assertArrayHasKey('_serial_no', $payload);
}
public function testServiceWithNameEmptyWechatCert()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'empty_wechat_public_cert'])->setPayload(new Collection([
'refund_id' => '111',
"name" => "yansongda",
'bank_account' => '222',
'real_name' => '333',
]));
$response = new Response(
200,
[],
json_encode([
'data' => [
[
'effective_time' => '2021-07-16T17:51:10+08:00',
'encrypt_certificate' => [
'algorithm' => 'AEAD_AES_256_GCM',
'associated_data' => 'certificate',
'ciphertext' => 'kbbHAUhBwdjYZkHPW149MW/8WNpxQo1Gyp4kVNVjd+zrXnyOFhgZic2U2+tobFAgfdr93zr0JZF3FdbxgkaOAV2NAeCfU8jsUYXSfn7fM8487jXMVXKKEneGiiv1/bDLkz7KFsTfu2y5Rv+igWQ+bvCUQAwoNzjupTXnnDR5hBiofZcFLHL45govyYE2o0qD5SLiJHcFS4pg/IOx8SIqUFNepr3piKXUxKowU8/kNxXyRzL8yp7XnhrzAzclupvjveNwZyiw3TqlLZdR5TbEFLCogWaRHZRqz3vKEfgRaUYUtXCtQVrm+adbSDBFIq34v+XfeIHMz9pKhH/m80N5Hx69hPzbvIdBhzwaEDyN3h8gaeYKFyW9xIAs5jCrzzUEkKyMzOKzx7XA+1HRakSyvs6RlkRTa/ztBy6aZL0nxK6XMZ9tA7zdf2VnBX/7WPQYRzoky0cVyH1KRZxI7In2hfvpjSvl6P7Adzp+EZXYM/dINTrrg+RQRe60tPy7vgE8PZZf+SAWzSZPWIm7Lx6GksJX0vnT4gOeTAPw6EeFsYU/ZD7fYslJOEbA14yHBrJFkwDpSI8aSHp2nZYbruM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XZmiwz/6WmlwSDepnGHqLEciXThAZq6FwunJZTcHY9LamJgIY81c9t/KHlSFqlc/9mW4OZHM4BOZQ5sTj5PWE+OP2Aq9CKdJqoK3OmphBg2ewjrZt5/tSn9jpk6NlVrHD7MsJcKi5a0he4qvNPh1cHqUqWcF4rBFmfPptdHIBV77LXnizJZMUAwf16KsmJpwJg==',
'nonce' => '4196a5b75276',
],
'expire_time' => '2026-07-15T17:51:10+08:00',
'serial_no' => 'test-45F59D4DABF31918AFCEC556D5D2C6E376675D57',
]
]
])
);
$http = Mockery::mock(Client::class);
$http->shouldReceive('sendRequest')->andReturn($response);
Pay::set(HttpClientInterface::class, $http);
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload()->all();
self::assertEquals('POST', $payload['_method']);
self::assertEquals('v3/refund/domestic/refunds/111/apply-abnormal-refund', $payload['_url']);
self::assertEquals('v3/refund/domestic/refunds/111/apply-abnormal-refund', $payload['_service_url']);
self::assertEquals('yansongda', $payload['name']);
self::assertArrayHasKey('bank_account', $payload);
self::assertNotEquals('222', $payload['bank_account']);
self::assertArrayHasKey('real_name', $payload);
self::assertNotEquals('333', $payload['real_name']);
self::assertArrayHasKey('_serial_no', $payload);
}
}