Passed
Pull Request — master (#772)
by Songda
01:56
created

InvokePrepayV2Plugin::getAppId()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
6
7
use Exception;
8
use Yansongda\Pay\Exception\ContainerException;
9
use Yansongda\Pay\Exception\ServiceNotFoundException;
10
use Yansongda\Pay\Rocket;
11
use Yansongda\Supports\Config;
12
use Yansongda\Supports\Str;
13
14
use function Yansongda\Pay\get_wechat_sign_v2;
15
16
class InvokePrepayV2Plugin extends InvokePrepayPlugin
17
{
18
    /**
19
     * @throws ContainerException
20
     * @throws ServiceNotFoundException
21
     * @throws Exception
22
     */
23
    protected function getInvokeConfig(Rocket $rocket, string $prepayId): Config
24
    {
25
        $config = new Config([
26
            'appId' => $this->getAppId($rocket),
27
            'timeStamp' => time().'',
28
            'nonceStr' => Str::random(32),
29
            'package' => 'prepay_id='.$prepayId,
30
            'signType' => 'MD5',
31
        ]);
32
33
        $config->set('paySign', get_wechat_sign_v2($rocket->getParams(), $config->toArray()));
34
35
        return $config;
36
    }
37
}
38