Completed
Pull Request — master (#1556)
by wannanbigpig
14:01
created

Client::getState()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 2
dl 0
loc 18
rs 9.9
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
class Client extends BaseClient
17
{
18
    /**
19
     * apply to settle in to become a small micro merchant.
20
     *
21
     * @param  $params
22
     *
23
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
24
     *
25
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
26
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
27
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\EncryptException
28
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidExtensionException
29
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
30
     * @throws \Psr\SimpleCache\InvalidArgumentException
31
     */
32
    public function applyForEnter(array $params)
33
    {
34
        $params = $this->processingParams(array_merge($params, [
35
            'version'   => '3.0',
36
            'cert_sn'   => '',
37
            'sign_type' => 'HMAC-SHA256',
38
            'nonce_str' => uniqid('micro'),
39
        ]));
40
        return $this->safeRequest('applyment/micro/submit', $params);
41
    }
42
43
    /**
44
     * query application status.
45
     *
46
     * @param  string  $applyment_id
47
     * @param  string  $business_code
48
     *
49
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
50
     *
51
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
52
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
53
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
54
     */
55
    public function getState(string $applyment_id, string $business_code = '')
56
    {
57
        if (!empty($applyment_id)) {
58
            $params = [
59
                'applyment_id' => $applyment_id,
60
            ];
61
        } else {
62
            $params = [
63
                'business_code' => $business_code,
64
            ];
65
        }
66
67
        $params = array_merge($params, [
68
            'version'   => '1.0',
69
            'sign_type' => 'HMAC-SHA256',
70
            'nonce_str' => uniqid('micro'),
71
        ]);
72
        return $this->safeRequest('applyment/micro/getstate', $params);
73
    }
74
75
    /**
76
     * merchant upgrade api.
77
     *
78
     * @param  array  $params
79
     *
80
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
81
     *
82
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
83
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
84
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\EncryptException
85
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidExtensionException
86
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
87
     * @throws \Psr\SimpleCache\InvalidArgumentException
88
     */
89
    public function upgrade(array $params)
90
    {
91
        $params['sub_mch_id'] = $params['sub_mch_id'] ?? $this->app['config']->sub_mch_id;
92
        $params               = $this->processingParams(array_merge($params, [
93
            'version'   => '1.0',
94
            'cert_sn'   => '',
95
            'sign_type' => 'HMAC-SHA256',
96
            'nonce_str' => uniqid('micro'),
97
        ]));
98
        return $this->safeRequest('applyment/micro/submitupgrade', $params);
99
    }
100
101
    /**
102
     * get upgrade state.
103
     *
104
     * @param  string  $sub_mch_id
105
     *
106
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
107
     *
108
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
109
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
110
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
111
     */
112
    public function getUpgradeState(string $sub_mch_id = '')
113
    {
114
        return $this->safeRequest('applyment/micro/getupgradestate', [
115
            'version'    => '1.0',
116
            'sign_type'  => 'HMAC-SHA256',
117
            'sub_mch_id' => $sub_mch_id ? : $this->app['config']->sub_mch_id,
118
            'nonce_str'  => uniqid('micro'),
119
        ]);
120
    }
121
}
122