接口URL
https://api.polyv.net/v2/danmu/{userId}/add
接口说明
(接口调用有频率限制,详细请查看)
上传点播视频弹幕接口,弹幕暂不支持特殊字符与表情符。
返回结果支持格式
JSON
请求方式
POST
请求参数
参数名 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
userId | true | string | 用户id,路径参数 |
ptime | true | string | 当前13位毫秒级时间戳,3分钟内有效 |
sign | true | string | 签名,40位大写的sha1值 |
vid | true | string | 点播视频vid |
msg | true | string | 弹幕信息 |
time | true | string | 弹幕出现的时间,格式 HH:mm:ss |
sessionId | false | string | 场次号 |
param2 | false | string | 自定义参数 |
fontSize | false | int32 | 字体大小,默认:18 |
fontMode | false | string | 出现位置,顶部:top,底部:bottom,滚动:roll(默认) |
fontColor | false | string | 字体颜色,格式0xFFFFFF, 默认:0xFFFFFF |
返回结果
// 成功结果
{
"code": 200,
"status": "success",
"message": "success",
"data": {
"Id": 1115759
}
}
失败返回json
// 时间戳过期:
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
// 签名报错
{
"code": 400,
"status": "error",
"message": "the sign is not right.",
"data": ""
}
// 必须参数为空
{
"code": 400,
"status": "error",
"message": "vid, msg and time should not be empty.",
"data": ""
}
// 弹幕时间格式不对
{
"code": 400,
"status": "error",
"message": "Wrong time format.",
"data": ""
}
// 非法参数
{
"code": 400,
"status": "error",
"message": "font size illegal",
"data": ""
}
// 视频不存在
{
"code": 400,
"status": "error",
"message": "vid doesn't exist.",
"data": ""
}
响应参数说明
字段 | 说明 | 类型 | schema |
---|---|---|---|
code | 响应码 | int32 | |
status | 响应状态:success/error/fail | string | |
message | 错误信息说明 | string | |
data | 响应数据 | object | |
data.Id | 弹幕Id | int32 |
响应错误说明
错误代码 | message | 说明 |
---|---|---|
400 | sign can not be empty. | 加密串为空 |
400 | ptime is too old. | 时间戳过期 |
400 | ptime is illegal. | 时间戳参数格式不对或者超过当前时间3分钟 |
400 | Could not find user by userId. | userId不存在 |
400 | the sign is not right. | 签名不正确 |
400 | vid doesn't exist. | 视频vid为空 |
400 | vid, msg and time should not be empty. | 必传参数为空 |
400 | Wrong time format. | 弹幕时间格式不对 |
400 | font size illegal | 字体格式非法 |
PHP请求示例
<?php
$userId="xxxxxxxxxxx";
$secretkey="xxxxxxxxxxx";
$url = 'http://api.polyv.net/v2/danmu/'.$userId.'/add';
$header = array('application/x-www-form-urlencoded');
$data = array(
"ptime" => time()*1000,
"msg" => "弹幕......",
"vid" => "xxxxxxxxxxx",
"time" => "00:01:10"
);
ksort($data);
$str='';
foreach ($data as $k => $v) {
$str = $str.$k.'='.$v.'&';
}
$str=substr($str,0,strlen($str)-1);
$str=$str.$secretkey;
$hash=strtoupper(sha1($str));
$data["sign"]=$hash;
// 请求接口
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$sResult = curl_exec($ch);
if($sError=curl_error($ch)){
die($sError);
}
curl_close($ch);
//打印获得的数据
print_r($sResult);
?>
签名规则:
将非空的请求参数按照参数名字典顺序排列,连接参数名与参数值,并在尾部加上secretkey,生成40位大写SHA1值,作为sign。 以下是示例过程:
1、请求参数为
ptime = "1492591990000"
vid = "382839019131be68715e9455f8d0971a_3"
format = "json"
2、将请求参数按照参数名字典顺序排列
format = "json"
ptime = "1492591990000"
vid = "382839019131be68715e9455f8d0971a_3"
3、连接字符串
连接参数名与参数值,并在尾部加上secretkey(secretkey的值为tIQp4ATe9Z),如下:
format=json&ptime=1492591990000&vid=382839019131be68715e9455f8d0971a_3tIQp4ATe9Z
4、生成签名sign
50BF9B165630A8047EB1D17D95A469CC51FF754E