-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathGroup.php
More file actions
313 lines (298 loc) · 8.29 KB
/
Group.php
File metadata and controls
313 lines (298 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
/**
* Group module
* @author hejinyu
*/
namespace RongCloud\Lib\Group;
use RongCloud\Lib\Group\Gag\Gag;
use RongCloud\Lib\Group\MuteAllMembers\MuteAllMembers;
use RongCloud\Lib\Group\MuteWhiteList\MuteWhiteList;
use RongCloud\Lib\Group\Remark\Remark;
use RongCloud\Lib\Request;
use RongCloud\Lib\Utils;
class Group
{
/**
* Group module path
*
* @var string
*/
private $jsonPath = 'Lib/Group/';
/**
* Request configuration file
*
* @var string
*/
private $conf = '';
/**
* Validation configuration file
*
* @var string
*/
private $verify = '';
/**
* Conversation constructor.
*/
function __construct()
{
$this->conf = Utils::getJson($this->jsonPath.'api.json');
$this->verify = Utils::getJson($this->jsonPath.'verify.json');
}
/**
* Synchronize group information
*
* @param array $Group Synchronized group information parameter
* @param
* $Group = [
* 'id'=> 'ujadk90ha',//User ID
* 'groups'=>[['id'=> 'group9998', 'name'=> 'RongCloud']]//User group information
* ];
* @return array
*/
public function sync(array $Group=[]){
$conf = $this->conf['sync'];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'user',
'data'=> $Group,
'verify'=> $this->verify['user']
]);
if($error) return $error;
$data = [];
// $data['group'] = array_column($Group['groups'], 'name', 'id');
foreach ($Group['groups'] as $v){
$data["group[{$v['id']}]"] = $v['name'];
}
$data['userId'] = $Group['id'];
$result = (new Request())->Request($conf['url'],$data);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Create Group
*
* @param array $Group Parameters for creating a group
* @param
* $Group = [
* 'id'=> 'watergroup1',// Group ID
* 'name'=> 'watergroup',// Group name
* 'members'=>[ // List of group members
* ['id'=> 'group9991111113']
* ]
* ];
* @return array
*/
public function create(array $Group=[]){
$conf = $this->conf['create'];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'group',
'data'=> $Group,
'verify'=> $this->verify['group']
]);
if($error) return $error;
foreach ($Group['members'] as &$v){
$v = $v['id'];
}
$Group = (new Utils())->rename($Group, [
'id'=> 'groupId',
'name'=> 'groupName',
'members'=> 'userId',
]);
$result = (new Request())->Request($conf['url'],$Group);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Join a group
*
* @param array $Group Parameters for joining a group
* @param
* $Group = [
* 'id'=> 'watergroup',// Group ID
* 'name'=>"watergroup",// Group name
* 'member'=>['id'=> 'group999'],// Group member information
* ];
* @return array
*/
public function joins(array $Group=[]){
$conf = $this->conf['join'];
$verify = $this->verify['group'];
unset($verify['memberIds'],$verify['name']);
$verify = array_merge($verify,$this->verify['member']);
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'group',
'data'=> $Group,
'verify'=> $verify
]);
if($error) return $error;
$Group['member'] = isset($Group['member']['id'])?$Group['member']['id']:"";
$Group = (new Utils())->rename($Group, [
'id'=> 'groupId',
'name'=> 'groupName',
'member'=> 'userId',
]);
$result = (new Request())->Request($conf['url'],$Group);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Exit group
*
* @param array $Group Exit group parameter
* @param
* $Group = [
* 'id'=> 'watergroup',// Group id
* 'member'=>['id'=> 'group999'],// Group member information
* ];
* @return array
*/
public function quit(array $Group=[]){
$conf = $this->conf['quit'];
$verify = $this->verify['group'];
$verify = ['id'=>$verify['id']];
$verify = array_merge($verify,$this->verify['member']);
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'group',
'data'=> $Group,
'verify'=> $verify
]);
if($error) return $error;
$Group['member'] = isset($Group['member']['id'])?$Group['member']['id']:"";
$Group = (new Utils())->rename($Group, [
'id'=> 'groupId',
'member'=> 'userId',
]);
$result = (new Request())->Request($conf['url'],$Group);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Disband group
*
* @param array $Group Disband group parameter
* @param
* $Group = [
* 'id'=> 'watergroup',//Group ID
* 'member'=>['id'=> 'group999'],//Administrator information
* ];
* @return array
*/
public function dismiss(array $Group=[]){
$conf = $this->conf['dismiss'];
$verify = $this->verify['group'];
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'group',
'data'=> $Group,
'verify'=> $verify
]);
if($error) return $error;
$Group['member'] = isset($Group['member']['id'])?$Group['member']['id']:"";
$Group = (new Utils())->rename($Group, [
'id'=> 'groupId',
'member'=> 'userId',
]);
$result = (new Request())->Request($conf['url'],$Group);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Modify group information
*
* @param array $Group Modify group information parameter
* @param
* $Group = [
* 'id'=> 'watergroup',//group id
* 'name'=>"watergroup"//group name
* ];
* @return array
*/
public function update(array $Group=[]){
$conf = $this->conf['update'];
$verify = $this->verify['group'];
$verify = ['id'=>$verify['id'],'name'=>$verify['name']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'group',
'data'=> $Group,
'verify'=> $verify
]);
if($error) return $error;
$Group = (new Utils())->rename($Group, [
'id'=> 'groupId',
'name'=> 'groupName',
]);
$result = (new Request())->Request($conf['url'],$Group);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Get group information
*
* @param array $Group Get group information parameter
* @param
* $Group = [
* 'id'=> 'watergroup',//group id
* ];
* @return array
*/
public function get(array $Group=[]){
$conf = $this->conf['get'];
$verify = $this->verify['group'];
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'group',
'data'=> $Group,
'verify'=> $verify
]);
if($error) return $error;
$Group = (new Utils())->rename($Group, [
'id'=> 'groupId',
]);
$result = (new Request())->Request($conf['url'],$Group);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
if($result['code'] == 200) {
$result = (new Utils())->rename($result, [
'users'=> 'members',
]);
}
return $result;
}
/**
* Create a group gag object
*
* @return Gag
*/
public function Gag(){
return new Gag();
}
/**
* Create a full member mute for the specified group
*
* @return MuteAllMembers
*/
public function MuteAllMembers(){
return new MuteAllMembers();
}
/**
* Create a mute whitelist for all members of the specified group
*
* @return MuteWhiteList
*/
public function MuteWhiteList(){
return new MuteWhiteList();
}
/**
* Group member remark
*
* @return Remark
*/
public function Remark(){
return new Remark();
}
}