-
Notifications
You must be signed in to change notification settings - Fork 117
/
Chatroom.php
403 lines (379 loc) · 11.2 KB
/
Chatroom.php
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
<?php
/**
* 聊天室
*/
namespace RongCloud\Lib\Chatroom;
use RongCloud\Lib\Request;
use RongCloud\Lib\Utils;
use RongCloud\Lib\Chatroom\Ban\Ban;
use RongCloud\Lib\Chatroom\Block\Block;
use RongCloud\Lib\Chatroom\Demotion\Demotion;
use RongCloud\Lib\Chatroom\Distribute\Distribute;
use RongCloud\Lib\Chatroom\Gag\Gag;
use RongCloud\Lib\Chatroom\Keepalive\Keepalive;
use RongCloud\Lib\Chatroom\Whitelist\Whitelist;
use RongCloud\Lib\Chatroom\Whitelist\Message;
use RongCloud\Lib\Chatroom\Entry\Entry;
use RongCloud\Lib\Chatroom\MuteAllMembers\MuteAllMembers;
use RongCloud\Lib\Chatroom\MuteWhiteList\MuteWhiteList;
class Chatroom
{
/**
* 聊天室模块路径
*
* @var string
*/
private $jsonPath = 'Lib/Chatroom/';
/**
* 请求配置文件
*
* @var string
*/
private $conf = "";
/**
* 校验配置文件
*
* @var string
*/
private $verify = "";
/**
* Chatroom constructor.
*/
function __construct()
{
$this->conf = Utils::getJson($this->jsonPath.'api.json');
$this->verify = Utils::getJson($this->jsonPath.'verify.json');
}
/**
* 聊天室创建
*
* @deprecated 已弃用,请使用 createV2 的方法进行创建
* @param array $Chatroom
* $Chatroom = [
'id'=> 'chatroom9992',//聊天室 id
'name'=> 'RongCloud',//聊天室名称
];
* @return mixed|null
*/
public function create(array $Chatroom=[]){
if(!isset($Chatroom[0])){
$Chatroom = [$Chatroom];
}
$conf = $this->conf['create'];
$verify = $this->verify['chatroom'];
$verify = ['id'=>$verify['id'],'name'=>$verify['name']];
$data = [];
foreach ($Chatroom as $v){
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $v,
'verify'=> $verify
]);
if($error) return $error;
$data["chatroom[{$v['id']}]"] = $v['name'];
}
$result = (new Request())->Request($conf['url'],$data);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* 聊天室创建
*
* @param array $Chatroom
* $Chatroom = [
'id'=> 'chatroom9992',//聊天室 id
'destroyType' => 0, //指定聊天室的销毁类型 0:默认值,表示不活跃时销毁,1:固定时间销毁
'destroyTime' => 60, //设置聊天室销毁时间
'isBan' => false, //是否禁言聊天室全体成员,默认 false
'whiteUserIds' => ['user1','user2'], //禁言白名单用户列表,支持批量设置,最多不超过 20 个
'entryOwnerId' => '', //聊天室自定义属性的所属用户 ID。
'entryInfo' => '', //聊天室自定义属性 KV 对,JSON 结构。
];
* @return mixed|null
*/
public function createV2(array $Chatroom=[]){
$conf = $this->conf['createV2'];
$verify = $this->verify['chatroom'];
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'], $Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* 设置聊天室销毁类型
*
* @param array $Chatroom
* $Chatroom = [
'id'=> 'chatroom9992', //聊天室 id
'destroyType'=> 0, //指定聊天室的销毁方式。
'destroyTime'=> 60 //设置聊天室销毁时间。
];
* @return mixed|null
*/
public function setDestroyType(array $Chatroom=[]){
$conf = $this->conf['setDestroyType'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* 销毁聊天室
*
* @param array $Chatroom
* $Chatroom = [
'id'=> 'chatroom9992',//聊天室 id
];
* @return mixed|null
*/
public function destory(array $Chatroom=[]){
$conf = $this->conf['destory'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* 查询聊天室基础信息
*
* @DateTime 2023-06-14
* @deprecated 已弃用,请使用 queryV2 的方法进行创建
* @param array $Chatroom ['id'=> ['chatroom1','chatroom1','chatroom1']]
*
* @return array
*/
public function query(array $Chatroom=[]){
$conf = $this->conf['query'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* 查询聊天室基础信息V2
*
* @DateTime 2023-10-08
* @param array $Chatroom ['id'=> ['chatroom1','chatroom1','chatroom1']]
*
* @return array
*/
public function queryV2(array $Chatroom=[]){
$conf = $this->conf['queryV2'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* 获取聊天室成员
*
* @param array $Chatroom
* $Chatroom = [
'id'=> 'chatroom9992',//聊天室 Id
'count'=>10,//聊天室成员信息数,最多返回 500 个成员
'order'=>2//查询聊天室成员顺序, 1: 加入时间正序 2: 加入时间倒序
];
* @return mixed|null
*/
public function get(array $Chatroom=[]){
$conf = $this->conf['get'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* 检查用户是否在聊天室
*
* @param array $Chatroom
* $Chatroom = [
'id'=> 'chatroom9992',//聊天室 id
'members'=>[
['id'=>"sea9902"]//人员id
]
];
* @return mixed|null
*/
public function isExist(array $Chatroom=[]){
$conf = $this->conf['isExist'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id'],'members'=>$verify['members']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
foreach ($Chatroom['members'] as &$v){
$v = $v['id'];
}
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
'members'=>'userId'
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
if($result['code'] == 200){
$result = (new Utils())->rename($result,['result'=>'members']);
foreach ($result['members'] as $k=>&$v){
$v = (new Utils())->rename($v,['userId'=>'id']);
}
}
return $result;
}
/**
* 创建聊天室全局禁言对象
*
* @return MuteWhiteList
*/
public function Ban(){
return new Ban();
}
/**
* 创建聊天室封禁对象
*
* @return Block
*/
public function Block(){
return new Block();
}
/**
* 创建聊天室消息降级对象
*
* @return Demotion
*/
public function Demotion(){
return new Demotion();
}
/**
* 创建聊天室消息分发对象
*
* @return Distribute
*/
public function Distribute(){
return new Distribute();
}
/**
* 创建聊天室成员禁言对象
*
* @return Gag
*/
public function Gag(){
return new Gag();
}
/**
* 创建聊天室包活对象
*
* @return Keepalive
*/
public function Keepalive(){
return new Keepalive();
}
/**
* 创建聊天室用户白名单对象
*
* @return Whitelist
*/
public function Whitelist(){
return new Whitelist();
}
/**
* 创建聊天室白名单消息对象
*
* @return Message
*/
public function Message(){
return new Message();
}
/**
* 创建聊天室白名单消息对象
*
* @return Entry
*/
public function Entry(){
return new Entry();
}
/**
* 聊天室全体禁言
*
* @return MuteAllMembers
*/
public function MuteAllMembers(){
return new MuteAllMembers();
}
/**
* 聊天室全体禁言白名单
*
* @return MuteWhiteList
*/
public function MuteWhiteList(){
return new MuteWhiteList();
}
}