Passed
Push — master ( 4857dc...3e097b )
by Songda
03:57 queued 01:53
created

QueryPlugin   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 26 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Unipay\Open\Pay\QrCode;
6
7
use Closure;
8
use Yansongda\Pay\Contract\PluginInterface;
9
use Yansongda\Pay\Exception\ContainerException;
10
use Yansongda\Pay\Exception\ServiceNotFoundException;
11
use Yansongda\Pay\Logger;
12
use Yansongda\Pay\Packer\QueryPacker;
13
use Yansongda\Pay\Rocket;
14
15
use function Yansongda\Pay\get_unipay_config;
16
17
/**
18
 * @see https://open.unionpay.com/tjweb/acproduct/APIList?acpAPIId=792&apiservId=468&version=V2.2&bussType=0
19
 */
20
class QueryPlugin implements PluginInterface
21
{
22
    /**
23
     * @throws ContainerException
24
     * @throws ServiceNotFoundException
25
     */
26
    public function assembly(Rocket $rocket, Closure $next): Rocket
27
    {
28
        Logger::debug('[Unipay][Pay][QrCode][QueryPlugin] 插件开始装载', ['rocket' => $rocket]);
29
30
        $params = $rocket->getParams();
31
        $config = get_unipay_config($params);
32
        $payload = $rocket->getPayload();
33
34
        $rocket->setPacker(QueryPacker::class)
35
            ->mergePayload([
36
                '_url' => 'gateway/api/backTransReq.do',
37
                '_sandbox_url' => 'https://101.231.204.80:5000/gateway/api/backTransReq.do',
38
                'encoding' => 'utf-8',
39
                'signature' => '',
40
                'bizType' => $payload?->get('bizType') ?? '000000',
41
                'accessType' => $payload?->get('accessType') ?? '0',
42
                'merId' => $config['mch_id'] ?? '',
43
                'signMethod' => '01',
44
                'txnType' => $payload?->get('txnType') ?? '00',
45
                'txnSubType' => $payload?->get('txnSubType') ?? '00',
46
                'version' => '5.1.0',
47
            ]);
48
49
        Logger::info('[Unipay][Pay][QrCode][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]);
50
51
        return $next($rocket);
52
    }
53
}
54