Completed
Pull Request — master (#1556)
by wannanbigpig
04:10
created

Client::upgrade()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\MicroMerchant\Base;
13
14
use EasyWeChat\MicroMerchant\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @author   liuml  <[email protected]>
20
 * @DateTime 2019-05-30  14:19
21
 */
22
class Client extends BaseClient
23
{
24
    /**
25
     * apply to settle in to become a small micro merchant.
26
     *
27
     * @param  $params
28
     *
29
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
30
     *
31
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
32
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
33
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\EncryptException
34
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidExtensionException
35
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
36
     * @throws \Psr\SimpleCache\InvalidArgumentException
37
     */
38
    public function applyForEnter(array $params)
39
    {
40
        $params = $this->processParams(array_merge($params, [
41
            'version' => '3.0',
42
            'cert_sn' => '',
43
            'sign_type' => 'HMAC-SHA256',
44
            'nonce_str' => uniqid('micro'),
45
        ]));
46
        return $this->safeRequest('applyment/micro/submit', $params);
47
    }
48
49
    /**
50
     * query application status.
51
     *
52
     * @param  string  $applymentId
53
     * @param  string  $businessCode
54
     *
55
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
56
     *
57
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
58
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
59
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
60
     */
61
    public function getStatus(string $applymentId, string $businessCode = '')
62
    {
63
        if (!empty($applymentId)) {
64
            $params = [
65
                'applyment_id' => $applymentId,
66
            ];
67
        } else {
68
            $params = [
69
                'business_code' => $businessCode,
70
            ];
71
        }
72
73
        $params = array_merge($params, [
74
            'version' => '1.0',
75
            'sign_type' => 'HMAC-SHA256',
76
            'nonce_str' => uniqid('micro'),
77
        ]);
78
        return $this->safeRequest('applyment/micro/getstate', $params);
79
    }
80
81
    /**
82
     * merchant upgrade api.
83
     *
84
     * @param  array  $params
85
     *
86
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
87
     *
88
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
89
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
90
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\EncryptException
91
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidExtensionException
92
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
93
     * @throws \Psr\SimpleCache\InvalidArgumentException
94
     */
95
    public function upgrade(array $params)
96
    {
97
        $params['sub_mch_id'] = $params['sub_mch_id'] ?? $this->app['config']->sub_mch_id;
98
        $params = $this->processParams(array_merge($params, [
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
99
            'version' => '1.0',
100
            'cert_sn' => '',
101
            'sign_type' => 'HMAC-SHA256',
102
            'nonce_str' => uniqid('micro'),
103
        ]));
104
        return $this->safeRequest('applyment/micro/submitupgrade', $params);
105
    }
106
107
    /**
108
     * get upgrade status.
109
     *
110
     * @param  string  $subMchId
111
     *
112
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
113
     *
114
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
115
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
116
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
117
     */
118
    public function getUpgradeStatus(string $subMchId = '')
119
    {
120
        return $this->safeRequest('applyment/micro/getupgradestate', [
121
            'version' => '1.0',
122
            'sign_type' => 'HMAC-SHA256',
123
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
124
            'nonce_str' => uniqid('micro'),
125
        ]);
126
    }
127
}
128