EnterRoomController.class.php
1.63 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
<?php
/**
* 【后台】进入直播间接口
* Created by PhpStorm.
* User: yingcai
* Date: 2018/1/12
* Time: 下午4:37
*/
namespace Apicp\Controller\LiveRoom;
use Common\Common\Constant;
use Common\Service\RoleService;
use Think\Cache\Driver\Redis;
class EnterRoomController extends AbstractController
{
protected $requireLogin = false;
/**
* LoginRoom
* @author houyingcai
* @desc 进入直播间接口
* @param Int lm_id:true:1 直播活动ID
* @param String password:true:aaa111 直播密令
* @return bool
*/
public function Index()
{
$password = I('post.password', '', 'raddslashes');
// 获取密令
$roleService = new RoleService();
$roleInfo = $roleService->get_by_conds([
'lm_id' => $this->liveMainDetail['lm_id'],
'type' => Constant::LIVE_ROLE_TYPE_LECTURER,
], [], true);
// 判断密令是否正确
if ($password != $roleInfo['password']) {
E('_ERR_LIVE_PASSWORD');
}
// 如果直播间有人登陆了就不让登陆
$redis = new Redis();
$redisToken = $redis->get($this->studioDetail['stream_id']);
if (!empty($redisToken)) {
E('_ERR_OTHER_PLACES_LANDED');
}
// 生成 token
$token = md5(uniqid(mt_rand(), true));
// 写cookie
$this->_cookie->setx($this->studioDetail['stream_id'], $token, self::ADMINER_ID_EXPIRE_TIME);
// 写redis
$redisServ = new Redis();
$redisServ->set($this->studioDetail['stream_id'], $token, self::ADMINER_ID_EXPIRE_TIME);
return true;
}
}