feat: 支持使用小程序等其他类型转账 (#552)

* 支持使用小程序等其他类型转账

* changelog
This commit is contained in:
yansongda 2022-01-09 17:22:22 +08:00 committed by GitHub
parent 9e29c732d0
commit fd921a2b5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 7 deletions

View File

@ -1,3 +1,9 @@
## v3.0.24
### added
- feat: 支持使用小程序等其他类型转账 (#552)
## v3.0.23
### fixed

View File

@ -8,7 +8,7 @@ use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Traits\HasWechatEncryption;
use Yansongda\Supports\Config;
use Yansongda\Supports\Collection;
class CreatePlugin extends GeneralPlugin
{
@ -25,9 +25,7 @@ class CreatePlugin extends GeneralPlugin
protected function doSomething(Rocket $rocket): void
{
$params = $rocket->getParams();
$config = get_wechat_config($params);
$extra = $this->getWechatId($config);
$extra = $this->getWechatId($params, $rocket->getPayload());
if (!empty($params['transfer_detail_list'][0]['user_name'] ?? '')) {
$params = $this->loadSerialNo($params);
@ -50,15 +48,27 @@ class CreatePlugin extends GeneralPlugin
return 'v3/partner-transfer/batches';
}
protected function getWechatId(Config $config): array
/**
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
* @throws \Yansongda\Pay\Exception\ContainerException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function getWechatId(array $params, Collection $payload): array
{
$config = get_wechat_config($params);
$key = ($params['_type'] ?? 'mp').'_app_id';
if ('app_app_id' === $key) {
$key = 'app_id';
}
$appId = [
'appid' => $config->get('mp_app_id'),
'appid' => $payload->get('appid', $config->get($key, '')),
];
if (Pay::MODE_SERVICE == $config->get('mode')) {
$appId = [
'sub_mchid' => $config->get('sub_mch_id', ''),
'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id', '')),
];
}

View File

@ -101,4 +101,18 @@ class CreatePluginTest extends TestCase
self::assertEquals('yansongda', $result->getParams()['_serial_no']);
self::assertStringContainsString('==', $userName);
}
public function testNormalOtherType()
{
$rocket = new Rocket();
$rocket->setParams(['_type' => 'mini'])->setPayload(new Collection());
$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/transfer/batches'), $radar->getUri());
self::assertEquals('wx55955316af4ef14', $payload->get('appid'));
}
}