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

Client::bindAppId()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 1
nop 3
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 3
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\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
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
36
     */
37
    public function recommendConf(string $subAppid, string $subscribeAppid, string $receiptAppid = '')
38
    {
39
        $params = [
40
            'sub_appid' => $subAppid,
41
        ];
42
43
        if (!empty($subscribeAppid)) {
44
            $params['subscribe_appid'] = $subscribeAppid;
45
        } else {
46
            $params['receipt_appid'] = $receiptAppid;
47
        }
48
49
        return $this->safeRequest('secapi/mkt/addrecommendconf', array_merge($params, [
50
            'sign_type' => 'HMAC-SHA256',
51
            'nonce_str' => uniqid('micro'),
52
        ]));
53
    }
54
55
    /**
56
     * Configure the new payment directory.
57
     *
58
     * @param string $jsapiPath
59
     * @param string $appid
60
     * @param string $subMchId
61
     *
62
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
63
     *
64
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
65
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
66
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
67
     */
68 1
    public function addPath(string $jsapiPath, string $appid = '', string $subMchId = '')
69
    {
70 1
        return $this->addSubDevConfig([
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
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
89
     */
90 1
    public function bindAppId(string $subAppid, string $appid = '', string $subMchId = '')
91
    {
92 1
        return $this->addSubDevConfig([
93 1
            'appid' => $appid ?: $this->app['config']->appid,
94 1
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
95 1
            'sub_appid' => $subAppid,
96
        ]);
97
    }
98
99
    /**
100
     * add sub dev config.
101
     *
102
     * @param $params
103
     *
104
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
105
     *
106
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
107
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
108
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
109
     */
110 2
    private function addSubDevConfig($params)
111
    {
112 2
        return $this->safeRequest('secapi/mch/addsubdevconfig', $params);
113
    }
114
115
    /**
116
     * querySubDevConfig.
117
     *
118
     * @param $subMchId
119
     *
120
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
121
     *
122
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
123
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
124
     * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
125
     */
126 1
    public function querySubDevConfig($subMchId = '')
127
    {
128 1
        return $this->safeRequest('secapi/mch/querysubdevconfig', [
129 1
            'sub_mch_id' => $subMchId ?: $this->app['config']->sub_mch_id,
130
        ]);
131
    }
132
}
133