EnterRoomController.class.php 1.63 KB
<?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;
    }
}