PayPlugin   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 22 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Unipay\Qra\Scan;
6
7
use Closure;
8
use Throwable;
9
use Yansongda\Artful\Contract\PluginInterface;
10
use Yansongda\Artful\Exception\ContainerException;
11
use Yansongda\Artful\Exception\ServiceNotFoundException;
12
use Yansongda\Artful\Logger;
13
use Yansongda\Artful\Packer\XmlPacker;
14
use Yansongda\Artful\Rocket;
15
use Yansongda\Supports\Str;
16
17
use function Yansongda\Pay\get_provider_config;
18
19
/**
20
 * @see https://up.95516.com/open/openapi/doc?index_1=1&index_2=1&chapter_1=235&chapter_2=253
21
 */
22
class PayPlugin implements PluginInterface
23
{
24
    /**
25
     * @throws ContainerException
26
     * @throws ServiceNotFoundException
27
     * @throws Throwable                随机数生成失败
28
     */
29
    public function assembly(Rocket $rocket, Closure $next): Rocket
30
    {
31
        Logger::debug('[Unipay][Qra][Scan][PayPlugin] 插件开始装载', ['rocket' => $rocket]);
32
33
        $params = $rocket->getParams();
34
        $config = get_provider_config('unipay', $params);
35
        $payload = $rocket->getPayload();
36
37
        $rocket->setPacker(XmlPacker::class)
38
            ->mergePayload([
39
                '_url' => 'https://qra.95516.com/pay/gateway',
40
                'service' => 'unified.trade.native',
41
                'charset' => 'UTF-8',
42
                'sign_type' => 'MD5',
43
                'mch_id' => $config['mch_id'] ?? '',
44
                'notify_url' => $payload?->get('notify_url') ?? $config['notify_url'] ?? '',
45
                'nonce_str' => Str::random(32),
46
            ]);
47
48
        Logger::info('[Unipay][Qra][Scan][PayPlugin] 插件装载完毕', ['rocket' => $rocket]);
49
50
        return $next($rocket);
51
    }
52
}
53