Passed
Pull Request — master (#1647)
by
11:06
created

Client   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 64%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
eloc 23
c 4
b 2
f 0
dl 0
loc 107
ccs 16
cts 25
cp 0.64
rs 10
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 5 3
A addConfig() 0 3 1
A bindAppId() 0 6 3
A addPath() 0 6 3
A setFollowConfig() 0 16 3
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\MerchantConfig;
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
     * Service providers configure recommendation functions for small and micro businesses.
26
     *
27
     * @param string $subAppId
28
     * @param string $subscribeAppId
29
     * @param string $receiptAppId
30
     * @param string $subMchId
31
     *
32
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
33
     *
34
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
35
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
36
     */
37
    public function setFollowConfig(string $subAppId, string $subscribeAppId, string $receiptAppId = '', string $subMchId = '')
38
    {
39
        $params = [
40
            'sub_appid' => $subAppId,
41
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
42
        ];
43
44
        if (!empty($subscribeAppid)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $subscribeAppid does not exist. Did you maybe mean $subscribeAppId?
Loading history...
45
            $params['subscribe_appid'] = $subscribeAppId;
46
        } else {
47
            $params['receipt_appid'] = $receiptAppId;
48
        }
49
50
        return $this->safeRequest('secapi/mkt/addrecommendconf', array_merge($params, [
51
            'sign_type' => 'HMAC-SHA256',
52
            'nonce_str' => uniqid('micro'),
53
        ]));
54
    }
55
56
    /**
57
     * Configure the new payment directory.
58
     *
59
     * @param string $jsapiPath
60
     * @param string $appId
61
     * @param string $subMchId
62
     *
63
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
64
     *
65
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
66
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
67
     */
68 1
    public function addPath(string $jsapiPath, string $appId = '', string $subMchId = '')
69
    {
70 1
        return $this->addConfig([
71 1
            'appid' => $appId ?: $this->app['config']->appid,
72 1
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
73 1
            'jsapi_path' => $jsapiPath,
74
        ]);
75
    }
76
77
    /**
78
     * bind appid.
79
     *
80
     * @param string $subAppId
81
     * @param string $appId
82
     * @param string $subMchId
83
     *
84
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
85
     *
86
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
87
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
88
     */
89 1
    public function bindAppId(string $subAppId, string $appId = '', string $subMchId = '')
90
    {
91 1
        return $this->addConfig([
92 1
            'appid' => $appId ?: $this->app['config']->appid,
93 1
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
94 1
            'sub_appid' => $subAppId,
95
        ]);
96
    }
97
98
    /**
99
     * add sub dev config.
100
     *
101
     * @param array $params
102
     *
103
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
104
     *
105
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
106
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
107
     */
108 2
    private function addConfig(array $params)
109
    {
110 2
        return $this->safeRequest('secapi/mch/addsubdevconfig', $params);
111
    }
112
113
    /**
114
     * query Sub Dev Config.
115
     *
116
     * @param string $subMchId
117
     * @param string $appId
118
     *
119
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
120
     *
121
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
122
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
123
     */
124 1
    public function getConfig(string $subMchId = '', string $appId = '')
125
    {
126 1
        return $this->safeRequest('secapi/mch/querysubdevconfig', [
127 1
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
128 1
            'appid' => $appId ?: $this->app['config']->appid,
129
        ]);
130
    }
131
}
132