建立單條彈幕
更新時間:2025-01-14 15:58:25
介面說明
1、通过视频id创建弹幕信息,弹幕暂不支持特殊字符与表情符号
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
介面URL
http://api.polyv.net/v2/danmu/{userid}/add
請求方式
POST
介面限制
1、介面同時支援HTTP、HTTPS,建議使用HTTPS以確保介面安全,介面呼叫有頻率限制,詳細請查看
請求參數說明
| 參數名 | 必選 | 類型 | 說明 |
|---|---|---|---|
| ptime | true | Long | 目前時間的毫秒級時間戳,3分鐘內有效 |
| sign | true | String | 簽名,為40位大寫的SHA1值,產生簽名的secretkey金鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在用戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器取得回應資料【詳見簽名產生規則】 |
| vid | true | String | 影片id |
| msg | true | String | 彈幕資訊 |
| time | true | String | 彈幕出現的時間,格式:HH:mm:ss,範例:00:00:20 |
| sessionId | false | String | 場次號,自訂參數,例如:表示學員資訊的學員id |
| param2 | false | String | 自訂參數 |
| fontSize | false | Integer | 字型大小,預設:18 |
| fontMode | false | String | 出現位置,預設為roll roll:滾動 top:頂部 bottom:底部 |
| fontColor | false | String | 字型顏色,格式:0xFFFFFF,預設:0xFFFFFF(白色) |
範例
http://api.polyv.net/v2/danmu/1b448be323/add
表單參數:
vid=1b448be323b68b2999802799a98dba54_1&msg=测试添加弹幕~&sign=49BBCBC672DF778CE6C6DE8EB1F4BB7BE9B2C395&time=00:00:05&ptime=1617173648080
回應參數說明
| 參數名 | 類型 | 說明 |
|---|---|---|
| code | Integer | 回應狀態碼,200為成功返回,非200為失敗【詳見全域錯誤說明】 |
| status | String | 回應狀態文字資訊 |
| message | String | 回應描述資訊,當code為400或500時,輔助描述錯誤原因 |
| data | Object | 成功返回彈幕id,失敗返回空【詳見data欄位說明】 |
data欄位說明
| 參數名 | 類型 | 說明 |
|---|---|---|
| Id | Integer | 彈幕id |
返回錯誤代碼列表
| 錯誤代碼 | 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 | 字型格式非法 |
Java請求範例
快速接入基礎程式碼請下載相關依賴原始碼, 點擊下載原始碼 ,下載後加入到自己的原始碼工程中即可。測試案例中的HttpUtil.java 和 VodSignUtil.java 都包含在下載檔案中。
強烈建議您使用點播Java SDK完成API的功能對接,點播Java SDK 對API呼叫邏輯、異常處理、資料簽名、HTTP請求執行緒池進行了統一封裝和最佳化。
private static final Logger log = LoggerFactory.getLogger(VodVideoManagementTest.class);
/**
* 创建弹幕
*/
@Test
public void testAddDanmu() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/v2/danmu/"+userId+"/add";
String vid = "1b448be323b68b2999802799a98dba54_1";
String msg = "测试添加弹幕";
String time = "00:00:05";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("vid", vid);
requestMap.put("msg", msg);
requestMap.put("time", time);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFormBody(url, requestMap);
log.debug("测试创建弹幕,{}", response);
//do somethings
}
回應範例
系統全域錯誤說明詳見全域錯誤說明
成功範例
{
"code": 200,
"status": "success",
"message": "success",
"data": {
"Id": 17251132
}
}
異常範例
時間戳過期:
{
"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": ""
}
