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

Client::submitApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
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 submitApplication(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
47
        return $this->safeRequest('applyment/micro/submit', $params);
48
    }
49
50
    /**
51
     * query application status.
52
     *
53
     * @param string $applymentId
54
     * @param string $businessCode
55
     *
56
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
57
     *
58
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
59
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
60
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
61
     */
62
    public function getStatus(string $applymentId, string $businessCode = '')
63
    {
64
        if (!empty($applymentId)) {
65
            $params = [
66
                'applyment_id' => $applymentId,
67
            ];
68
        } else {
69
            $params = [
70
                'business_code' => $businessCode,
71
            ];
72
        }
73
74
        $params = array_merge($params, [
75
            'version' => '1.0',
76
            'sign_type' => 'HMAC-SHA256',
77
            'nonce_str' => uniqid('micro'),
78
        ]);
79
80
        return $this->safeRequest('applyment/micro/getstate', $params);
81
    }
82
83
    /**
84
     * merchant upgrade api.
85
     *
86
     * @param array $params
87
     *
88
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
89
     *
90
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
91
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
92
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\EncryptException
93
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidExtensionException
94
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
95
     * @throws \Psr\SimpleCache\InvalidArgumentException
96
     */
97
    public function upgrade(array $params)
98
    {
99
        $params['sub_mch_id'] = $params['sub_mch_id'] ?? $this->app['config']->sub_mch_id;
100
        $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...
101
            'version' => '1.0',
102
            'cert_sn' => '',
103
            'sign_type' => 'HMAC-SHA256',
104
            'nonce_str' => uniqid('micro'),
105
        ]));
106
107
        return $this->safeRequest('applyment/micro/submitupgrade', $params);
108
    }
109
110
    /**
111
     * get upgrade status.
112
     *
113
     * @param string $subMchId
114
     *
115
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
116
     *
117
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
118
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
119
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
120
     */
121
    public function getUpgradeStatus(string $subMchId = '')
122
    {
123
        return $this->safeRequest('applyment/micro/getupgradestate', [
124
            'version' => '1.0',
125
            'sign_type' => 'HMAC-SHA256',
126
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
127
            'nonce_str' => uniqid('micro'),
128
        ]);
129
    }
130
}
131