Client   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 30
dl 0
loc 102
ccs 0
cts 30
cp 0
rs 10
c 3
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getStatus() 0 19 2
A getUpgradeStatus() 0 7 2
A upgrade() 0 11 1
A submitApplication() 0 10 1
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 array $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 \GuzzleHttp\Exception\GuzzleException
35
     */
36
    public function submitApplication(array $params)
37
    {
38
        $params = $this->processParams(array_merge($params, [
39
            'version' => '3.0',
40
            'cert_sn' => '',
41
            'sign_type' => 'HMAC-SHA256',
42
            'nonce_str' => uniqid('micro'),
43
        ]));
44
45
        return $this->safeRequest('applyment/micro/submit', $params);
46
    }
47
48
    /**
49
     * query application status.
50
     *
51
     * @param string $applymentId
52
     * @param string $businessCode
53
     *
54
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
55
     *
56
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
57
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
58
     * @throws \GuzzleHttp\Exception\GuzzleException
59
     */
60
    public function getStatus(string $applymentId, string $businessCode = '')
61
    {
62
        if (!empty($applymentId)) {
63
            $params = [
64
                'applyment_id' => $applymentId,
65
            ];
66
        } else {
67
            $params = [
68
                'business_code' => $businessCode,
69
            ];
70
        }
71
72
        $params = array_merge($params, [
73
            'version' => '1.0',
74
            'sign_type' => 'HMAC-SHA256',
75
            'nonce_str' => uniqid('micro'),
76
        ]);
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 \GuzzleHttp\Exception\GuzzleException
92
     */
93
    public function upgrade(array $params)
94
    {
95
        $params['sub_mch_id'] = $params['sub_mch_id'] ?? $this->app['config']->sub_mch_id;
96
        $params = $this->processParams(array_merge($params, [
97
            'version' => '1.0',
98
            'cert_sn' => '',
99
            'sign_type' => 'HMAC-SHA256',
100
            'nonce_str' => uniqid('micro'),
101
        ]));
102
103
        return $this->safeRequest('applyment/micro/submitupgrade', $params);
104
    }
105
106
    /**
107
     * get upgrade status.
108
     *
109
     * @param string $subMchId
110
     *
111
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
112
     *
113
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
114
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
115
     * @throws \GuzzleHttp\Exception\GuzzleException
116
     */
117
    public function getUpgradeStatus(string $subMchId = '')
118
    {
119
        return $this->safeRequest('applyment/micro/getupgradestate', [
120
            'version' => '1.0',
121
            'sign_type' => 'HMAC-SHA256',
122
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
123
            'nonce_str' => uniqid('micro'),
124
        ]);
125
    }
126
}
127