Client.php 13.6 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 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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
<?php
namespace common\lib\QcloudApi;

use \QcloudApi;
/**
 * 腾讯云接口
 * @author    mingqiao.tan<mingqiao.tan@yoho.cn>
 */
//error_reporting(E_ALL ^ E_NOTICE);
require_once dirname(__FILE__).'/QcloudApi.php';

class Client{

    private $_config = array(
        'SecretId'       => 'AKIDXwq8mqFT479AXttmyBRo8Ebt2ziaqeZs',
        'SecretKey'      => 'mvmxc6Ozu6akckaD9hXFaHFtIeG7dv2s',
        'RequestMethod'  => 'GET',
        'DefaultRegion'  => 'bj'
    );

    private $_obj;

    /**
     * 实例化自身
     */
	public static function self($a = QcloudApi::MODULE_LIVE)
	{
        static $self = [];
        if (empty($self[$a])){
            $self[$a] = new self($a);
        }
		return $self[$a];
	}
    
    private function __construct($a){
        $this->_obj = QcloudApi::load($a, $this->_config);
    }

    /**
     * 创建直播频道	CreateLVBChannel
     * @param type $channelName
     * @param type $outputSourceType
     * @return type
     */
    public function CreateLVBChannel($channelName,$outputSourceType = 3)
    {
        $cvm = $this->_obj;
        
        $package = array(
            //直播频道的名称
            'channelName'=>$channelName,
            //直播频道描述
            //'channelDescribe'=>$channelName,
            //选择输出源类型(1只有RTMP/flv输出2:只有HLS输出3:有RTMP/FLV HLS输出)
            'outputSourceType'=>$outputSourceType,
            //若使用腾讯云播放器,则是设置默认播放器的密码,设置此密码后点击观看时输入密码才可观看
            //'playerPassword'=>'',
            //直播源列表,每个直播源可以包括类型、名称和地址(限用于拉流)注:目前只支持一个直播源
            'sourceList.1.type'  =>1,
            'sourceList.1.name'  =>'video-1999',
            //水印ID
            'watermarkId'=>0,
        );
        
        $a = $this->_obj->generateUrl('CreateLVBChannel', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->CreateLVBChannel($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    //查询直播频道列表
    /*
       channelStatus int	用作频道列表过滤,频道状态(0:无输入流;1:有输入流;2:异常;3:关闭;4:配置不完整)
       ascDesc		 int	结果排序,默认按频道创建时间排序,0:按时间升序 1:按时间降序
       pageNo	 	 int	分页页号,比如想查看第3页的列表,将该变量设置为3
       pageSize	 	 int	每一个分页上显示的频道的个数
       orderBy	 	 str	默认以频道创建时间来排序
      */
    public function DescribeLVBChannelList($channelStatus='',$ascDesc=1,$pageNo=1,$pageSize=10,$orderBy='create_time'){
        if (9 == $channelStatus) {
            $ret = array();
            //0:无输入流;1:有输入流;2:异常;3:关闭;4:配置不完整
            $status = array(0,1,2,3,4);
            foreach($status as $state){
                $package = array(
                    'channelStatus'=>$state,
                    'ascDesc'      =>$ascDesc,
                    'pageNo'       =>$pageNo,
                    'pageSize'     =>$pageSize,
                    'orderBy'      =>$orderBy
                );
                $a = $this->_obj->generateUrl('DescribeLVBChannelList', $package);//获取接口url
                if (!$a) {
                    continue;
                } else {
                    $res = $this->_obj->DescribeLVBChannelList($package);      //执行url
                    if (!$res) {
                        continue;
                    } else {
                        if(isset($res['channelSet'])){
                            if (!is_array($res['channelSet'])) {
                                continue;
                            }
                            foreach ($res['channelSet'] as $c) {
                                $ret[] = $c;
                            }
                        }
                    }
                }
            }
            return $ret;
        }
        $package = array(
            'channelStatus'=>$channelStatus,
            'ascDesc'      =>$ascDesc,
            'pageNo'       =>$pageNo,
            'pageSize'     =>$pageSize,
            'orderBy'      =>$orderBy
        );
        $a = $this->_obj->generateUrl('DescribeLVBChannelList', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeLVBChannelList($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }
    //查询直播频道详情
    public function DescribeLVBChannel($channelId){
        $package = array(
            'channelId'=>$channelId
        );
        //$a = $this->_obj->DescribeLVBChannel($package);//通过魔术方法直接执行接口url
        $a = $this->_obj->generateUrl('DescribeLVBChannel', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeLVBChannel($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }
    //修改直播频道
    public function ModifyLVBChannel(){

    }

    //批量启用直播频道  param channelIds array   return ture 成功,其他失败
    public function StartLVBChannel(array $channelIds){
        if(is_array($channelIds) && !empty($channelIds)) {
            $package = array();
            foreach($channelIds as $k=>$v){
                $n = $k+1;
                $package['channelIds.'.$n]= $v;
            }
        }else{
            return false;
        }
        $a = $this->_obj->generateUrl('StartLVBChannel', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->StartLVBChannel($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    //批量停止直播频道 return ture 成功,其他失败
    public function StopLVBChannel(array $channelIds){
        if(is_array($channelIds) && !empty($channelIds)) {
            $package = array();
            foreach($channelIds as $k=>$v){
                $n = $k+1;
                $package['channelIds.'.$n]= $v;
            }
        }else{
            return false;
        }
        $a = $this->_obj->generateUrl('StopLVBChannel', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->StopLVBChannel($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }
    //查询直播频道当前并发收看数
    public function DescribeLVBOnlineUsers($channelId){
        $package = array(
            'channelIds.1'=>$channelId
        );
        $a = $this->_obj->generateUrl('DescribeLVBOnlineUsers', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeLVBOnlineUsers($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    //删除直播频道
    public function DeleteLVBChannel(array $channelIds){
        if(is_array($channelIds) && !empty($channelIds)) {
            $package = array();
            foreach($channelIds as $k=>$v){
                $n = $k+1;
                $package['channelIds.'.$n]= $v;
            }
        }else{
            return false;
        }
        $a = $this->_obj->generateUrl('DeleteLVBChannel', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DeleteLVBChannel($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    //创建录制任务
    public function CreateRecord($channelId, $startTime = '', $endTime = ''){
        $package = array(
            'channelId'=>$channelId,
            'startTime'=>$startTime,
            'endTime'=>$endTime
        );
        //$a = $this->_obj->CreateRecord($package);//通过魔术方法直接执行接口url
        $a = $this->_obj->generateUrl('CreateRecord', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->CreateRecord($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    //终止录制任务
    public function StopRecord($channelId,$taskId){
        $package = array(
            'channelId'=>$channelId,
            'taskId'=>$taskId
        );
        //$a = $this->_obj->StopRecord($package);//通过魔术方法直接执行接口url
        $a = $this->_obj->generateUrl('StopRecord', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->StopRecord($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    /*
     * 查询已录制分片列表
     * channelId	是	String	频道id
     * taskId	    是	Int	任务id
     * pageNo	    否	Int	页码,默认为1
     * pageSize	    否	Int	分页大小,默认为10
    */
    public function DescribeRecord($channelId,$taskId,$pageNo=1,$pageSize=10){
        $package = array(
            'channelId'=>$channelId,
            'taskId'=>$taskId,
            'pageNo'=>$pageNo,
            'pageSize'=>$pageSize
        );
        $a = $this->_obj->generateUrl('DescribeRecord', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeRecord($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    //创建截图任务
    public function CreateLVBShot(){

    }
    //终止截图任务
    public function StopLVBShot(){

    }

    //查看队列消息
    public function DescribeQueueLog(){

    }

    //获取录播视频播放信息
    // P.S.谭明乔:此方法为互动点播使用,v4.0.6直播不使用,可以废弃
    public function DescribeRecordPlayInfo($vid,$notifyUrl=''){
        $package = array(
            'notifyUrl'=>$notifyUrl,
            'vid'=>$vid,
        );
        $a = $this->_obj->generateUrl('DescribeRecordPlayInfo', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeRecordPlayInfo($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }
    //获取录播视频播放信息
    public function DescribeVodPlayUrls($vid){
        $package = array(
            'fileId'=>$vid,
        );
        $a = $this->_obj->generateUrl('DescribeVodPlayUrls', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeVodPlayUrls($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }
    //获取视频分类列表
    public function DescribeClass(){
        $package = array();
        $a = $this->_obj->generateUrl('DescribeClass',$package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeClass($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }
    //视频转码
    public function ConvertVodFile($fileId,$isScreenshot=0,$isWatermark=0,$notifyUrl=''){
        $package = array(
            'fileId'=>$fileId,
            'isScreenshot'=>$isScreenshot,
            'isWatermark'=>$isWatermark,
            'notifyUrl'=>$notifyUrl,
        );
        $a = $this->_obj->generateUrl('ConvertVodFile',$package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->ConvertVodFile($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    public function DescribeRecordList($channelId,$pageNo,$pageSize){
        $package = array(
            'channelId'=>$channelId,
            'pageNo'=>$pageNo,
            'pageSize'=>$pageSize
        );
        $a = $this->_obj->generateUrl('DescribeRecordList', $package);//获取接口url
        if ($a === false) {
            return false;
        } else {
            $res = $this->_obj->DescribeRecordList($package);      //执行url
            if($res === false){
                return false;
            } else{
                return $res;
            }
        }
    }

    public function error(){
        $error = $this->_obj->getError();
        return $error->getMessage();
    }
}