Skip to content

Commit

Permalink
增加只签约插件
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Apr 6, 2023
1 parent 5b2a017 commit a2d42bc
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/Plugin/Wechat/Papay/OnlyContractPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Yansongda\Pay\Plugin\Wechat\Papay;

use Closure;

use function Yansongda\Pay\get_wechat_config;

use Yansongda\Pay\Parser\NoHttpRequestParser;
use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin;
use Yansongda\Pay\Rocket;

/**
* 返回只签约(委托代扣)参数.
*/
class OnlyContractPlugin extends RadarSignPlugin
{
public function assembly(Rocket $rocket, Closure $next): Rocket
{
$config = get_wechat_config($rocket->getParams());

$wechatId = $this->getWechatId($config, $rocket);

if (!$rocket->getPayload()->has('notify_url')) {
$wechatId['notify_url'] = $config['notify_url'] ?? null;
}

$rocket->mergePayload($wechatId);

$rocket->mergePayload([
'sign' => $this->v2GetSign($config['mch_secret_key_v2'] ?? '', $rocket->getPayload()->all()),
]);

$rocket->setDestination($rocket->getPayload());

$rocket->setDirection(NoHttpRequestParser::class);

return $next($rocket);
}

protected function getWechatId(array $config, Rocket $rocket): array
{
$configKey = $this->getConfigKey($rocket->getParams());

$result = [
'appid' => $config[$configKey] ?? '',
'mch_id' => $config['mch_id'] ?? '',
];

return $result;
}

protected function getConfigKey(array $params): string
{
$key = ($params['_type'] ?? 'mp').'_app_id';

if ('app_app_id' === $key) {
$key = 'app_id';
}

return $key;
}
}

0 comments on commit a2d42bc

Please sign in to comment.