Completed
Push — master ( fd42ea...71ecec )
by Carlos
03:07
created

UserClient::changeOpenid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
ccs 0
cts 0
cp 0
crap 2
rs 9.4285
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\OfficialAccount\User;
13
14
use EasyWeChat\Kernel\BaseClient;
15
16
/**
17
 * Class UserClient.
18
 *
19
 * @author overtrue <[email protected]>
20
 */
21
class UserClient extends BaseClient
22
{
23
    /**
24
     * Fetch a user by open id.
25
     *
26
     * @param string $openid
27
     * @param string $lang
28
     *
29
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
30
     *
31
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
32
     */
33
    public function get(string $openid, string $lang = 'zh_CN')
34
    {
35
        $params = [
36
            'openid' => $openid,
37
            'lang' => $lang,
38
        ];
39
40
        return $this->httpGet('cgi-bin/user/info', $params);
41
    }
42
43
    /**
44
     * Batch get users.
45
     *
46
     * @param array  $openids
47
     * @param string $lang
48
     *
49
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
50
     *
51
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
52
     */
53
    public function select(array $openids, string $lang = 'zh_CN')
54
    {
55
        return $this->httpPostJson('cgi-bin/user/info/batchget', [
56
            'user_list' => array_map(function ($openid) use ($lang) {
57
                return [
58
                    'openid' => $openid,
59
                    'lang' => $lang,
60
                ];
61
            }, $openids),
62
        ]);
63
    }
64
65
    /**
66
     * List users.
67
     *
68
     * @param string $nextOpenId
69
     *
70
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
71
     *
72
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
73
     */
74
    public function list(string $nextOpenId = null)
75
    {
76
        $params = ['next_openid' => $nextOpenId];
77
78
        return $this->httpGet('cgi-bin/user/get', $params);
79
    }
80
81
    /**
82
     * Set user remark.
83
     *
84
     * @param string $openid
85
     * @param string $remark
86
     *
87
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
88
     *
89
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
90
     */
91
    public function remark(string $openid, string $remark)
92
    {
93
        $params = [
94
            'openid' => $openid,
95
            'remark' => $remark,
96
        ];
97
98
        return $this->httpPostJson('cgi-bin/user/info/updateremark', $params);
99
    }
100
101
    /**
102
     * Get black list.
103
     *
104
     * @param string|null $beginOpenid
105
     *
106
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
107
     *
108
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
109
     */
110
    public function blacklist(string $beginOpenid = null)
111
    {
112
        $params = ['begin_openid' => $beginOpenid];
113
114
        return $this->httpPostJson('cgi-bin/tags/members/getblacklist', $params);
115
    }
116
117
    /**
118
     * Batch block user.
119
     *
120
     * @param array|string $openidList
121
     *
122
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
123
     *
124
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
125
     */
126
    public function block($openidList)
127
    {
128
        $params = ['openid_list' => (array) $openidList];
129
130
        return $this->httpPostJson('cgi-bin/tags/members/batchblacklist', $params);
131
    }
132
133
    /**
134
     * Batch unblock user.
135
     *
136
     * @param array $openidList
137
     *
138
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
139
     *
140
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
141
     */
142
    public function unblock($openidList)
143
    {
144
        $params = ['openid_list' => (array) $openidList];
145
146
        return $this->httpPostJson('cgi-bin/tags/members/batchunblacklist', $params);
147
    }
148
149
    /**
150
     * @param string $oldAppId
151
     * @param array  $openidList
152
     *
153
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
154
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
155
     */
156
    public function changeOpenid(string $oldAppId, array $openidList)
157
    {
158
        $params = [
159
            'from_appid' => $oldAppId,
160
            'openid_list' => $openidList,
161
        ];
162
163
        return $this->httpPostJson('cgi-bin/changeopenid', $params);
164
    }
165
}
166