RoomController.php
9.07 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
<?php
namespace soa\controllers\v1;
use Yii;
use soa\controllers\BaseController;
use common\models\RoomNums;
use common\models\Video;
use common\models\Room;
/**
* Room controller
*/
class RoomController extends BaseController
{
/**
* 弹幕服务器上传房间一些数目参数
* @return mixed
*/
public function actionSetnums()
{
//http://newboys.test.yoho.cn/yohoboyins/v4/qcloud/setLiveNums?parameters={"room":"2","likeNums":0,"onlineNums":0,"audienceNums":"11369"}
$gets = $this->requests();
$room_id = $gets['room'];
if ($room_id) {
if (!$model = RoomNums::findOne(['room_id' => $room_id])) {
$model = new RoomNums();
$model->room_id = $room_id;
}
if (isset($gets['likeNums'])) {
$model->like_num = $gets['likeNums'];
}
if (isset($gets['onlineNums'])) {
$model->online_num = $gets['onlineNums'];
}
if (isset($gets['audienceNums'])) {
$model->audience_num = $gets['audienceNums'];
}
if (isset($gets['vestOnlineNums'])) {
$model->vest_online_num = $gets['vestOnlineNums'];
}
if ($model->save()) {
$retArr = [
'code' => Yii::$app->params['success_code'],
'messsage' => '保存成功'
];
} else {
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '保存失败'
];
}
} else {
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '更新失败,缺少房间号'
];
}
$this->renderJson($retArr['code'], $retArr['messsage']);
}
/**
* 弹幕服务器上报弹幕消息
* @author yaoxiaofeng
*/
public function actionSetlivecomment()
{
$gets = $this->requests();
$datas = [];
$room_id = $gets['room'];
$datas['room_id'] = $room_id;
$datas['uid'] = $gets['uid'];
$datas['comment'] = isset($gets['msg']) ? $gets['msg'] : '';
$datas['name'] = $gets['name'];
$datas['avatar'] = $gets['avatar'];
$datas['cmd'] = $gets['cmd'];
$datas['create_time'] = $gets['create_time'];
try {
$result = Yii::$app->db->createCommand()->insert($this->getTableName($room_id), $datas)->execute();
if ($result) {
$retArr = [
'code' => Yii::$app->params['success_code'],
'messsage' => '插入成功'
];
} else {
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '插入失败'
];
}
} catch (\yii\db\Exception $e) {
$retArr = [
'code' => Yii::$app->params['exception_code'],
'messsage' => $e->getMessage()
];
}
$this->renderJson($retArr['code'], $retArr['messsage']);
}
public function actionGetlivingroomid()
{
return [10000, 10001];
}
/**
* 获取禁言用户列表
*/
public function actionGetforbiddenuids()
{
$forbidedUids = [];
$rooms = (new \yii\db\Query())
->select(['room_id'])
->from('tbl_room')
->where(['status' => 1])
->limit(100)
->all();
if ($rooms) {
foreach ($rooms as $room) {
$room_id = $room['room_id'];
$uids = (new \yii\db\Query())
->select(['uid'])
->from('tbl_forbidden')
->where(['room_id' => $room_id])
->all();
if ($uids) {
foreach ($uids as $v) {
$forbidedUids[$room_id][] = $v['uid'];
}
}
}
}
$this->renderJson(Yii::$app->params['success_code'], '', $forbidedUids);
}
/**
* 获取推流地址
* @author yaoxiaofeng
*/
public function actionGetpushflow()
{
$requests = $this->requests();
// $room_id = $requests['room_id'];
$result = (new \yii\db\Query())
->select('a.room_id,a.title,a.living,a.secret,b.channel_id,b.upstream_address')
->from('tbl_room a')
->leftJoin('tbl_room_qchannel b', 'a.room_id=b.room_id')
->where(['a.living' => 0])
->all();
if ($result) {
foreach($result as $flow){
$data[] = [
'url' => $flow['upstream_address'].'&record=flv',
'name' => $flow['title'],
'channel_id' => $flow['channel_id'],
'secret' => $flow['secret'],
'cid' => '',
'app' => '1',
'id' => $flow['room_id'],
'type' => $flow['living'],
];
}
} else {
$data = [];
}
$this->renderJson(Yii::$app->params['success_code'], '', $data);
}
/**
* 设置直播开始结束状态
* @author yaoxiaofeng
*/
public function actionSetstat()
{
$requests = $this->requests();
$status = $requests['living_stat'];
$room_id = $requests['room_id'];
$status_valid = [0,1];
if (in_array($status, $status_valid) && $room_id) {
try {
$model = new Video();
if($status==1){ //开始
$result = $model->setVideoStart($room_id);
}elseif($status==0){//结束
$result = $model->setVideoStop($room_id);
}
if ($result) {
$retArr = [
'code' => Yii::$app->params['success_code'],
'messsage' => '设置成功'
];
} else {
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '设置失败'
];
}
} catch (\Exception $e) {
$retArr = [
'code' => Yii::$app->params['exception_code'],
'messsage' => $e->getMessage()
];
}
} else {
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '请检查传参是否正确'
];
}
$this->renderJson($retArr['code'], $retArr['messsage']);
}
/**
* 主播选择推流房间验证接口
* @author yaoxiaofeng
*/
public function actionValidmaster(){
$requests = $this->requests();
$secret = $requests['secret'];
$room_id = $requests['room_id'];
if($model = Room::findOne(['room_id'=>$room_id])){
if($model->secret == $secret){
$retArr = [
'code' => Yii::$app->params['success_code'],
'messsage' => '验证成功'
];
}else{
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '验证失败'
];
}
}else{
$retArr = [
'code' => Yii::$app->params['failed_code'],
'messsage' => '房间不存在'
];
}
$this->renderJson($retArr['code'], $retArr['messsage']);
}
/**
* 获取评论表名称
* @param $room_id
* @return string
*/
private function getTableName($room_id)
{
return 'tbl_live_comment' . str_pad((int)($room_id % 10), 2, '0', STR_PAD_LEFT);
}
/**
* 直播中的所有房间
*/
public function actionListing()
{
$list = Room::find()->where(['and',['living'=>1],['status'=>1]])->all();
foreach ($list as $k=>$model){
$row = [
'room_id'=>(int)$model->room_id,
'vest'=>$model->vest,
];
$list[$k] = $row;
}
$this->renderJson(Yii::$app->params['success_code'],'',$list);
}
public function actionLog(){
$message = "test";
$level = "";
Yii::$app->log->getLogger()->log($message, $level);
}
public function actionTest(){
$re = \common\lib\QcloudApi\Client::self()->CreateRecord("16093425727657864680", date('Y-m-d H:i:s',time()+120), '');
// $re = \common\lib\QcloudApi\Client::self()->DescribeRecordList("16093425727657864680",1,10);
// $re = \common\lib\QcloudApi\Client::self()->StopRecord("16093425727657524184", "131525");
var_dump($re);
//http://200013340.vod.myqcloud.com/200013340_6e79da1e65d140d887cdbb7f3ebadf79.f20.mp4
}
}