设置播放器片头广告
更新时间:2023-11-14 14:07:19
接口描述
1、接口用于设置某频道播放器的片头广告
2、接口URL中的{channelId}为 频道ID
3、接口支持https
接口URL
http://api.polyv.net/live/v2/channelAdvert/{channelId}/updateHead
请求方式
POST
支持格式
JSON
请求数限制
TRUE
请求参数
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| appId | 是 | string | 从API设置中获取,在直播系统登记的appId |
| timestamp | 是 | string | 当前13位毫秒级时间戳,3分钟内有效 |
| sign | 是 | string | 签名,32位大写MD5值 |
| enabled | 否 | string | Y-开启,N-关闭;设置开关时,其余设置参数无效 |
| headAdvertType | 否 | string | 广告类型,NONE-无广告,IMAGE-图片广告,FLV-视频广告 |
| headAdvertMediaUrl | 否 | string | 广告地址 |
| headAdvertHref | 否 | string | 广告跳转地址 |
| headAdvertDuration | 否 | int | 广告时长 |
| headAdvertWidth | 否 | int | 广告宽度 |
| headAdvertHeight | 否 | int | 广告高度 |
响应成功JSON示例:
{
"code": 200,
"status": "success",
"message": "",
"data": true
}
响应失败JSON示例:
未输入appId
{
"code": 400,
"status": "error",
"message": "appId is required.",
"data": ""
}
appId不正确
{
"code": 400,
"status": "error",
"message": "application not found.",
"data": ""
}
时间戳错误
{
"code": 400,
"status": "error",
"message": "invalid timestamp.",
"data": ""
}
签名错误
{
"code": 403,
"status": "error",
"message": "invalid signature.",
"data": ""
}
频道不存在
{
"code": 400,
"status": "error",
"message": "channel not found.",
"data": ""
}
频道类型错误
{
"code": 400,
"status": "error",
"message": "invalid advert type",
"data": ""
}
开关参数错误
{
"code": 400,
"status": "error",
"message": "invalid enabled value",
"data": ""
}
非法请求
{
"code": 403,
"status": "error",
"message": "operation forbidden.",
"data": ""
}
字段说明
| 参数名 | 说明 |
|---|---|
| code | 请求结果代码,成功为200 错误为400,签名错误为403 |
| status | 请求结果,成功时为"success"错误时为"error" |
| message | 错误信息,请求成功时为空串,错误时错误信息 |
| data | 请求成功为true,错误为空串 |
php请求示例
<?php
//引用config.php
include 'config.php';
//接口需要的参数(非sign)赋值
$channelId="123713";
$headAdvertType = "none";
$headAdvertMediaUrl = "http://www.headAdvertMediaUrl.com";
$headAdvertHref = "http://www.headAdvertHref.com";
$headAdvertDuration = 50;
$headAdvertWidth = 100;
$headAdvertHeight = 200;
$params = array(
'appId' => $appId,
'timestamp' => $timestamp,
'headAdvertType' => $headAdvertType,
'headAdvertMediaUrl' => $headAdvertMediaUrl,
'headAdvertHref' => $headAdvertHref,
'headAdvertDuration' => $headAdvertDuration,
'headAdvertWidth' => $headAdvertWidth,
'headAdvertHeight' => $headAdvertHeight
);
//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法
$url="http://api.polyv.net/live/v2/channelAdvert/".$channelId."/updateHead";
function post($url, $post_data = '', $timeout = 5){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
if($post_data != ''){
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, false);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
$params["sign"] = $sign;
echo post($url, $params);
?>
