fix: 添加分账接受人姓名加密字段错误 (#566)

* fix: 添加分账接受人姓名加密字段错误 (#565)

* add unit test: 添加分账接受人姓名加密字段错误 (#565)

* changelog

* styles: fix coding style

Co-authored-by: zhonghuihui <zhonghuihui@example.com>
Co-authored-by: yansongda <me@yansongda.cn>
This commit is contained in:
bupthui 2022-02-18 21:49:42 +08:00 committed by GitHub
parent 83f5822e52
commit 8b4db445e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 23 deletions

View File

@ -1,7 +1,19 @@
## v3.0.25
## v3.0.27
### fix
- fix: 添加分账接受人姓名加密字段错误 (#566)
## v3.0.26
### added
- feat: 支持 psr/log 2.x and 3.x (#562)
## v3.0.25
### fixed
- fix: 支持分账传递姓名 (#559)
## v3.0.24

View File

@ -28,12 +28,13 @@ class AddReceiverPlugin extends GeneralPlugin
$config = get_wechat_config($rocket->getParams());
$extra = $this->getWechatId($config, $rocket->getPayload());
if (!empty($params['receivers'][0]['name'] ?? '')) {
if (!empty($params['name'] ?? '')) {
$params = $this->loadSerialNo($params);
$name = $this->getEncryptUserName($params);
$params['name'] = $name;
$extra['name'] = $name;
$rocket->setParams($params);
$extra['receivers'] = $this->getEncryptUserName($params);
}
$rocket->mergePayload($extra);
@ -63,15 +64,13 @@ class AddReceiverPlugin extends GeneralPlugin
* @throws \Yansongda\Pay\Exception\InvalidParamsException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function getEncryptUserName(array $params): array
protected function getEncryptUserName(array $params): string
{
$lists = $params['receivers'] ?? [];
$name = $params['name'] ?? '';
$publicKey = $this->getPublicKey($params, $params['_serial_no'] ?? '');
foreach ($lists as $key => $list) {
$lists[$key]['name'] = encrypt_wechat_contents($list['name'], $publicKey);
}
$name = encrypt_wechat_contents($name, $publicKey);
return $lists;
return $name;
}
}

View File

@ -29,12 +29,12 @@ class AddReceiverPluginTest extends TestCase
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection());
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;});
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/receivers/add'), $radar->getUri());
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL] . 'v3/profitsharing/receivers/add'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertArrayNotHasKey('sub_mchid', $payload->all());
}
@ -44,12 +44,12 @@ class AddReceiverPluginTest extends TestCase
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;});
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/receivers/add'), $radar->getUri());
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE] . 'v3/profitsharing/receivers/add'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertEquals('1600314070', $payload->get('sub_mchid'));
}
@ -59,7 +59,7 @@ class AddReceiverPluginTest extends TestCase
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;});
$payload = $result->getPayload();
@ -70,20 +70,16 @@ class AddReceiverPluginTest extends TestCase
public function testEncryptName()
{
$params = [
'receivers' => [
[
'name' => 'yansongda'
]
]
'name' => 'yansongda',
];
$rocket = new Rocket();
$rocket->setParams($params)->setPayload(new Collection());
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket;});
$payload = $result->getPayload();
self::assertNotEquals('yansongda', $payload->get('receivers.0.name'));
self::assertStringContainsString('==', $payload->get('receivers.0.name'));
self::assertNotEquals('yansongda', $payload->get('name'));
self::assertStringContainsString('==', $payload->get('name'));
}
}