Completed
Pull Request — master (#1556)
by wannanbigpig
07:00 queued 03:07
created

Client   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 105
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 12

5 Methods

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