1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Plugin\Unipay\Pay\Web; |
6
|
|
|
|
7
|
|
|
use Closure; |
8
|
|
|
use Yansongda\Pay\Contract\PluginInterface; |
9
|
|
|
use Yansongda\Pay\Direction\ResponseDirection; |
10
|
|
|
use Yansongda\Pay\Exception\ContainerException; |
11
|
|
|
use Yansongda\Pay\Exception\ServiceNotFoundException; |
12
|
|
|
use Yansongda\Pay\Logger; |
13
|
|
|
use Yansongda\Pay\Packer\QueryPacker; |
14
|
|
|
use Yansongda\Pay\Rocket; |
15
|
|
|
|
16
|
|
|
use function Yansongda\Pay\get_unipay_config; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see https://open.unionpay.com/tjweb/acproduct/APIList?acpAPIId=754&apiservId=448&version=V2.2&bussType=0 |
20
|
|
|
*/ |
21
|
|
|
class PayPlugin implements PluginInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @throws ContainerException |
25
|
|
|
* @throws ServiceNotFoundException |
26
|
|
|
*/ |
27
|
|
|
public function assembly(Rocket $rocket, Closure $next): Rocket |
28
|
|
|
{ |
29
|
|
|
Logger::debug('[Unipay][Pay][Web][PayPlugin] 插件开始装载', ['rocket' => $rocket]); |
30
|
|
|
|
31
|
|
|
$params = $rocket->getParams(); |
32
|
|
|
$config = get_unipay_config($params); |
33
|
|
|
$payload = $rocket->getPayload(); |
34
|
|
|
|
35
|
|
|
$rocket->setPacker(QueryPacker::class) |
36
|
|
|
->setDirection(ResponseDirection::class) |
37
|
|
|
->mergePayload([ |
38
|
|
|
'_url' => 'gateway/api/frontTransReq.do', |
39
|
|
|
'encoding' => 'utf-8', |
40
|
|
|
'signature' => '', |
41
|
|
|
'bizType' => $payload?->get('bizType') ?? '000201', |
42
|
|
|
'accessType' => $payload?->get('accessType') ?? '0', |
43
|
|
|
'merId' => $config['mch_id'] ?? '', |
44
|
|
|
'currencyCode' => '156', |
45
|
|
|
'channelType' => $payload?->get('channelType') ?? '07', |
46
|
|
|
'signMethod' => '01', |
47
|
|
|
'txnType' => $payload?->get('txnType') ?? '01', |
48
|
|
|
'txnSubType' => $payload?->get('txnSubType') ?? '01', |
49
|
|
|
'frontUrl' => $payload?->get('frontUrl') ?? $config['return_url'] ?? '', |
50
|
|
|
'backUrl' => $payload?->get('backUrl') ?? $config['notify_url'] ?? '', |
51
|
|
|
'version' => '5.1.0', |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
Logger::info('[Unipay][Pay][Web][PayPlugin] 插件装载完毕', ['rocket' => $rocket]); |
55
|
|
|
|
56
|
|
|
return $next($rocket); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|