1
|
|
|
<?php |
2
|
|
|
namespace Wechat\API; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* 微信用户分组相关接口. |
6
|
|
|
* |
7
|
|
|
* @author Tian. |
8
|
|
|
*/ |
9
|
|
|
class GroupsApi extends BaseApi |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* 创建用户组. |
13
|
|
|
* |
14
|
|
|
* @param string $name 分组名 30字符以内 |
15
|
|
|
* |
16
|
|
|
* @return array id 分组ID , name 分组名. |
17
|
|
|
*/ |
18
|
|
|
public function create($name) |
19
|
|
|
{ |
20
|
|
|
if (!is_string($name) || strlen($name) >= 30) { |
21
|
|
|
$this->setError('参数错误,请传入字符串或名字的长度不能大于30字符'); |
22
|
|
|
|
23
|
|
|
return false; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$queryStr = [ |
27
|
|
|
'group' => ['name' => $name], |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
$res = $this->_post('create', $queryStr); |
31
|
|
|
|
32
|
|
|
return $res; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* 查询分组 |
37
|
|
|
* |
38
|
|
|
* @return array 所有分组信息 如没有分组返回false. |
39
|
|
|
*/ |
40
|
|
|
public function get() |
41
|
|
|
{ |
42
|
|
|
$queryStr = []; |
43
|
|
|
|
44
|
|
|
$res = $this->_get('get', $queryStr); |
45
|
|
|
|
46
|
|
|
return $res; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* 查询用户所在分组 |
51
|
|
|
* |
52
|
|
|
* @param string $openid 用户ID |
53
|
|
|
* |
54
|
|
|
* @return int. |
|
|
|
|
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function getid($openid) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
if (!$openid) { |
59
|
|
|
$this->setError('参数错误,缺少Openid'); |
60
|
|
|
|
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$queryStr = ['openid' => $openid]; |
65
|
|
|
|
66
|
|
|
$res = $this->_post('getid', $queryStr); |
67
|
|
|
|
68
|
|
|
return $res; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* 修改分组名 |
73
|
|
|
* |
74
|
|
|
* @param int|string $id 分组ID,$name 分组名 |
75
|
|
|
* |
76
|
|
|
* @return bool. |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
public function update($id, $name) |
79
|
|
|
{ |
80
|
|
|
if (!is_numeric($id) || !is_string($name) || strlen($name) >= 30) { |
81
|
|
|
$this->setError('参数错误,分组ID不是数字或分组名不是有效的字符串或名字的长度大于30字符'); |
82
|
|
|
|
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$queryStr = [ |
87
|
|
|
'group' => ['id' => $id, 'name' => $name], |
88
|
|
|
]; |
89
|
|
|
|
90
|
|
|
$res = $this->_post('update', $queryStr); |
91
|
|
|
|
92
|
|
|
return $res; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* 删除指定分组 |
97
|
|
|
* |
98
|
|
|
* @param int $id 分组ID |
99
|
|
|
* |
100
|
|
|
* @return bool. 注:删除成功时返回的是 '' ,删除失败时返回的是false,(包括分组ID不是数字或分组ID已经不存在) |
|
|
|
|
101
|
|
|
*/ |
102
|
|
View Code Duplication |
public function delete($id) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
if (!is_numeric($id)) { |
105
|
|
|
$this->setError('参数错误,分组ID不是数字'); |
106
|
|
|
|
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$queryStr = [ |
111
|
|
|
'group' => ['id' => $id], |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
$res = $this->_post('delete', $queryStr); |
115
|
|
|
|
116
|
|
|
return $res; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* 移动用户到指定分组 |
121
|
|
|
* |
122
|
|
|
* @param string $openid 用户ID,to_groupid 指定分组ID |
123
|
|
|
* |
124
|
|
|
* @return bool. |
125
|
|
|
*/ |
|
|
|
|
126
|
|
|
|
127
|
|
View Code Duplication |
public function moveUser($openid, $to_groupid) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
if (!is_numeric($to_groupid) || !is_string($openid)) { |
130
|
|
|
$this->setError('参数错误,用户ID格式不正确或组ID不是数字'); |
131
|
|
|
|
132
|
|
|
return false; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$queryStr = ['openid' => $openid, 'to_groupid' => $to_groupid]; |
136
|
|
|
|
137
|
|
|
$res = $this->_post('members/update', $queryStr); |
138
|
|
|
|
139
|
|
|
return $res; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* 批量移动用户到指定分组 |
144
|
|
|
* |
145
|
|
|
* @param array $openid_list 用户ID,to_groupid 指定分组ID |
146
|
|
|
* |
147
|
|
|
* @return bool. 注:其中批量移动时,其中有一个用户的id是错的,那么其他的也不会移动,若用户已经在目标组里那么返回值也是true |
|
|
|
|
148
|
|
|
*/ |
149
|
|
View Code Duplication |
public function MoveUserlistGroup($openid_list, $to_groupid) |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
if (!is_array($openid_list)) { |
152
|
|
|
$this->setError('参数必须为一个数组'); |
153
|
|
|
|
154
|
|
|
return false; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$queryStr = ['openid_list' => $openid_list, 'to_groupid' => $to_groupid]; |
158
|
|
|
|
159
|
|
|
$res = $this->_post('members/batchupdate', $queryStr); |
160
|
|
|
|
161
|
|
|
return $res; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.