对接保利威直播api-php
api官方接口地址
https://help.polyv.net/index.html#/live/api/channel/operate/basic_create
零、创建直播分类
//创建直播分类
//请求头
$data = [
'appId'=>'',
'timestamp' =>$this->tretime(),
'categoryName'=>$title,//分类名
];
$server = '';
$data['sign'] = $this->sort($data,$server);
ksort($data);
$url = 'http://api.polyv.net/live/v3/user/category/create';
$result = $this->postJson($url,'',http_build_query($data));
return json_decode($result,true);
一、创建频道
代码如下(示例):
//创建频道
//请求头
$data = [
'appId'=>'',//appid
'timestamp' =>$this->tretime(),//13位时间戳
];
$server = '';
// 签名
$sign = $this->sort($data,$server);
//参数体
$date = [
'basicSetting'=>[
'name'=>'',//频道名
'channelPasswd'=>'',//频道密码
'categoryId'=>'',//分类ID 创建分类成功后会给你 categoryId
//'maxViewer'=>'',//最大在线人数
'scene'=>'alone',//直播场景 alone活动场景
'startTime'=>$this->tretime(),//直播开始时间13位时间戳
],//频道详情
'sign'=>$sign,
];
$data['sign'] = $sign;
ksort($data);
$url = 'http://api.polyv.net/live/v3/channel/basic/create';
$result = $this->postJson($url,json_encode($date,320),http_build_query($data));
$result = json_decode($result,true);
print_r($result);die;
二、签名
//数据 server
protected function sort($data,$server){
ksort($data);
$string = '';
foreach ($data as $k=>$v){
$string .=$k.$v;
}
//拼接server
$string = $server.$string.$server;
//转大写 并md5加密
$string = strtoupper(md5($string));
return $string;
}
三、13位时间戳
//13位毫秒级时间戳
protected function tretime(){
list($s1, $s2) = explode(' ', microtime());
$time = (float)sprintf('%.0f',(floatval($s1) + floatval($s2)) * 1000);
return $time;
}
三、请求
/**
* http post请求
* @param $url
* @param $data
* @param array $header
* @param int $timeout
* @return mixed|string
* @throws Exception
*/
public function postJson($url, $data, $date,$header = array(
"Content-Type: application/json;charset=UTF-8"
),$timeout=5)
{
$url = trim($url.'?'.$date);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($ch);
if ($res === false) {
$res = curl_error($ch);
throw new Exception($res, 1);
}
curl_close($ch);
return $res;
}
总结
以上就是创建频道的步骤了,那个分类的id也是需要请求创建分类 第三方返回个 categoryId 就是分类的id
看不懂的评论,我有空就回
本文详细介绍了如何使用PHP对接保利威直播API,包括创建直播分类、创建频道、签名生成、13位时间戳的获取以及实际的请求过程。在创建频道时,需要注意获取分类ID,这是通过创建分类接口得到的。

2576

被折叠的 条评论
为什么被折叠?



