php版网易视频云api
最近在做在线教育课程,使用网易云视频作为在线视频直播。
网易官方只有java示例,我们使用php,就自己写个api。
当然实现也是很简单的。
演示:http://www.deitui.com/index.php?m=openclass
class v163Class{
private $AppKey; //开发者平台分配的AppKey
private $AppSecret; //开发者平台分配的AppSecret,可刷新
private $Nonce; //随机数(最大长度128个字符)
private $CurTime; //当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
private $CheckSum; //SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
const HEX_DIGITS = "0123456789abcdef";
public function __construct($AppKey,$AppSecret){
$this->AppKey = $AppKey;
$this->AppSecret = $AppSecret;
}
/**生成验证码**/
public function checkSumBuilder(){
//此部分生成随机字符串
$hex_digits = self::HEX_DIGITS;
$this->Nonce;
for($i=0;$i<128;$i++){ //随机字符串最大128个字符,也可以小于该数
$this->Nonce.= $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));
}
}
php版网易视频云api的更多相关文章
- 网易视频云技术分享:linux软raid的bitmap分析
网易视频云是网易倾力打造的一款基于云计算的分布式多媒体处理集群和专业音视频技术,提供稳定流畅.低时延.高并发的视频直播.录制.存储.转码及点播等音视频的PAAS服务,在线教育.远程医疗.娱乐秀场.在线 ...
- 阿里云视频直播API签名机制源码
阿里云视频直播API签名机制源码 本文展示:通过代码实现下阿里视频直播签名处理规则 阿里云视频直播签名机制,官方文档链接:https://help.aliyun.com/document_detail ...
- 第一章 基础设施,1.3 阿里视频云ApsaraVideo是怎样让4000万人同时狂欢的(作者:蔡华)
1.3 阿里视频云ApsaraVideo是怎样让4000万人同时狂欢的 前言 在今年的双11中,双11天猫狂欢夜的直播成为一大亮点. 根据官方披露数据,直播总观看人数超4257万,同时观看人数峰值达5 ...
- 又拍云 API 使用的那些小事
又拍云提供了丰富的 API 调用,为了减少用户在初次接入时可能会遇到的坑”,本文将对又拍云常用的 API 使用方法做个简单的梳理,力求让业务接入变得更简单,更高效. 目前我们的 API 主要有四大类, ...
- 阿里云API公共参数的获取
阿里云公共参数API https://help.aliyun.com/document_detail/50284.html?spm=5176.10695662.1996646101.searchcl ...
- 腾讯云API弹性公网IP踩坑
由于自己管理的云服务器数量比较多,时不时需要更换IP,在管理台上一下下点击,实在浪费时间,于是就想到了通过API调用的方式,将更换IP一系列动作,全部集成到Python代码里面,实现一行命令,完成IP ...
- ShowDoc,APIDoc,可道云API,语雀-适合IT企业的文档工具
ShowDoc,APIDoc,可道云API,语雀-适合IT企业的文档工具 一.ShowDoc官方文档及说明 1.1 它可以用来做什么 1.2 它都有些什么功能 1.3 使用在线的ShowDoc 1.4 ...
- LiveVideoStackCon2021 北京站专访:从上云到创新,视频云的新技术、新场景
伴随着视频技术的进步和标准的迭代,视频产业从模拟进入到数字时代,完成了从电影电视到互联网的媒介转换,并且衍生出了超高清.3D.AR/VR 等多种创新形态.特别是在后疫情的当下,我们可以看到音视频技术领 ...
- 旅图beta版 asp.net web api 单元测试
旅图 beta版 asp.net web api 单元测试 测试接口:http://120.27.7.115:1010/Help 测试目的 对每个接口单元进行测试,保证每个接口的可靠性. 单元描述 注 ...
随机推荐
- 使用VisualSVN Server搭建SVN服务器(转载)
转载于http://www.cnblogs.com/greywolf/archive/2013/01/28/2879952.html 使用 VisualSVN Server来实现主要的 SVN功能则要 ...
- cocos2d-x编程的一些小技巧
转自:http://blog.sina.com.cn/s/blog_61d2d3f50100zgz8.html 一. CC_ASSERT 或 CCAssert宏 Assert - 断言 使用断言可 ...
- [转]Reducing script compile time or a better workflow to reduce excessive recompiling
http://forum.unity3d.com/threads/148078-Reducing-script-compile-time-or-a-better-workflow-to-reduce- ...
- [ES6] 21. ESNext, ES6-Shim & Node
ES-Next: Esnextis similar to traceur, you can use command line to compile files. Install: npm instal ...
- <ASP.NET4 从入门到精通>学习笔记3
第三部分,状态管理与缓存 何为状态管理.起始对于web而言.经过前面章节的解说.已经理解,对于web程序,就是一个无状态的程序.每次的请求与每次的响应,两者之间本身就是独立存在的,这一点对于早期的静态 ...
- MAC地址查询 Linux/Unix操作系统mac地址怎么查
Linux/Unix操作系统熟悉的人都通常是用console命令控制台来进行相应的操作. Linux/Unix操作系统查看网卡mac地址的方法可以通过以下命令获得: 1.ifconfig -a 2. ...
- Android(java)学习笔记141:SQLiteDatabase的query方法参数分析
public Cursor query (boolean distinct, String table, String[] columns, String selection, String[] se ...
- ajax 特殊参数值无法传到后台问题
用原生的ajax请求后台的登录功能,使用特殊字符作为密码的时候发现无法把参数传到后台;发现前端就报错了.可能是因为特殊符号吧. 用 encodeURIComponent() 这个方法进行编码之后就可以 ...
- php session_id()函数介绍及代码实例
session_id()功能: 获取设置当前回话ID. 函数说明: string session_id ([ string $id ] ) 参数: 如果指定了参数$id,那么函数会替换当前的回话id. ...
- Spring 和 MyBatis 环境整合
本案例主要是讲述Spring 和 MyBatis 的环境整合 , 对页面功能的实现并没有做的很完整 先附上本案例的结构 1 . 创建项目并导入相关jar包 commons-collections4 ...