-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathUser.php
More file actions
476 lines (444 loc) · 11.8 KB
/
User.php
File metadata and controls
476 lines (444 loc) · 11.8 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?php
/**
* User Module
* User=> hejinyu
* Date=> 2018/7/23
* Time=> 11=>41
*/
namespace RongCloud\Lib\User;
use RongCloud\Lib\User\Tag\Tag;
use RongCloud\Lib\User\Block\Block;
use RongCloud\Lib\User\Blacklist\Blacklist;
use RongCloud\Lib\User\Whitelist\Whitelist;
use RongCloud\Lib\User\MuteGroups\MuteGroups;
use RongCloud\Lib\User\Onlinestatus\Onlinestatus;
use RongCloud\Lib\User\MuteChatrooms\MuteChatrooms;
use RongCloud\Lib\User\Chat\Ban;
use RongCloud\Lib\User\Remark\Remark;
use RongCloud\Lib\User\BlockPushPeriod\BlockPushPeriod;
use RongCloud\Lib\User\Profile\Profile;
use RongCloud\Lib\User\Friend\Friend;
use RongCloud\Lib\Utils;
use RongCloud\Lib\Request;
class User
{
/**
* User module path
*
* @var string
*/
private $jsonPath = 'Lib/User/';
/**
* Request configuration file
*
* @var string
*/
private $conf = '';
/**
* Verification configuration file
*
* @var string
*/
private $verify = '';
/**
* User constructor.
*/
function __construct()
{
// Initialize request configuration and validate file path
$this->conf = Utils::getJson($this->jsonPath . 'api.json');
$this->verify = Utils::getJson($this->jsonPath . 'verify.json');
}
/**
* @param array $User User registration
* @param
* $User = [
* 'id'=> 'ujadk90ha', // User ID
* 'name'=> 'Maritn', // User name
* 'portrait'=> 'http://7xogjk.com1.z0.glb.clouddn.com/IuDkFprSQ1493563384017406982' // User avatar
* ];
* @return array
*/
public function register(array $User = [])
{
$conf = $this->conf['register'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId',
'portrait' => 'portraitUri'
]);
$result = (new Request())->Request($conf['url'], $User);
$bodyParameter = (new Request())->getQueryFields($User);
$result = (new Utils())->responseError($result, $conf['response']['fail'], $bodyParameter);
return $result;
}
/**
* Token invalidation
*
* @param array $User User information
* @param
* $User = [
* 'id'=> ['ujadk90ha1'], // User IDs that need to have their tokens invalidated, supports setting up to 20 IDs.
* 'time'=> 1623123911000 // Expiration timestamp accurate to milliseconds, all tokens obtained by the user before this timestamp will be invalidated. Tokens in use by connected users before this timestamp will not be immediately invalidated, but will be unable to reconnect after disconnection.
* ];
* @return array
*/
public function expire(array $User = [])
{
$conf = $this->conf['expire'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['expire']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId'
]);
$result = (new Request())->Request($conf['url'], $User);
$bodyParameter = (new Request())->getQueryFields($User);
$result = (new Utils())->responseError($result, $conf['response']['fail'], $bodyParameter);
return $result;
}
/**
* @param array $User User information update
* @param
* $User = [
* 'id'=> 'ujadk90ha', // User ID
* 'name'=> 'Maritn', // User name
* 'portrait'=> 'http://7xogjk.com1.z0.glb.clouddn.com/IuDkFprSQ1493563384017406982' // User avatar
* ];
* @return array
*/
public function update(array $User = [])
{
$conf = $this->conf['update'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId',
'portrait' => 'portraitUri'
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* @param array $User Query user information
* @param
* $User = [
* 'id'=> 'ujadk90ha',//User ID
* ];
* @return array
*/
public function get(array $User = [])
{
$conf = $this->conf['get'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId',
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
if ($result['code'] == 200) {
$result = (new Utils())->rename($result, [
'userName' => 'name',
'userPortrait' => 'portrait',
]);
}
return $result;
}
/**
* @param array $User User deregistration
* @param
* $User = [
* 'id'=> 'ujadk90ha',//User ID
* ];
* @return array
*/
public function abandon(array $User = [])
{
$conf = $this->conf['cancel_set'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId',
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* @param array $User Query for deactivated users
* @param
* @return array
*/
public function abandonQuery(array $params = ["page" => 1, "size" => 50])
{
$conf = $this->conf['cancel_query'];
$User = (new Utils())->rename($params, [
'page' => 'pageNo',
'size' => 'pageSize'
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* @param array $User Deactivate user activation
* @param
* $User = [
* 'id'=> 'ujadk90ha',//User ID
* ];
* @return array
*/
public function activate(array $User = [])
{
$conf = $this->conf['active'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId',
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Reactivate user ID
* @param array $User User ID
* @param
* $User = [
* 'id'=> 'ujadk90ha', // User ID
* ];
* @return array
*/
public function reactivate(array $User = [])
{
$conf = $this->conf['reactivate'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId',
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* @param array $User Query the group where the user is located
* @param
* $User = [
* 'id'=> 'ujadk90ha',//User ID
* ];
* @return array
*/
public function getGroups(array $User = [])
{
$conf = $this->conf['getGroups'];
$error = (new Utils())->check(
[
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]
);
if ($error) {
return $error;
}
$User = (new Utils())->rename($User, [
'id' => 'userId',
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
public function query(array $params = ["page" => 1, "pageSize" => 20, "order" => 0]) {
$conf = $this->conf['user_query'];
$User = (new Utils())->rename($params, [
'size' => 'pageSize'
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
public function del(array $params) {
$conf = $this->conf['user_del'];
$User = (new Utils())->rename($params, [
'id' => 'userId',
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Create a block object
*
* @return Block
*/
public function Block()
{
return new Block();
}
/**
* Create a blacklist object
*
* @return Blacklist
*/
public function Blacklist()
{
return new Blacklist();
}
/**
* Create an online status object for the user
*
* @return Onlinestatus
*/
public function Onlinestatus()
{
return new Onlinestatus();
}
/**
* Global group muting
*
* @return MuteGroups
*/
public function MuteGroups()
{
return new MuteGroups();
}
/**
* Global chatroom mute
*
* @return MuteChatrooms
*/
public function MuteChatrooms()
{
return new MuteChatrooms();
}
/**
* User tag
*
* @return Tag
*/
public function Tag()
{
return new Tag();
}
/**
* Create a whitelist object
*
* @return Whitelist
*/
public function Whitelist()
{
return new Whitelist();
}
/**
* User mute ban
*
* @return Ban
*/
public function Ban()
{
return new Ban();
}
/**
* User push remark
*
* @return Remark
*/
public function Remark()
{
return new Remark();
}
/**
* User quiet time period
*
* @return Remark
*/
public function BlockPushPeriod()
{
return new BlockPushPeriod();
}
/**
* User Profile Hosting
*
* @return Profile
*/
public function Profile()
{
return new Profile();
}
/**
* Friend profile (info hosting)
*
* @return Friend
*/
public function Friend()
{
return new Friend();
}
}