Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
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
曲欣亮
shop
Commits
c187e1b4
Commit
c187e1b4
authored
Sep 23, 2019
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取云上传的临时密钥
parent
31fc640f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
216 additions
and
19 deletions
+216
-19
pom.xml
pom.xml
+49
-1
YunController.java
src/main/java/com/egolm/shop/controller/YunController.java
+140
-0
ShopContstrant.java
src/main/java/com/egolm/shop/util/ShopContstrant.java
+27
-18
No files found.
pom.xml
View file @
c187e1b4
...
...
@@ -106,6 +106,42 @@
<artifactId>
sigar
</artifactId>
<version>
1.6.4
</version>
</dependency>
<!-- 阿里云 start -->
<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>
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<!-- <version>2.3.0</version> -->
<version>
2.8.3
</version>
</dependency>
<!-- 阿里云 end -->
<!-- 腾讯云 start -->
<dependency>
<groupId>
com.qcloud
</groupId>
<artifactId>
cos_api
</artifactId>
<version>
5.6.7
</version>
</dependency>
<dependency>
<groupId>
com.tencent.cloud
</groupId>
<artifactId>
cos-sts-java
</artifactId>
<version>
3.0.4
</version>
</dependency>
<!-- 腾讯云 end-->
</dependencies>
<build>
<plugins>
...
...
@@ -135,7 +171,7 @@
</build>
<repositories>
<repository>
<repository>
<id>
my
</id>
<name>
my
</name>
<url>
http://git.egolm.com:9003/nexus/content/groups/public/
</url>
...
...
@@ -150,5 +186,17 @@
<name>
mvnrepository
</name>
<url>
http://mvnrepository.com/
</url>
</repository>
<repository>
<id>
bintray-qcloud-maven-repo
</id>
<name>
qcloud-maven-repo
</name>
<url>
https://dl.bintray.com/qcloud/maven-repo/
</url>
<layout>
default
</layout>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
false
</enabled>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
src/main/java/com/egolm/shop/controller/YunController.java
0 → 100644
View file @
c187e1b4
package
com
.
egolm
.
shop
.
controller
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.egolm.common.StringUtil
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.shop.service.SystemCtrlService
;
import
com.egolm.shop.util.ShopContstrant
;
import
com.tencent.cloud.CosStsClient
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
@Api
(
tags
={
"服务云接口"
})
@RestController
@RequestMapping
(
"yun"
)
public
class
YunController
{
@Autowired
private
SystemCtrlService
systemCtrlService
;
@ApiOperation
(
"获取上传凭证及上传的云平台"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
false
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sign"
,
dataType
=
"String"
,
required
=
true
,
value
=
"签名"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"timestamp"
,
dataType
=
"String"
,
required
=
true
,
value
=
"时间戳"
,
defaultValue
=
""
)
})
@RequestMapping
(
value
=
"/getPolicy"
,
method
=
RequestMethod
.
GET
)
public
String
createGuest
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
Map
<
String
,
Object
>
choiceMap
=
systemCtrlService
.
queryTSystemCtrlByCode
(
ShopContstrant
.
Choice_OSS_KEY
,
"936"
);
if
(
choiceMap
!=
null
)
{
String
value1
=
choiceMap
.
get
(
"sValue1"
)
+
""
;
System
.
out
.
println
(
value1
);
if
(
value1
.
equalsIgnoreCase
(
ShopContstrant
.
Aliyun_OSS_KEY
))
{
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<
String
,
Object
>();
resultMap
.
put
(
"tmpSecretId"
,
""
);
resultMap
.
put
(
"tmpSecretKey"
,
"没做"
);
resultMap
.
put
(
"sessionToken"
,
""
);
resultMap
.
put
(
"webUrl"
,
""
);
resultMap
.
put
(
"region"
,
""
);
resultMap
.
put
(
"bucketName"
,
""
);
resultMap
.
put
(
"type"
,
"aliyun"
);
return
Rjx
.
json
(
resultMap
).
setCode
(
200
).
toString
();
}
if
(
value1
.
equalsIgnoreCase
(
ShopContstrant
.
Tencent_Cos_Key
))
{
int
expiryTime
=
1800
;
//秒
Map
<
String
,
Object
>
expiryMap
=
systemCtrlService
.
queryTSystemCtrlByCode
(
ShopContstrant
.
Tencent_Expiry_Time
,
"936"
);
//过期时间
if
(
expiryMap
!=
null
)
{
try
{
String
expriyMM
=
expiryMap
.
get
(
"sValue1"
)
+
""
;
//分钟
if
(
StringUtil
.
isNotEmpty
(
expriyMM
))
{
expiryTime
=
Integer
.
valueOf
(
expriyMM
)
*
60
;
}
}
catch
(
NumberFormatException
e
)
{
}
}
Map
<
String
,
Object
>
tencentyunMap
=
systemCtrlService
.
queryTSystemCtrlByCode
(
ShopContstrant
.
Tencent_Cos_Key
,
"936"
);
if
(
tencentyunMap
==
null
)
{
return
Rjx
.
jsonErr
().
setMessage
(
"腾讯云COS参数未配置"
).
toJson
();
}
String
region
=
tencentyunMap
.
get
(
"sValue1"
)
+
""
;
String
bucketName
=
tencentyunMap
.
get
(
"sValue2"
)
+
""
;
String
appID
=
tencentyunMap
.
get
(
"sValue3"
)
+
""
;
String
secret
=
tencentyunMap
.
get
(
"sValue4"
)
+
""
;
String
webUrl
=
tencentyunMap
.
get
(
"sValue5"
)+
""
;
TreeMap
<
String
,
Object
>
config
=
new
TreeMap
<
String
,
Object
>();
try
{
// 替换为您的 SecretId
config
.
put
(
"SecretId"
,
appID
);
// 替换为您的 SecretKey
config
.
put
(
"SecretKey"
,
secret
);
// 临时密钥有效时长,单位是秒
config
.
put
(
"durationSeconds"
,
expiryTime
);
// 换成您的 bucket
config
.
put
(
"bucket"
,
bucketName
);
// 换成 bucket 所在地区
config
.
put
(
"region"
,
region
);
// 这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的目录,例子:* 或者 doc/* 或者 picture.jpg
config
.
put
(
"allowPrefix"
,
"*"
);
// 密钥的权限列表。简单上传、表单上传和分片上传需要以下的权限,其他权限列表请看 https://cloud.tencent.com/document/product/436/31923
String
[]
allowActions
=
new
String
[]
{
// 简单上传
"name/cos:PutObject"
,
// 表单上传、小程序上传
"name/cos:PostObject"
,
// 分片上传
"name/cos:InitiateMultipartUpload"
,
"name/cos:ListMultipartUploads"
,
"name/cos:ListParts"
,
"name/cos:UploadPart"
,
"name/cos:CompleteMultipartUpload"
};
config
.
put
(
"allowActions"
,
allowActions
);
System
.
out
.
println
(
config
);
JSONObject
credential
=
CosStsClient
.
getCredential
(
config
);
System
.
out
.
println
(
credential
);
//成功返回临时密钥信息,如下打印密钥信息
JSONObject
credentialObj
=
credential
.
getJSONObject
(
"credentials"
);
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<
String
,
Object
>();
resultMap
.
put
(
"tmpSecretId"
,
credentialObj
.
getString
(
"tmpSecretId"
));
resultMap
.
put
(
"tmpSecretKey"
,
credentialObj
.
getString
(
"tmpSecretKey"
));
resultMap
.
put
(
"sessionToken"
,
credentialObj
.
getString
(
"sessionToken"
));
resultMap
.
put
(
"webUrl"
,
webUrl
);
resultMap
.
put
(
"region"
,
region
);
resultMap
.
put
(
"bucketName"
,
bucketName
);
resultMap
.
put
(
"type"
,
"tencentyun"
);
return
Rjx
.
json
(
resultMap
).
setCode
(
200
).
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
//失败抛出异常
return
Rjx
.
json
().
setMessage
(
"腾讯云临时密钥获取失败"
).
toJson
();
}
}
}
return
Rjx
.
jsonOk
().
toString
();
}
}
src/main/java/com/egolm/shop/util/ShopContstrant.java
View file @
c187e1b4
package
com
.
egolm
.
shop
.
util
;
public
class
ShopContstrant
{
public
static
final
String
CUST_SIGN
=
"T_"
;
//游客账号标记
public
static
final
String
GUEST_LEVEL_TYPE_ID
=
"-1"
;
// 游客 custLevelTypeID 状态
//短信
public
static
final
String
CHOICE_SMS_KEY
=
"ChoiceSmsKey"
;
// 短信选择器
public
static
final
String
SMS_TEMPLATE_CODE
=
"SmsTemplate"
;
//模板字典 code tcommon表
public
static
final
String
SystemCtl_Redis_Base_Key
=
"SystemCtl"
;
//与job服务中缓存的Key一样 存放在 opsForHash中
public
static
final
String
CLIENT_MD5KEY
=
"Client_Md5Key"
;
//客户端计算签名的MD5 Key
}
package
com
.
egolm
.
shop
.
util
;
public
class
ShopContstrant
{
public
static
final
String
CUST_SIGN
=
"T_"
;
//游客账号标记
public
static
final
String
GUEST_LEVEL_TYPE_ID
=
"-1"
;
// 游客 custLevelTypeID 状态
//短信
public
static
final
String
CHOICE_SMS_KEY
=
"ChoiceSmsKey"
;
// 短信选择器
public
static
final
String
SMS_TEMPLATE_CODE
=
"SmsTemplate"
;
//模板字典 code tcommon表
public
static
final
String
SystemCtl_Redis_Base_Key
=
"SystemCtl"
;
//与job服务中缓存的Key一样 存放在 opsForHash中
public
static
final
String
CLIENT_MD5KEY
=
"Client_Md5Key"
;
//客户端计算签名的MD5 Key
//上传的
public
static
final
String
Choice_OSS_KEY
=
"ChoiceOssKEY"
;
//OSS选择
public
static
final
String
Self_OSS_KEY
=
"SelfOssKey"
;
//自建OSS
public
static
final
String
Aliyun_OSS_KEY
=
"AliyunOssKey"
;
//阿里云OSS
public
static
final
String
Tencent_Cos_Key
=
"TencentCosKey"
;
//腾讯云COS
public
static
final
String
Aliyun_Expiry_Time
=
"AliOssFileExpiryTime"
;
//阿里文件 过期时间 单位分钟
public
static
final
String
Tencent_Expiry_Time
=
"TencentExpiryTime"
;
//腾讯文件 过期时间 单位分钟
}
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