|
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
|
|
|
/** |
|
13
|
|
|
* User.php. |
|
14
|
|
|
* |
|
15
|
|
|
* @author overtrue <[email protected]> |
|
16
|
|
|
* @copyright 2015 overtrue <[email protected]> |
|
17
|
|
|
* |
|
18
|
|
|
* @see https://github.com/overtrue |
|
19
|
|
|
* @see http://overtrue.me |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace EasyWeChat\User; |
|
23
|
|
|
|
|
24
|
|
|
use EasyWeChat\Core\AbstractAPI; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class User. |
|
28
|
|
|
*/ |
|
29
|
|
|
class User extends AbstractAPI |
|
30
|
|
|
{ |
|
31
|
|
|
const API_GET = 'https://api.weixin.qq.com/cgi-bin/user/info'; |
|
32
|
|
|
const API_BATCH_GET = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget'; |
|
33
|
|
|
const API_LIST = 'https://api.weixin.qq.com/cgi-bin/user/get'; |
|
34
|
|
|
const API_GROUP = 'https://api.weixin.qq.com/cgi-bin/groups/getid'; |
|
35
|
|
|
const API_REMARK = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark'; |
|
36
|
|
|
const API_OAUTH_GET = 'https://api.weixin.qq.com/sns/userinfo'; |
|
37
|
|
|
const API_GET_BLACK_LIST = 'https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist'; |
|
38
|
|
|
const API_BATCH_BLACK_LIST = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist'; |
|
39
|
|
|
const API_BATCH_UNBLACK_LIST = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Fetch a user by open id. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $openId |
|
45
|
|
|
* @param string $lang |
|
46
|
|
|
* |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
1 |
View Code Duplication |
public function get($openId, $lang = 'zh_CN') |
|
50
|
|
|
{ |
|
51
|
|
|
$params = [ |
|
52
|
1 |
|
'openid' => $openId, |
|
53
|
1 |
|
'lang' => $lang, |
|
54
|
1 |
|
]; |
|
55
|
|
|
|
|
56
|
1 |
|
return $this->parseJSON('get', [self::API_GET, $params]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Batch get users. |
|
61
|
|
|
* |
|
62
|
|
|
* @param array $openIds |
|
63
|
|
|
* @param string $lang |
|
64
|
|
|
* |
|
65
|
|
|
* @return \EasyWeChat\Support\Collection |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function batchGet(array $openIds, $lang = 'zh_CN') |
|
68
|
|
|
{ |
|
69
|
1 |
|
$params = []; |
|
70
|
|
|
|
|
71
|
1 |
|
$params['user_list'] = array_map(function ($openId) use ($lang) { |
|
72
|
|
|
return [ |
|
73
|
1 |
|
'openid' => $openId, |
|
74
|
1 |
|
'lang' => $lang, |
|
75
|
1 |
|
]; |
|
76
|
1 |
|
}, $openIds); |
|
77
|
|
|
|
|
78
|
1 |
|
return $this->parseJSON('json', [self::API_BATCH_GET, $params]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* List users. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $nextOpenId |
|
85
|
|
|
* |
|
86
|
|
|
* @return \EasyWeChat\Support\Collection |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function lists($nextOpenId = null) |
|
89
|
|
|
{ |
|
90
|
1 |
|
$params = ['next_openid' => $nextOpenId]; |
|
91
|
|
|
|
|
92
|
1 |
|
return $this->parseJSON('get', [self::API_LIST, $params]); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Set user remark. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $openId |
|
99
|
|
|
* @param string $remark |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
1 |
View Code Duplication |
public function remark($openId, $remark) |
|
104
|
|
|
{ |
|
105
|
|
|
$params = [ |
|
106
|
1 |
|
'openid' => $openId, |
|
107
|
1 |
|
'remark' => $remark, |
|
108
|
1 |
|
]; |
|
109
|
|
|
|
|
110
|
1 |
|
return $this->parseJSON('json', [self::API_REMARK, $params]); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get user's group id. |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $openId |
|
117
|
|
|
* |
|
118
|
|
|
* @return int |
|
119
|
|
|
*/ |
|
120
|
1 |
|
public function group($openId) |
|
121
|
|
|
{ |
|
122
|
1 |
|
return $this->getGroup($openId); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get user's group. |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $openId |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
1 |
|
public function getGroup($openId) |
|
133
|
|
|
{ |
|
134
|
1 |
|
$params = ['openid' => $openId]; |
|
135
|
|
|
|
|
136
|
1 |
|
return $this->parseJSON('json', [self::API_GROUP, $params]); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Get black list. |
|
141
|
|
|
* |
|
142
|
|
|
* @param string|null $beginOpenid |
|
143
|
|
|
* |
|
144
|
|
|
* @return \EasyWeChat\Support\Collection |
|
145
|
|
|
*/ |
|
146
|
1 |
|
public function blacklist($beginOpenid = null) |
|
147
|
|
|
{ |
|
148
|
1 |
|
$params = ['begin_openid' => $beginOpenid]; |
|
149
|
|
|
|
|
150
|
1 |
|
return $this->parseJSON('json', [self::API_GET_BLACK_LIST, $params]); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Batch block user. |
|
155
|
|
|
* |
|
156
|
|
|
* @param array $openidList |
|
157
|
|
|
* |
|
158
|
|
|
* @return \EasyWeChat\Support\Collection |
|
159
|
|
|
*/ |
|
160
|
1 |
|
public function batchBlock(array $openidList) |
|
161
|
|
|
{ |
|
162
|
1 |
|
$params = ['openid_list' => $openidList]; |
|
163
|
|
|
|
|
164
|
1 |
|
return $this->parseJSON('json', [self::API_BATCH_BLACK_LIST, $params]); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Batch unblock user. |
|
169
|
|
|
* |
|
170
|
|
|
* @param array $openidList |
|
171
|
|
|
* |
|
172
|
|
|
* @return \EasyWeChat\Support\Collection |
|
173
|
|
|
*/ |
|
174
|
1 |
|
public function batchUnblock(array $openidList) |
|
175
|
|
|
{ |
|
176
|
1 |
|
$params = ['openid_list' => $openidList]; |
|
177
|
|
|
|
|
178
|
1 |
|
return $this->parseJSON('json', [self::API_BATCH_UNBLACK_LIST, $params]); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|