登录  /  注册
首页 > php教程 > PHP源码 > 正文

网易云视频直播php版api

不言
发布: 2018-05-30 09:46:50
原创
8811人浏览过

跳至                     [1]     [全屏预览]

AppKey    = $AppKey;
        $this->AppSecret = $AppSecret;
    }
	/**生成验证码**/ 
	public function checkSumBuilder(){
    	//此部分生成随机字符串
    	$hex_digits = self::HEX_DIGITS;
    	$this->Nonce;
    	for($i=0;$iNonce.= $hex_digits[rand(0,15)];
    	}
    	$this->CurTime = (string)(time());	//当前时间戳,以秒为单位

    	$join_string = $this->AppSecret.$this->Nonce.$this->CurTime;
    	$this->CheckSum = sha1($join_string);
 
    }
 
	/*****post请求******/
	public function postDataCurl($url,$data=array()){
    	$this->checkSumBuilder();		//发送请求前需先生成checkSum
		if(!empty($data)){
			$json=json_encode($data);
		}else{
			$json="";
		}
		$timeout = 5000;  
        $http_header = array(
            'AppKey:'.$this->AppKey,
            'Nonce:'.$this->Nonce,
            'CurTime:'.$this->CurTime,
            'CheckSum:'.$this->CheckSum,
            'Content-Type: application/json;charset=utf-8;',
			'Content-Length: ' . strlen($json)
        );
		$ch = curl_init(); 
		curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $json);
        curl_setopt ($ch, CURLOPT_HEADER, false); 
		curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        
		$result = curl_exec($ch);  
        if (false === $result) {
            $result =  curl_errno($ch);
        }
		curl_close($ch); 
		return json_decode($result,true) ;
    } 
	/***频道添加***/
	public function channel_add($name,$type=0){
		$url="https://vcloud.163.com/app/channel/create";
		return $data=$this->postDataCurl($url,array("name"=>$name,"type"=>$type));
	}
	/****频道更新*****/
	public function channel_update($name,$cid,$type=0){
		$url="https://vcloud.163.com/app/channel/update";
		return $data=$this->postDataCurl($url,array("name"=>$name,"cid"=>$cid,"type"=>$type));
	}
	/****频道删除******/
	public function channel_delete($cid){
		$url="https://vcloud.163.com/app/channel/delete";
		return $data=$this->postDataCurl($url,array("cid"=>$cid));
	}
	/****获取频道信息******/
	public function channel_get($cid){
		$url="https://vcloud.163.com/app/channelstats";
		return $data=$this->postDataCurl($url,array("cid"=>$cid));
	}
	/***
	获取频道列表
	records	int	单页记录数,默认值为10	否
	pnum	int	要取第几页,默认值为1	否
	ofield	String	排序的域,支持的排序域为:ctime(默认)	否
	sort	int	升序还是降序,1升序,0降序,默认为desc	否
	**/
	public function channel_list($option=array("records"=>10,"pnum"=>1,"ofield"=>"ctime","sort"=>1)){
		$url="https://vcloud.163.com/app/channellist";
		return $data=$this->postDataCurl($url,$option);
	}
	/**重新获取推流地址***/
	public function channel_reset($cid){
		$url="https://vcloud.163.com/app/address";
		return $data=$this->postDataCurl($url,array("cid"=>$cid));
	}
	/*****
	设置频道为录制状态
	cid	String	频道ID	是
	needRecord	int	1-开启录制; 0-关闭录制	是
	format	int	1-flv; 0-mp4	是
	duration	int	录制切片时长(分钟),默认120分钟	否
	filename	String	录制后文件名,格式为filename_YYYYMMDD-HHmmssYYYYMMDD-HHmmss, 
	文件名录制起始时间(年月日时分秒) -录制结束时间(年月日时分秒)	否
	****/
	
	public function channel_setRecord($cid,$option=array()){
		$url="https://vcloud.163.com/app/channel/setAlwaysRecord";
		return $data=$this->postDataCurl($url,$option);
	}
	/****暂停频道*****/
	public function channel_pause($cid){
		$url="https://vcloud.163.com/app/channel/pause";
		return $data=$this->postDataCurl($url,array("cid"=>$cid));
	}
	/****批量暂停频道****/
	public function channel_pauselist($cidList){
		$url="https://vcloud.163.com/app/channellist/pause";
		return $data=$this->postDataCurl($url,array("cidList"=>$cidList));
	}
	/****恢复频道*****/
	public function channel_resume($cid){
		$url="https://vcloud.163.com/app/channel/resume";
		return $data=$this->postDataCurl($url,array("cid"=>$cid));
	}
	/****批量恢复频道****/
	public function channel_resumelist($cidList){
		$url="https://vcloud.163.com/app/channellist/resume";
		return $data=$this->postDataCurl($url,array("cidList"=>$cidList));
	}
	/****获取频道的视频地址*****/
	public function channel_videolist($cid){
		$url="https://vcloud.163.com/app/videolist";
		return $data=$this->postDataCurl($url,array("cid"=>$cid));
	}
	
	
}

?>           		
登录后复制

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
php
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号