Get Video Playback Token
Updated: 2024-12-31 18:37:43
API Description
1、获取Playsafe Token(播放凭证),用于播放加密视频
2、如果一个token尚未过期,此时使用相同的videoId、viewerId、viewerIp、iswxa参数值请求该接口,则会复用原来的token,并延长原token的有效期
3、接口支持https协议
API URL
http://hls.videocc.net/service/v1/token
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| userid | true | String | POLYV VOD account ID. Refer to Get Secret Key. Path: Official Site -> Login -> VOD (API Interface) |
| sign | true | String | Signature, a 32-character uppercase MD5 value. See MD5 Signature Generation Rules |
| videoId | true | String | Video ID, e.g., e6b23c6f519c5906e54a13b8200d7bb0_e |
| ts | true | Long | Current 13-digit millisecond timestamp, valid for 10 minutes |
| viewerId | true | String | Viewer ID. Different viewers must use different IDs, composed of letters and numbers. For mobile requests, viewerId must be base64 encoded |
| viewerIp | false | String | Viewer IP. If empty, the IP of the request caller will be automatically obtained |
| viewerName | false | String | Viewer name |
| expires | false | Long | Token validity duration in seconds. Default is 10 minutes if empty. Maximum validity is 24 hours |
| disposable | false | Boolean | Token validity. Default is false true: Token is valid for one-time use only (invalid after first verification) false: Token can be verified multiple times within the validity period |
| iswxa | false | Integer | Whether it is a WeChat Mini Program playback. Default is 0 1: Yes 0: No |
| type | false | String | Device type for restricting the request source. Values: WEB (web), NATIVE (native) |
| extraParams | false | String | Custom additional parameters |
| securitySeed | false | String | Custom token encryption seed for private encrypted videos, used to enhance video playback security. Must be used with a designated player. Contact POLYV customer service for detailed usage rules |
Example
http://hls.videocc.net/service/v1/token
Form Parameters:
viewerName=ceshi&expires=300&viewerId=ceshiid&viewerIp=127.0.0.1&sign=A5423CC62E20F80AD8812395119E5FA9&videoId=1b448be323b68b2999802799a98dba54_1&iswxa=1&userid=1b448be323&disposable=true&ts=1621851214050
Response Parameters
| 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 error details |
| data | Object | Token-related data returned on success. See data field description |
data Field Description
| Parameter | Type | Description |
|---|---|---|
| token | String | Token value |
| userId | String | POLYV VOD account ID. Refer to Get Secret Key. Path: Official Site -> Login -> VOD (API Interface) |
| appId | String | Account appId. See Get Secret Key |
| videoId | String | Video ID, e.g., e6b23c6f519c5906e54a13b8200d7bb0_e |
| viewerId | String | Viewer ID. Different viewers must use different IDs |
| viewerIp | String | Viewer IP. If empty, the IP of the request caller will be automatically obtained |
| viewerName | String | Viewer name |
| ttl | Long | Token validity duration in milliseconds |
| disposable | Boolean | Token validity true: Token is valid for one-time use only false: Token can be verified multiple times within the validity period |
| iswxa | Integer | Whether it is a WeChat Mini Program playback 1: Yes 0: No |
| extraParams | String | Custom additional parameters |
| createdTime | Long | Token creation time, 13-digit millisecond timestamp |
| expiredTime | Long | Token expiration time, 13-digit millisecond timestamp |
Java Request Example
For quick integration of basic code, please download the relevant dependency source code. Click to download source code. After downloading, add it to your own source project. The test cases HttpUtil.java and VodSignUtil.java are included in the download file.
It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.
private static final Logger log = LoggerFactory.getLogger(VodTokenTest.class);
/**
* 获取视频播放凭证
*/
@Test
public void testCreateToken() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userid = super.userId;
//业务参数
String url = "http://hls.videocc.net/service/v1/token";
String videoId = "1b448be323b68b2999802799a98dba54_1";
String ts = Long.toString(System.currentTimeMillis());
String viewerId = "ceshiid";
String viewerIp = "127.0.0.1";
String viewerName = "ceshi";
String expires = "300";
String disposable = "true";
String iswxa = "1";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("userid", userid);
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);
//用md5进行签名
requestMap.put("sign", VodSignUtil.getSignMd5(requestMap, secretKey));
String response = HttpUtil.postFormBody(url, requestMap);
log.debug("测试获取视频播放凭证,{}", response);
//do somethings
}
Response Example
For global error descriptions, see Global Error Description
Success Example
{
"code": 200,
"status": "success",
"message": "",
"data": {
"token": "586e4510-d584-40de-b4a6-8cd0d363c9d0-smcdibbk",
"userId": "1b448be323",
"appId": null,
"videoId": "1b448be323b68b2999802799a98dba54_1",
"viewerIp": "127.0.0.1",
"viewerId": "ceshiid",
"viewerName": "ceshi",
"extraParams": null,
"ttl": 300000,
"createdTime": 1617776662954,
"expiredTime": 1617776962954,
"iswxa": 1,
"disposable": true
}
}
Error Example
Invalid userid
{
"code": 400,
"status": "error",
"message": "user_not_found",
"data": "user secretKey not found."
}
Expired ts
{
"code": 403,
"status": "error",
"message": "ts_expired",
"data": "ts parameter is expired."
}
Invalid Signature
{
"code": 403,
"status": "error",
"message": "sign_invalid",
"data": "sign parameter invalid."
}
