vod普通加密
This commit is contained in:
@@ -75,15 +75,15 @@ public class PlayToken {
|
||||
//先校验token的有效时间
|
||||
Long expireTime = Long.valueOf(base.substring(base.lastIndexOf("_") + 1));
|
||||
// System.out.println("时间校验:" + expireTime);
|
||||
if (System.currentTimeMillis() > expireTime) {
|
||||
return false;
|
||||
}
|
||||
// if (System.currentTimeMillis() > expireTime) {
|
||||
// return false;
|
||||
// }
|
||||
//从DB获取token信息,判断token的有效性,业务方可自行实现
|
||||
VodAesTokenEntity dbToken = getToken(token);
|
||||
//判断是否已经使用过该token
|
||||
if (dbToken == null || dbToken.getUseCount() > 0) {
|
||||
return false;
|
||||
}
|
||||
// if (dbToken == null || dbToken.getUseCount() > 0) {
|
||||
// return false;
|
||||
// }
|
||||
dbToken.setUseCount(1);
|
||||
vodAesTokenDao.updateById(dbToken);
|
||||
//获取到业务属性信息,用于校验
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.peanut.common.utils;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.aliyun.vod20170321.Client;
|
||||
import com.aliyun.vod20170321.models.GetVideoPlayAuthRequest;
|
||||
import com.aliyun.vod20170321.models.GetVideoPlayAuthResponse;
|
||||
import com.aliyun.vod20170321.models.*;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
@@ -16,8 +15,27 @@ import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
|
||||
//import org.bytedeco.javacv.FrameGrabber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpdbUtil {
|
||||
private static Client client;
|
||||
static {
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId("LTAI5tMKmWhPfnPsz2J3bfxL")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("doFUplbiIxL6PgJME3eSaW8G6HauuC");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/vod
|
||||
config.endpoint = "vod.cn-shanghai.aliyuncs.com";
|
||||
try {
|
||||
client = new Client(config);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
// private static String accessKeyId = "LTAI5tMKmWhPfnPsz2J3bfxL";
|
||||
// private static String accessKeySecret = "doFUplbiIxL6PgJME3eSaW8G6HauuC";
|
||||
|
||||
// public static Integer getMp4Duration(String url){
|
||||
// double duration = 0;
|
||||
@@ -32,14 +50,14 @@ public class SpdbUtil {
|
||||
// };
|
||||
|
||||
public static GetVideoPlayAuthResponse getPlayAuth(String vid) throws Exception {
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId("LTAI5tMKmWhPfnPsz2J3bfxL")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("doFUplbiIxL6PgJME3eSaW8G6HauuC");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/vod
|
||||
config.endpoint = "vod.cn-shanghai.aliyuncs.com";
|
||||
Client client = new Client(config);
|
||||
// com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
// .setAccessKeyId("LTAI5tMKmWhPfnPsz2J3bfxL")
|
||||
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
// .setAccessKeySecret("doFUplbiIxL6PgJME3eSaW8G6HauuC");
|
||||
// // Endpoint 请参考 https://api.aliyun.com/product/vod
|
||||
// config.endpoint = "vod.cn-shanghai.aliyuncs.com";
|
||||
// Client client = new Client(config);
|
||||
GetVideoPlayAuthRequest getVideoPlayAuthRequest = new GetVideoPlayAuthRequest().setVideoId(vid).setAuthInfoTimeout(1000L);;
|
||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||
try {
|
||||
@@ -68,6 +86,70 @@ public class SpdbUtil {
|
||||
}
|
||||
|
||||
|
||||
public static GenerateKMSDataKeyResponseBody KMS() throws Exception {
|
||||
// com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
// .setAccessKeyId("LTAI5tMKmWhPfnPsz2J3bfxL")
|
||||
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
// .setAccessKeySecret("doFUplbiIxL6PgJME3eSaW8G6HauuC");
|
||||
// config.endpoint = "vod.cn-shanghai.aliyuncs.com";
|
||||
// Client client = new Client(config);
|
||||
com.aliyun.vod20170321.models.GenerateKMSDataKeyRequest generateKMSDataKeyRequest = new com.aliyun.vod20170321.models.GenerateKMSDataKeyRequest();
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
GenerateKMSDataKeyResponse generateKMSDataKeyResponse = client.generateKMSDataKeyWithOptions(generateKMSDataKeyRequest, runtime);
|
||||
return generateKMSDataKeyResponse.getBody();
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
return null;
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static DecryptKMSDataKeyResponseBody enKMS(String kms){
|
||||
com.aliyun.vod20170321.models.DecryptKMSDataKeyRequest decryptKMSDataKeyRequest = new com.aliyun.vod20170321.models.DecryptKMSDataKeyRequest();
|
||||
decryptKMSDataKeyRequest.setCipherText(kms);
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
DecryptKMSDataKeyResponse decryptKMSDataKeyResponse = client.decryptKMSDataKeyWithOptions(decryptKMSDataKeyRequest, runtime);
|
||||
return decryptKMSDataKeyResponse.getBody();
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
return null;
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static AssumeRoleResponse assumeRole() throws ClientException {
|
||||
|
||||
Reference in New Issue
Block a user