vod普通加密
This commit is contained in:
@@ -25,11 +25,7 @@ import java.net.URI;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class HlsDecryptService {
|
||||
@Autowired
|
||||
private PlayToken playToken;
|
||||
private static DefaultAcsClient client;
|
||||
|
||||
static {
|
||||
@@ -79,7 +75,7 @@ public class HlsDecryptService {
|
||||
String token = getMtsHlsUriToken(httpExchange);
|
||||
boolean validRe = false;
|
||||
try {
|
||||
validRe = playToken.validateToken(token);
|
||||
// validRe = playToken.validateToken(token);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -201,7 +197,6 @@ public class HlsDecryptService {
|
||||
// System.out.println("hls decrypt server started");
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws IOException {
|
||||
// HlsDecryptService server = new HlsDecryptService();
|
||||
serviceBootStrap();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.peanut.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.aliyun.vod20170321.Client;
|
||||
@@ -150,6 +151,68 @@ public class SpdbUtil {
|
||||
}
|
||||
|
||||
|
||||
public static void startM3u8(String vid,String edk){
|
||||
com.aliyun.vod20170321.models.SubmitTranscodeJobsRequest submitTranscodeJobsRequest = new com.aliyun.vod20170321.models.SubmitTranscodeJobsRequest();
|
||||
submitTranscodeJobsRequest.setVideoId(vid);
|
||||
submitTranscodeJobsRequest.setTemplateGroupId("d346d2609a058b9dfd9b8bb392175721");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("CipherText",edk);
|
||||
jsonObject.put("DecryptKeyUri","http://59.110.212.44:8099?CipherText="+edk);
|
||||
jsonObject.put("KeyServiceType","KMS");
|
||||
submitTranscodeJobsRequest.setEncryptConfig(jsonObject.toJSONString());
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.submitTranscodeJobsWithOptions(submitTranscodeJobsRequest, runtime);
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static GetPlayInfoResponseBody getUrl(String vid){
|
||||
com.aliyun.vod20170321.models.GetPlayInfoRequest getPlayInfoRequest = new com.aliyun.vod20170321.models.GetPlayInfoRequest();
|
||||
getPlayInfoRequest.setVideoId(vid);
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
GetPlayInfoResponse playInfoWithOptions = client.getPlayInfoWithOptions(getPlayInfoRequest, runtime);
|
||||
GetPlayInfoResponseBody body = playInfoWithOptions.getBody();
|
||||
return body;
|
||||
} 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 {
|
||||
|
||||
@@ -39,5 +39,7 @@ public class CourseCatalogueChapterVideoEntity {
|
||||
@TableField(exist = false)
|
||||
private String Mp4Url;
|
||||
@TableField(exist = false)
|
||||
private String m3u8Url;
|
||||
@TableField(exist = false)
|
||||
private String MtsHlsUriToken;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.peanut.modules.master.controller;
|
||||
|
||||
import com.aliyun.vod20170321.models.GenerateKMSDataKeyResponseBody;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.utils.SpdbUtil;
|
||||
import com.peanut.modules.common.dao.VideoM3u8Dao;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.to.EditCourseRecordDto;
|
||||
import com.peanut.modules.common.to.ParamTo;
|
||||
@@ -35,6 +38,8 @@ public class CourseController {
|
||||
private SysCourseDirectService sysCourseDirectService;
|
||||
@Autowired
|
||||
private ShopProductService shopProductService;
|
||||
@Autowired
|
||||
private VideoM3u8Dao videoM3u8Dao;
|
||||
|
||||
|
||||
@RequestMapping("/getCourseList")
|
||||
@@ -60,6 +65,19 @@ public class CourseController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/pushM3u8Video")
|
||||
public R pushM3u8Video(@RequestBody Map<String,String> map) throws Exception {
|
||||
String s = map.get("vid");
|
||||
GenerateKMSDataKeyResponseBody kms = SpdbUtil.KMS();
|
||||
VideoM3u8Entity videoM3u8Entity = new VideoM3u8Entity();
|
||||
assert kms != null;
|
||||
videoM3u8Entity.setEdk(kms.getCiphertextBlob());
|
||||
videoM3u8Entity.setVid(s);
|
||||
videoM3u8Dao.insert(videoM3u8Entity);
|
||||
SpdbUtil.startM3u8(s,kms.getCiphertextBlob());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/getCoursedetail")
|
||||
public R getCoursedetail(@RequestBody ParamTo param){
|
||||
CourseEntity course = courseService.getById(param.getId());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.peanut.modules.master.service.impl;
|
||||
|
||||
import com.aliyun.vod20170321.models.GetPlayInfoResponseBody;
|
||||
import com.aliyun.vod20170321.models.GetVideoPlayAuthResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -109,7 +110,10 @@ public class CourseCatalogueChapterVideoServiceImpl extends ServiceImpl<CourseCa
|
||||
String playAuth = p.getBody().getPlayAuth();
|
||||
video.setPlayAuth(playAuth);
|
||||
String s = playToken.generateToken();
|
||||
GetPlayInfoResponseBody urlBody = SpdbUtil.getUrl(video.getVideo());
|
||||
String url = urlBody==null?null:urlBody.getPlayInfoList().getPlayInfo().get(0).getPlayURL()+"?MtsHlsUriToken="+s;
|
||||
video.setMtsHlsUriToken(s);
|
||||
video.setM3u8Url(url);
|
||||
}
|
||||
UserCourseVideoPositionEntity videoPosition = getVideoPosition(video, uId);
|
||||
video.setUserCourseVideoPositionEntity(videoPosition);
|
||||
|
||||
@@ -218,6 +218,14 @@ public class CourseController {
|
||||
return R.ok().put("result",decryptKMSDataKeyResponseBody);
|
||||
}
|
||||
|
||||
@RequestMapping("/mytt2")
|
||||
public R mytt2(@RequestBody Map<String,String> map){
|
||||
GetPlayInfoResponseBody urlbody = SpdbUtil.getUrl(map.get("vid"));
|
||||
String url = urlbody==null?null:urlbody.getPlayInfoList().getPlayInfo().get(0).getPlayURL();
|
||||
return R.ok().put("result",url);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/ttt")
|
||||
@SneakyThrows
|
||||
public R ttt(){
|
||||
|
||||
@@ -1,20 +1,39 @@
|
||||
package com.peanut.modules.sys.controller;
|
||||
|
||||
import com.aliyun.vod20170321.models.DecryptKMSDataKeyResponseBody;
|
||||
import com.peanut.common.utils.PlayToken;
|
||||
import com.peanut.common.utils.SpdbUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/vodAli")
|
||||
public class VodAliController {
|
||||
@Autowired
|
||||
private PlayToken playToken;
|
||||
|
||||
@GetMapping("/vodAliVideoRe")
|
||||
public String vodAliVideoRe(@RequestParam("CipherText") String cipherText,
|
||||
@RequestParam("MtsHlsUriToken") String mtsHlsUriToken){
|
||||
|
||||
@RequestMapping("/vodAliVideoRe")
|
||||
public void vodAliVideoRe(@RequestBody Map<String,Object> map){
|
||||
boolean validRe = false;
|
||||
try {
|
||||
validRe = playToken.validateToken(mtsHlsUriToken);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (!validRe) {
|
||||
return "Illegal access";
|
||||
}
|
||||
if (null == cipherText)
|
||||
return "Illegal access";
|
||||
|
||||
DecryptKMSDataKeyResponseBody decryptKMSDataKeyResponseBody = SpdbUtil.enKMS(cipherText);
|
||||
return decryptKMSDataKeyResponseBody.getPlaintext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user