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
|
1 |
|
public function get(string $openid, string $lang = 'zh_CN') |
34
|
|
|
{ |
35
|
|
|
$params = [ |
36
|
1 |
|
'openid' => $openid, |
37
|
1 |
|
'lang' => $lang, |
38
|
|
|
]; |
39
|
|
|
|
40
|
1 |
|
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
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
53
|
|
|
*/ |
54
|
1 |
|
public function select(array $openids, string $lang = 'zh_CN') |
55
|
|
|
{ |
56
|
1 |
|
return $this->httpPostJson('cgi-bin/user/info/batchget', [ |
57
|
1 |
|
'user_list' => array_map(function ($openid) use ($lang) { |
58
|
|
|
return [ |
59
|
1 |
|
'openid' => $openid, |
60
|
1 |
|
'lang' => $lang, |
61
|
|
|
]; |
62
|
1 |
|
}, $openids), |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* List users. |
68
|
|
|
* |
69
|
|
|
* @param string $nextOpenId |
70
|
|
|
* |
71
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
72
|
|
|
* |
73
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
74
|
|
|
*/ |
75
|
1 |
|
public function list(string $nextOpenId = null) |
76
|
|
|
{ |
77
|
1 |
|
$params = ['next_openid' => $nextOpenId]; |
78
|
|
|
|
79
|
1 |
|
return $this->httpGet('cgi-bin/user/get', $params); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set user remark. |
84
|
|
|
* |
85
|
|
|
* @param string $openid |
86
|
|
|
* @param string $remark |
87
|
|
|
* |
88
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
89
|
|
|
* |
90
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
91
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
92
|
|
|
*/ |
93
|
1 |
|
public function remark(string $openid, string $remark) |
94
|
|
|
{ |
95
|
|
|
$params = [ |
96
|
1 |
|
'openid' => $openid, |
97
|
1 |
|
'remark' => $remark, |
98
|
|
|
]; |
99
|
|
|
|
100
|
1 |
|
return $this->httpPostJson('cgi-bin/user/info/updateremark', $params); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get black list. |
105
|
|
|
* |
106
|
|
|
* @param string|null $beginOpenid |
107
|
|
|
* |
108
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
109
|
|
|
* |
110
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
111
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
112
|
|
|
*/ |
113
|
1 |
|
public function blacklist(string $beginOpenid = null) |
114
|
|
|
{ |
115
|
1 |
|
$params = ['begin_openid' => $beginOpenid]; |
116
|
|
|
|
117
|
1 |
|
return $this->httpPostJson('cgi-bin/tags/members/getblacklist', $params); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Batch block user. |
122
|
|
|
* |
123
|
|
|
* @param array|string $openidList |
124
|
|
|
* |
125
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
126
|
|
|
* |
127
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
128
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
129
|
|
|
*/ |
130
|
1 |
|
public function block($openidList) |
131
|
|
|
{ |
132
|
1 |
|
$params = ['openid_list' => (array) $openidList]; |
133
|
|
|
|
134
|
1 |
|
return $this->httpPostJson('cgi-bin/tags/members/batchblacklist', $params); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Batch unblock user. |
139
|
|
|
* |
140
|
|
|
* @param array $openidList |
141
|
|
|
* |
142
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
143
|
|
|
* |
144
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
145
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
146
|
|
|
*/ |
147
|
1 |
|
public function unblock($openidList) |
148
|
|
|
{ |
149
|
1 |
|
$params = ['openid_list' => (array) $openidList]; |
150
|
|
|
|
151
|
1 |
|
return $this->httpPostJson('cgi-bin/tags/members/batchunblacklist', $params); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param string $oldAppId |
156
|
|
|
* @param array $openidList |
157
|
|
|
* |
158
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
159
|
|
|
* |
160
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
161
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
162
|
|
|
*/ |
163
|
1 |
|
public function changeOpenid(string $oldAppId, array $openidList) |
164
|
|
|
{ |
165
|
|
|
$params = [ |
166
|
1 |
|
'from_appid' => $oldAppId, |
167
|
1 |
|
'openid_list' => $openidList, |
168
|
|
|
]; |
169
|
|
|
|
170
|
1 |
|
return $this->httpPostJson('cgi-bin/changeopenid', $params); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|