Passed
Push — master ( 2154e0...fe1902 )
by Songda
01:54
created

InvokePrepayV2Plugin::getSign()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 16
rs 9.9332
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
/**
17
 * @see https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6
18
 */
19
class InvokePrepayV2Plugin extends InvokePrepayPlugin
20
{
21
    /**
22
     * @throws ContainerException
23
     * @throws ServiceNotFoundException
24
     * @throws Exception
25
     */
26
    protected function getInvokeConfig(Rocket $rocket, string $prepayId): Config
27
    {
28
        $config = new Config([
29
            'appId' => $this->getAppId($rocket),
30
            'timeStamp' => time().'',
31
            'nonceStr' => Str::random(32),
32
            'package' => 'prepay_id='.$prepayId,
33
            'signType' => 'MD5',
34
        ]);
35
36
        $config->set('paySign', get_wechat_sign_v2($rocket->getParams(), $config->toArray()));
37
38
        return $config;
39
    }
40
}
41