SpringBoot整合腾讯云点播上传视频接⼝,后端详细代码及步骤!/**
* @Author zhushaojie
* @Date 2020/9/15 11:27
* @Version 1.0
*/
public class Signature {
private String secretId;
private String secretKey;
private long currentTime;
private int random;
private int signValidDuration;
private static final String HMAC_ALGORITHM ="HmacSHA1";
private static final String CONTENT_CHARSET ="UTF-8";
public static byte[]byteMerger(byte[] byte1,byte[] byte2){
byte[] byte3 =new byte[byte1.length + byte2.length];
System.arraycopy(byte1,0, byte3,0, byte1.length);
System.arraycopy(byte2,0, byte3, byte1.length, byte2.length);
return byte3;
}
public String getUploadSignature()throws Exception {
String strSign;
String contextStr ="";
spring教学视频
long endTime =(currentTime + signValidDuration);
contextStr +="secretId="+ de(secretId,"utf8");
contextStr +="¤tTimeStamp="+ currentTime;
contextStr +="&expireTime="+ endTime;
contextStr +="&random="+ random;
try{
Mac mac = Instance(HMAC_ALGORITHM);
SecretKeySpec secretKey =new SecretKeySpec(Bytes(CONTENT_CHARSET), Algorithm());
mac.init(secretKey);
byte[] hash = mac.Bytes(CONTENT_CHARSET));
byte[] sigBuf =byteMerger(hash, Bytes("utf8"));
strSign =new String(new BASE64Encoder().encode(sigBuf).getBytes());
strSign = place(" ","").replace("\n","").replace("\r","");
}catch(Exception e){
throw e;
}
return strSign;
}
public void setSecretId(String secretId){
this.secretId = secretId;
}
public void setSecretKey(String secretKey){
this.secretKey = secretKey;
}
public void setCurrentTime(long currentTime){
this.currentTime = currentTime;
}
public void setRandom(int random){
this.random = random;
}
public void setSignValidDuration(int signValidDuration){
this.signValidDuration = signValidDuration;
}
}
接⼝SignatureController
/**
* @Author zhushaojie
* @Date 2020/9/15 11:28
* @Version 1.0
*/
@Controller
@RequestMapping("/signature")
public class SignatureController{
@RequestMapping("getUgcUploadSign")
@ResponseBody
public OutputObject getUgcUploadSign(){
String secretId ="你的secretId";
String secretKey ="你的secretKey";
Signature sign =new Signature();
sign.setSecretId(secretId);
sign.setSecretKey(secretKey);
sign.setCurrentTime(System.currentTimeMillis()/1000);
sign.setRandom(new Random().nextInt(java.lang.Integer.MAX_VALUE));
sign.setSignValidDuration(3600*24*2);
try{
String signature = UploadSignature();
Map<String, String> map = wHashMap();
map.put("signature", signature);
// return JsonResult.succeed(map);
return new OutputObject(ReturnCode.SUCCESS,"签名获取成功",map);
}catch(Exception e){
e.printStackTrace();
// return JsonResult.fail("获取签名失败");
return new OutputObject(ReturnCode.FAIL,"签名获取失败",null);
}
}
}
到这⾥就结束了,如果有⼩伙伴有疑问可以在下⽅留⾔,或者关注咨询问题!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。