保利威文档中心

幫助中心

設定播放器片頭廣告

更新時間: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);
?>

簽名規則(config.php檔案程式碼檢視)

簽名產生規則

联系客服,在线咨询