60 lines
2.0 KiB
Java
60 lines
2.0 KiB
Java
package com.peanut.modules.sys.controller;
|
|
|
|
import com.aliyun.vod20170321.models.DecryptKMSDataKeyResponseBody;
|
|
import com.aliyun.vod20170321.models.GetPlayInfoResponseBody;
|
|
import com.peanut.common.utils.PlayToken;
|
|
import com.peanut.common.utils.SpdbUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
import java.util.Map;
|
|
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/sys/vodAli")
|
|
public class VodAliController {
|
|
@Autowired
|
|
private PlayToken playToken;
|
|
@Autowired
|
|
private SpdbUtil spdbUtil;
|
|
|
|
@GetMapping("/vodAliVideoRe")
|
|
public byte[] vodAliVideoRe(@RequestParam("CipherText") String cipherText,
|
|
@RequestParam("MtsHlsUriToken") String mtsHlsUriToken){
|
|
|
|
boolean validRe = false;
|
|
try {
|
|
validRe = playToken.validateToken(mtsHlsUriToken);
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
if (!validRe) {
|
|
return Base64.decodeBase64("Illegal access");
|
|
}
|
|
if (null == cipherText) {
|
|
return Base64.decodeBase64("Illegal access !");
|
|
}
|
|
DecryptKMSDataKeyResponseBody decryptKMSDataKeyResponseBody = SpdbUtil.enKMS(cipherText);
|
|
return Base64.decodeBase64(decryptKMSDataKeyResponseBody.getPlaintext());
|
|
}
|
|
|
|
|
|
@PostMapping("/uploadCallback")
|
|
public void uploadCallback(@RequestBody Map<String,Object> map) throws Exception {
|
|
String vid = String.valueOf(map.get("VideoId"));
|
|
spdbUtil.vodTranslationM3u8(vid);
|
|
}
|
|
|
|
@RequestMapping("/getTokenForYLJK")
|
|
public String getTokenForYLJK(String vid) throws Exception {
|
|
String s = playToken.generateToken();
|
|
GetPlayInfoResponseBody urlBody = SpdbUtil.getUrl(vid);
|
|
String url = urlBody==null?null:urlBody.getPlayInfoList().getPlayInfo().get(0).getPlayURL()+"?MtsHlsUriToken="+s;
|
|
return url;
|
|
}
|
|
|
|
|
|
}
|