Commit cfa6ca45 authored by zhangyong's avatar zhangyong

增加阿里云视频

parent 7502085e
......@@ -5,34 +5,53 @@
<groupId>com.egolm</groupId>
<artifactId>siff-film-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<start-class>com.egolm.film.FilmApplication</start-class>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<repositories>
<repository>
<id>sonatype-nexus-staging</id>
<name>Sonatype Nexus Staging</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.38</version>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.38</version>
</dependency>
<dependency>
<groupId>com.egolm</groupId>
......@@ -40,9 +59,9 @@
<version>0.0.1-RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
......@@ -55,22 +74,33 @@
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-vod</artifactId>
<version>2.11.6</version>
</dependency>
</dependencies>
<build>
<plugins>
......
package com.egolm.film.api.common;
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.common.service.Messages;
import com.egolm.film.api.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("获取点播授权STS")
@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.util;
import java.util.Map;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoRequest;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoRequest;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
public class AliyunUtil {
private static String accessKeyId = "";//"LTAIOtHCCpDLXYp8";
private static String accessKeySecret = "";//"9XTHW7P9TTRvCsBHBSclOue2tdWOoa";
private final DefaultAcsClient aliyunClient;
public AliyunUtil() {
this.aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret));
}
public AliyunUtil(String accessKeyId,String accessKeySecret) {
this.aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret));
}
/**
*
* @Title: createUploadVideo @Description: 获取视频上传凭证和地址 @param: @param
* client @param: @return @return: String @throws
*/
public CreateUploadVideoResponse createUploadVideo(Map<String,Object> params) {
CreateUploadVideoRequest request = new CreateUploadVideoRequest();
CreateUploadVideoResponse response = null;
try {
/*
* 必选,视频源文件名称(必须带后缀, 支持 ".3gp", ".asf", ".avi", ".dat", ".dv", ".flv", ".f4v",
* ".gif", ".m2t", ".m3u8", ".m4v", ".mj2", ".mjpeg", ".mkv", ".mov", ".mp4",
* ".mpe", ".mpg", ".mpeg", ".mts", ".ogg", ".qt", ".rm", ".rmvb", ".swf",
* ".ts", ".vob", ".wmv", ".webm"".aac", ".ac3", ".acm", ".amr", ".ape", ".caf",
* ".flac", ".m4a", ".mp3", ".ra", ".wav", ".wma")
*/
request.setFileName(params.get("fileName")+"");
// 必选,视频标题
request.setTitle(params.get("title")+"");
// 可选,分类ID
request.setCateId(params.get("cateId")==null?0l:Long.valueOf(params.get("cateId")+""));
// 可选,视频标签,多个用逗号分隔
request.setTags(params.get("tags")+"");
// 可选,视频描述
request.setDescription(params.get("description")+"");
response = aliyunClient.getAcsResponse(request);
} catch (ServerException e) {
System.out.println("CreateUploadVideoRequest Server Exception:");
e.printStackTrace();
return null;
} catch (ClientException e) {
System.out.println("CreateUploadVideoRequest Client Exception:");
e.printStackTrace();
return null;
}
System.out.println("RequestId:" + response.getRequestId());
System.out.println("UploadAuth:" + response.getUploadAuth());
System.out.println("UploadAddress:" + response.getUploadAddress());
return response;
}
/**
*
* @Title: refreshUploadVideo
* @Description: 刷新视频上传凭证
* @param: @param client
* @param: @param videoId
* @return: void
* @throws
*/
public RefreshUploadVideoResponse refreshUploadVideo(String videoId) {
RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
RefreshUploadVideoResponse response = null;
try {
request.setVideoId(videoId);
response = aliyunClient.getAcsResponse(request);
System.out.println("RequestId:" + response.getRequestId());
System.out.println("UploadAuth:" + response.getUploadAuth());
} catch (ServerException e) {
System.out.println("RefreshUploadVideoRequest Server Exception:");
e.printStackTrace();
} catch (ClientException e) {
System.out.println("RefreshUploadVideoRequest Client Exception:");
e.printStackTrace();
}
return response;
}
/**
*
* @Title: getVideoPlayAuth
* @Description: 获取播放凭证
* @param: @param videoId
* @param: @return
* @return: GetVideoPlayAuthResponse
* @throws
*/
public GetVideoPlayAuthResponse getVideoPlayAuth(String videoId) {
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
request.setVideoId(videoId);
GetVideoPlayAuthResponse response = null;
try {
response = aliyunClient.getAcsResponse(request);
} catch (ServerException e) {
throw new RuntimeException("GetVideoPlayAuthRequest Server failed");
} catch (ClientException e) {
throw new RuntimeException("GetVideoPlayAuthRequest Client failed");
}
response.getPlayAuth(); //播放凭证
response.getVideoMeta(); //视频Meta信息
return response;
}
}
......@@ -12,4 +12,9 @@ spring.datasource.min-evictable-idle-time-millis=1800000
spring.datasource.max-wait=10000
spring.datasource.initial-size=10
spring.datasource.max-active=100
spring.datasource.min-idle=10
\ No newline at end of file
spring.datasource.min-idle=10
###配置阿里云视频点播上传所需要的STS密钥
aliyun.sts.accessKeyId=LTAIOtHCCpDLXYp8
aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
\ No newline at end of file
......@@ -12,4 +12,4 @@ err.name_null=The username can not be empty
err.pwd_null=The password can not be empty
err.pwd_error=Password error
err.args_nums=Incorrect number of parameters
err.param_null=Parameter can not be empty.
......@@ -12,4 +12,4 @@ err.name_null=\u59D3\u540D\u4E0D\u80FD\u4E3A\u7A7A
err.pwd_null=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
err.pwd_error=\u5BC6\u7801\u9519\u8BEF
err.args_nums=\u653E\u6620\u53C2\u6570\u6570\u91CF\u9519\u8BEF
err.param_null=\u53C2\u6570\u4E0D\u80FD\u4E3A\u7A7A
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