Get Video Playback Credential
Updated: 2024-08-05 16:37:36
API Description
1、通过子账号id和视频id,创建加密视频的播放凭证,即 Playsafe Token
2、如果一个凭证token尚未过期,此时使用相同的 videoId、viewerId、viewerIp、iswxa 参数值请求该接口,
会复用原来的凭证token,并延长原凭证token的有效期
3、接口支持https协议
API URL
http://hls.videocc.net/service/v2/token/create-child
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. Click for details
- This API currently only supports sub-accounts. To create a credential token for the main account, refer to Get Video Playback Credential
Request Parameter Description - Delete Video
| Parameter | Required | Type | Description |
|---|---|---|---|
| appId | true | String | Polyv VOD sub-account appId. Retrieval path: Polyv VOD Console -> Settings -> Account Management |
| ts | true | Long | Current time, 13-digit millisecond timestamp, valid for 10 minutes. Example: 1617863545204 |
| sign | true | String | Signature, 32-digit uppercase MD5 value. See MD5 Signature Generation Rules |
| videoId | true | String | Video ID. Retrieval path: Polyv VOD Console -> Video List; Can also be obtained from Upload Video; Example: 1b448be32370f4822ac40fd926112a66_1 |
| viewerId | true | String | Viewer ID. Different viewers must use different IDs. Composed of letters and numbers. |
| viewerIp | false | String | Viewer IP. If empty, the IP of the API caller will be automatically obtained. |
| viewerName | false | String | Viewer name |
| expires | false | Long | Validity period of the playback credential token, in seconds. Default is 10 minutes if empty. |
| disposable | false | Boolean | Whether the playback credential token is valid for one-time use only. Default is false. true: The token is valid for one-time use only, i.e., it becomes invalid after one verification. false: Can be verified multiple times within the validity period. |
| iswxa | false | Integer | Whether it is for WeChat Mini Program playback. Default is 0. 1: Yes 0: No |
| extraParams | false | String | Custom additional parameters |
| securitySeed | false | String | Custom token encryption factor for private encrypted videos, used to enhance video playback security. Must be used with a designated player. Please consult Polyv customer service for detailed usage rules. |
Example
http://hls.videocc.net/service/v2/token/create-child
Form Parameters:
viewerName=%E8%A7%82%E7%9C%8B%E8%80%85%E6%98%B5%E7%A7%B0&expires=10000&viewerId=ovtl9t_RxnrTdqkXqkT5Q5lnxp2A&appId=a0Wmol5EwX&viewerIp=59.41.20.74&sign=6804C5B24FED47E49776C2CB85823316&videoId=1b448be32370f4822ac40fd926112a66_1&extraParams=ddd&iswxa=1&disposable=true&ts=1617936971500
Response Parameter Description
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Response status code. 200 indicates success, non-200 indicates failure. See Global Error Description |
| status | String | Response status text |
| message | String | Response description. When code is 400 or 500, provides auxiliary error reason. |
| data | Object | On success, returns detailed playback credential information. See data field description. On failure, returns error reason. |
data Field Description
| Field | Type | Description |
|---|---|---|
| token | String | Video playback credential |
| userId | String | Polyv VOD account ID |
| appId | String | Sub-account appId |
| videoId | String | Video ID |
| viewerIp | String | Viewer IP |
| viewerId | String | Viewer ID |
| viewerName | String | Viewer name |
| extraParams | String | Custom additional parameters |
| ttl | Long | Credential token validity period, in milliseconds |
| createdTime | Long | Credential token creation time |
| expiredTime | Long | Credential token expiration time |
| iswxa | Integer | Whether it is for WeChat Mini Program playback 1: Yes 0: No |
| disposable | Boolean | Whether the playback credential token is valid for one-time use only true: The token is valid for one-time use only, i.e., it becomes invalid after one verification false: Can be verified multiple times within the validity period |
Java Request Example
For quick integration of basic code, please download the relevant dependency source code. Click here to download the source code. Add it to your own source project after downloading. HttpUtil.java and VodSignUtil.java in the test cases are included in the downloaded file.
It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides a unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.
private static final Logger log = LoggerFactory.getLogger(VodSubAccountTest.class);
/**
* 获取视频播放凭证
* @throws Exception
* @throws NoSuchAlgorithmException
*/
@Test
public void testCreateSubToken() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String appId = super.appId;
String appSecret = super.appSecret;
String ts = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://hls.videocc.net/service/v2/token/create-child";
String videoId = "1b448be32370f4822ac40fd926112a66_1";
String viewerId = "ovtl9t_RxnrTdqkXqkT5Q5lnxp2A";
String viewerIp = "59.41.20.74";
String viewerName = "观看者昵称";
String expires = "10000";
String disposable = "true";
String isWXa = "1";
String extraParams = "ddd";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("appId", appId);
requestMap.put("videoId", videoId);
requestMap.put("ts", ts);
requestMap.put("viewerId", viewerId);
requestMap.put("viewerIp", viewerIp);
requestMap.put("viewerName", viewerName);
requestMap.put("expires", expires);
requestMap.put("disposable", disposable);
requestMap.put("iswxa", isWXa);
requestMap.put("extraParams", extraParams);
//用md5进行签名,使用子账号的secretKey签名
requestMap.put("sign", VodSignUtil.getSignMd5(requestMap, appSecret));
String response = HttpUtil.postFormBody(url, requestMap);
log.debug("测试获取视频播放凭证,{}", response);
//do somethings
}
Response Example
For global system error descriptions, see Global Error Description
Success Example
{
"code": 200,
"status": "success",
"message": "",
"data": {
"token": "783428b1-8b92-4c56-b255-9e14214b75b9-eesrv9rRagxTktuXtuT8Q8vgaf2A",
"userId": "1b448be323",
"appId": "a0Wmol5EwX",
"videoId": "1b448be32370f4822ac40fd926112a66_1",
"viewerIp": "59.41.20.74",
"viewerId": "ovtl9t_RxnrTdqkXqkT5Q5lnxp2A",
"viewerName": "观看者昵称",
"extraParams": "ddd",
"ttl": 10000000,
"createdTime": 1617936972611,
"expiredTime": 1617946972611,
"iswxa": 1,
"disposable": true
}
}
Error Example
{
"code": 403,
"status": "error",
"message": "sign_not_found",
"data": "sign parameter not found."
}
