-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathChatroom.php
More file actions
155 lines (144 loc) · 4.35 KB
/
Chatroom.php
File metadata and controls
155 lines (144 loc) · 4.35 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
<?php
/**
* Chat room message
*/
namespace RongCloud\Lib\Message\Chatroom;
use RongCloud\Lib\Request;
use RongCloud\Lib\Utils;
use RongCloud\Lib\ConversationType;
class Chatroom
{
private $jsonPath = 'Lib/Message/Chatroom/';
/**
* Request configuration file
*
* @var string
*/
private $conf = '';
/**
* Verify configuration file
*
* @var string
*/
private $verify = '';
/**
* Chatroom constructor.
*/
function __construct()
{
$this->conf = Utils::getJson($this->jsonPath . 'api.json');
$this->verify = Utils::getJson($this->jsonPath . '../verify.json');;
}
/**
* @param array $Message Chat room message sending
* @param
* $Message = [
* 'senderId'=> 'ujadk90ha',// Sender ID
* 'targetId'=> 'kkj9o01',// Chat room ID
* "objectName"=>'RC:TxtMsg',// Message type - text
* 'content'=>['content'=>'Hello, host']// Message content
* ];
* @return array
*/
public function send(array $Message = [])
{
$conf = $this->conf['send'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'message',
'data' => $Message,
'verify' => $this->verify['message']
]);
if ($error) return $error;
$Message = (new Utils())->rename($Message, [
'senderId' => 'fromUserId',
'targetId' => 'toChatroomId'
]);
$result = (new Request())->Request($conf['url'], $Message);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* @param array $Message Chatroom broadcast message
* @param
* $Message = [
* 'senderId'=> 'ujadk90ha',//Sender ID
* "objectName"=>'RC:TxtMsg',//Message type: text
* 'content'=>['content'=>'Hello, host']//Message content
* ];
* @return array
*/
public function broadcast(array $Message = [])
{
$conf = $this->conf['broadcast'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'message',
'data' => $Message,
'verify' => $this->verify['message']
]);
if ($error) return $error;
$Message = (new Utils())->rename($Message, [
'senderId' => 'fromUserId',
]);
$result = (new Request())->Request($conf['url'], $Message);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* @param array $Message Chat room message recall
* @param
* $Message = [
* 'senderId'=> 'ujadk90ha',//Sender Id
* 'targetId'=> 'markoiwm',//Chat room Id
* "uId"=>'5GSB-RPM1-KP8H-9JHF',//Unique identifier of the message
* 'sentTime'=>'1519444243981'//Message sending time
* ];
* @return array
*/
public function recall(array $Message = [])
{
$conf = $this->conf['recall'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'message',
'data' => $Message,
'verify' => $this->verify['message']
]);
if ($error) return $error;
$Message = (new Utils())->rename($Message, [
'senderId' => 'fromUserId',
'uId' => 'messageUID'
]);
$Message['conversationType'] = ConversationType::t()['CHATROOM'];
$result = (new Request())->Request($conf['url'], $Message);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* getHistoryMsg
*
* @param array $param = [
* 'userId'=> 'ujadk90ha',
* 'targetId'=> 'markoiwm',
* "startTime"=> 1759130000000,
* 'endTime'=> 1759140981000,
* 'includeStart'=> true
* ];
* @return array
*/
public function getHistoryMsg(array $param = [])
{
$conf = $this->conf['chatroomHistoryMsg'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'historyMsg',
'data' => $param,
'verify' => $this->verify['historyMsg']
]);
if ($error) return $error;
$result = (new Request())->Request($conf['url'], $param, 'json');
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
}