Commit 3c922ae9 authored by 张永's avatar 张永

1

parent eeefcf41
package com.egolm.film.api.web;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.film.api.service.Messages;
import com.egolm.film.util.AliyunUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags={"阿里云接口"})
@Controller
@RequestMapping("aliyun")
public class AliyunApiController {
@Value("${aliyun.sts.accessKeyId}")
private String accessKeyId;
@Value("${aliyun.sts.accessKeySecret}")
private String accessKeySecret;
@Autowired
private Messages messages;
@ResponseBody
@ApiOperation("获取点播授权Auth")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "fileName", dataType = "String", required = true, value = "文件名称(带后缀名)", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "title", dataType = "String", required = true, value = "标题", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "cateId", dataType = "Long", required = true, value = "分类ID", defaultValue = "0"),
@ApiImplicitParam(paramType = "query", name = "tags", dataType = "String", required = false, value = "视频标签,多个用逗号分隔", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "description", dataType = "String", required = false, value = "描述", defaultValue = ""),
})
@RequestMapping(value = "/createUploadVideo",method=RequestMethod.POST)
public Object createUploadVideo(HttpServletRequest request) {
String fileName = request.getParameter("fileName");
String title = request.getParameter("title");
String cateId = request.getParameter("cateId");
String tags = request.getParameter("tags");
String description = request.getParameter("description");
if(!StringUtil.isNotEmpty(fileName,title)) {
return Rjx.jsonErr().setMessage(messages.get("err.param_null"));
}
Map<String,Object> params = new HashMap<String,Object>();
params.put("fileName", fileName);
params.put("title", title);
params.put("cateId", cateId);
params.put("tags", tags);
params.put("description", description);
AliyunUtil aliyunUtil = new AliyunUtil(accessKeyId,accessKeySecret);
CreateUploadVideoResponse response = aliyunUtil.createUploadVideo(params);
return Rjx.jsonOk().set("RequestId", response.getRequestId()).set("UploadAuth", response.getUploadAuth())
.set("UploadAddress", response.getUploadAddress())
.set("VideoId", response.getVideoId());
}
@ResponseBody
@ApiOperation("刷新点播授权")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "videoId", dataType = "String", required = true, value = "点播ID", defaultValue = ""),
})
@RequestMapping(value = "/refreshUploadVideo",method=RequestMethod.GET)
public Object refreshUploadVideo(HttpServletRequest request) {
String videoId = request.getParameter("videoId");
if(!StringUtil.isNotEmpty(videoId)) {
return Rjx.jsonErr().setMessage(messages.get("err.param_null"));
}
AliyunUtil aliyunUtil = new AliyunUtil(accessKeyId,accessKeySecret);
RefreshUploadVideoResponse response = aliyunUtil.refreshUploadVideo(videoId);
if(response != null) {
return Rjx.jsonOk().set("RequestId", response.getRequestId()).set("UploadAuth", response.getUploadAuth()).set("UploadAddress", response.getUploadAddress());
}else {
return Rjx.jsonErr().setMessage("InvalidVideo.NotFound : The video does not exist.");
}
}
@ResponseBody
@ApiOperation("获取播放凭证")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "videoId", dataType = "String", required = true, value = "点播ID", defaultValue = ""),
})
@RequestMapping(value = "/getVideoPlayAuth",method=RequestMethod.GET)
public Object getVideoPlayAuth(HttpServletRequest request) {
String videoId = request.getParameter("videoId");
if(!StringUtil.isNotEmpty(videoId)) {
return Rjx.jsonErr().setMessage(messages.get("err.param_null"));
}
AliyunUtil aliyunUtil = new AliyunUtil(accessKeyId,accessKeySecret);
try {
GetVideoPlayAuthResponse response = aliyunUtil.getVideoPlayAuth(videoId);
if(response != null) {
return Rjx.jsonOk().set("playAuth", response.getPlayAuth()).set("videoMeta", response.getVideoMeta());
}else {
return Rjx.jsonErr().setMessage("InvalidVideo.NotFound : The video does not exist.");
}
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setMessage(e.getMessage());
}
}
}
package com.egolm.film.api.web;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.film.api.service.Messages;
import com.egolm.film.util.AliyunUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags={"阿里云接口"})
@Controller
@RequestMapping("aliyun")
public class AliyunApiController {
@Value("${aliyun.sts.accessKeyId}")
private String accessKeyId;
@Value("${aliyun.sts.accessKeySecret}")
private String accessKeySecret;
@Autowired
private Messages messages;
@ResponseBody
@ApiOperation("获取点播授权Auth")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "fileName", dataType = "String", required = true, value = "文件名称(带后缀名)", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "title", dataType = "String", required = true, value = "标题", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "cateId", dataType = "Long", required = true, value = "分类ID", defaultValue = "0"),
@ApiImplicitParam(paramType = "query", name = "tags", dataType = "String", required = false, value = "视频标签,多个用逗号分隔", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "description", dataType = "String", required = false, value = "描述", defaultValue = ""),
})
@RequestMapping(value = "/createUploadVideo",method=RequestMethod.POST)
public Object createUploadVideo(HttpServletRequest request) {
String fileName = request.getParameter("fileName");
String title = request.getParameter("title");
String cateId = request.getParameter("cateId");
String tags = request.getParameter("tags");
String description = request.getParameter("description");
if(!StringUtil.isNotEmpty(fileName,title)) {
return Rjx.jsonErr().setMessage(messages.get("err.param_null"));
}
Map<String,Object> params = new HashMap<String,Object>();
params.put("fileName", fileName);
params.put("title", title);
params.put("cateId", cateId);
params.put("tags", tags);
params.put("description", description);
AliyunUtil aliyunUtil = new AliyunUtil(accessKeyId,accessKeySecret);
CreateUploadVideoResponse response = aliyunUtil.createUploadVideo(params);
return Rjx.jsonOk().set("RequestId", response.getRequestId()).set("UploadAuth", response.getUploadAuth())
.set("UploadAddress", response.getUploadAddress())
.set("VideoId", response.getVideoId());
}
@ResponseBody
@ApiOperation("刷新点播授权")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "videoId", dataType = "String", required = true, value = "点播ID", defaultValue = ""),
})
@RequestMapping(value = "/refreshUploadVideo",method=RequestMethod.GET)
public Object refreshUploadVideo(HttpServletRequest request) {
String videoId = request.getParameter("videoId");
if(!StringUtil.isNotEmpty(videoId)) {
return Rjx.jsonErr().setMessage(messages.get("err.param_null"));
}
AliyunUtil aliyunUtil = new AliyunUtil(accessKeyId,accessKeySecret);
RefreshUploadVideoResponse response = aliyunUtil.refreshUploadVideo(videoId);
if(response != null) {
return Rjx.jsonOk().set("RequestId", response.getRequestId()).set("UploadAuth", response.getUploadAuth()).set("UploadAddress", response.getUploadAddress());
}else {
return Rjx.jsonErr().setMessage("InvalidVideo.NotFound : The video does not exist.");
}
}
@ResponseBody
@ApiOperation("获取播放凭证")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "videoId", dataType = "String", required = true, value = "点播ID", defaultValue = ""),
})
@RequestMapping(value = "/getVideoPlayAuth",method=RequestMethod.GET)
public Object getVideoPlayAuth(HttpServletRequest request) {
String videoId = request.getParameter("videoId");
if(!StringUtil.isNotEmpty(videoId)) {
return Rjx.jsonErr().setMessage(messages.get("err.param_null"));
}
AliyunUtil aliyunUtil = new AliyunUtil(accessKeyId,accessKeySecret);
try {
GetVideoPlayAuthResponse response = aliyunUtil.getVideoPlayAuth(videoId);
if(response != null) {
return Rjx.jsonOk().set("playAuth", response.getPlayAuth()).set("videoMeta", response.getVideoMeta());
}else {
return Rjx.jsonErr().setCode(-1).setMessage("InvalidVideo.NotFound : The video does not exist.");
}
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setMessage(e.getMessage());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment