Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sentinel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sentinel
Commits
71871f45
Commit
71871f45
authored
Oct 29, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://key@gitlab.egolm.com/hanxu/siff-film-api.git
parents
fc015f76
cfa6ca45
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
325 additions
and
32 deletions
+325
-32
pom.xml
pom.xml
+59
-29
AliyunApiController.java
...n/java/com/egolm/film/api/common/AliyunApiController.java
+133
-0
AliyunUtil.java
src/main/java/com/egolm/film/api/util/AliyunUtil.java
+125
-0
application-dev.properties
src/main/resources/application-dev.properties
+6
-1
messages_en_US.properties
src/main/resources/i18n/messages_en_US.properties
+1
-1
messages_zh_CN.properties
src/main/resources/i18n/messages_zh_CN.properties
+1
-1
No files found.
pom.xml
View file @
71871f45
...
...
@@ -16,11 +16,30 @@
<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-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
...
...
@@ -71,6 +90,17 @@
<groupId>
com.sun.mail
</groupId>
<artifactId>
javax.mail
</artifactId>
</dependency>
<dependency>
<groupId>
com.aliyun
</groupId>
<artifactId>
aliyun-java-sdk-core
</artifactId>
<version>
4.1.2
</version>
</dependency>
<dependency>
<groupId>
com.aliyun
</groupId>
<artifactId>
aliyun-java-sdk-vod
</artifactId>
<version>
2.11.6
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/com/egolm/film/api/common/AliyunApiController.java
0 → 100644
View file @
71871f45
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
());
}
}
}
src/main/java/com/egolm/film/api/util/AliyunUtil.java
0 → 100644
View file @
71871f45
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
?
0
l:
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
;
}
}
src/main/resources/application-dev.properties
View file @
71871f45
...
...
@@ -13,3 +13,8 @@ spring.datasource.max-wait=10000
spring.datasource.initial-size
=
10
spring.datasource.max-active
=
100
spring.datasource.min-idle
=
10
###配置阿里云视频点播上传所需要的STS密钥
aliyun.sts.accessKeyId
=
LTAIOtHCCpDLXYp8
aliyun.sts.accessKeySecret
=
9XTHW7P9TTRvCsBHBSclOue2tdWOoa
\ No newline at end of file
src/main/resources/i18n/messages_en_US.properties
View file @
71871f45
...
...
@@ -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.
src/main/resources/i18n/messages_zh_CN.properties
View file @
71871f45
...
...
@@ -12,4 +12,4 @@ err.name_null=\u59D3\u540D\u4E0D\u80FD\u4E3A\u7A7A
err.pwd_null
=
\u
5BC6
\u7801\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
err.pwd_error
=
\u
5BC6
\u7801\u9519\u
8BEF
err.args_nums
=
\u
653E
\u6620\u
53C2
\u6570\u6570\u
91CF
\u9519\u
8BEF
err.param_null
=
\u
53C2
\u6570\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment