Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-module-system
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-module-system
Commits
03ad40ec
提交
03ad40ec
authored
9月 17, 2025
作者:
000516
浏览文件
操作
浏览文件
下载
差异文件
添加阿里云oss(卤币学院-bucket)token获取
上级
924827a7
2ae38597
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
93 行增加
和
0 行删除
+93
-0
pom.xml
pom.xml
+9
-0
AliyunGetToken.java
...java/com/sfa/system/controller/aliyun/AliyunGetToken.java
+33
-0
AliyunUtil.java
src/main/java/com/sfa/system/utils/AliyunUtil.java
+51
-0
没有找到文件。
pom.xml
浏览文件 @
03ad40ec
...
@@ -90,6 +90,15 @@
...
@@ -90,6 +90,15 @@
<artifactId>
spring-webmvc
</artifactId>
<artifactId>
spring-webmvc
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
</dependency>
<dependency>
<groupId>
com.aliyun
</groupId>
<artifactId>
sts20150401
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/sfa/system/controller/aliyun/AliyunGetToken.java
0 → 100644
浏览文件 @
03ad40ec
package
com
.
sfa
.
system
.
controller
.
aliyun
;
import
com.alibaba.fastjson.JSONObject
;
import
com.sfa.system.utils.AliyunUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author : liqiulin
* @date : 2025-02-06 13
* @describe :
*/
@Slf4j
@RestController
@RequestMapping
(
"/aliyun/"
)
public
class
AliyunGetToken
{
@Autowired
private
AliyunUtil
aliyunUtil
;
@GetMapping
(
"/sts_token"
)
public
Object
getStsToken
()
{
try
{
JSONObject
stsToken
=
aliyunUtil
.
getStsToken
();
return
stsToken
;
}
catch
(
Exception
e
)
{
return
e
.
getMessage
();
}
}
}
src/main/java/com/sfa/system/utils/AliyunUtil.java
0 → 100644
浏览文件 @
03ad40ec
package
com
.
sfa
.
system
.
utils
;
import
com.alibaba.fastjson.JSONObject
;
import
com.aliyun.sts20150401.Client
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
* @author : liqiulin
* @date : 2025-02-06 13
* @describe :
*/
@Component
public
class
AliyunUtil
{
@Value
(
"${aliyun.access-key-id}"
)
private
String
OSS_ACCESS_KEY_ID
;
@Value
(
"${aliyun.access-key-secret}"
)
private
String
OSS_ACCESS_KEY_SECRET
;
@Value
(
"${aliyun.halogen-oss.region-id}"
)
private
String
REGION_ID
;
@Value
(
"${aliyun.halogen-oss.bucket-name}"
)
private
String
BUCKET_NAME
;
@Value
(
"${aliyun.halogen-oss.web-js-link}"
)
private
String
WEB_JS_LIN
;
@Value
(
"${aliyun.halogen-oss.sts-role-arm}"
)
private
String
OSS_STS_ROLE_ARN
;
public
JSONObject
getStsToken
()
throws
Exception
{
com
.
aliyun
.
teaopenapi
.
models
.
Config
config
=
new
com
.
aliyun
.
teaopenapi
.
models
.
Config
()
.
setAccessKeyId
(
OSS_ACCESS_KEY_ID
)
.
setAccessKeySecret
(
OSS_ACCESS_KEY_SECRET
);
config
.
endpoint
=
"sts."
+
REGION_ID
+
".aliyuncs.com"
;
Client
client
=
new
Client
(
config
);
com
.
aliyun
.
sts20150401
.
models
.
AssumeRoleRequest
assumeRoleRequest
=
new
com
.
aliyun
.
sts20150401
.
models
.
AssumeRoleRequest
()
.
setDurationSeconds
(
3600L
)
.
setRoleArn
(
OSS_STS_ROLE_ARN
)
.
setRoleSessionName
(
"000516"
);
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
runtime
=
new
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
();
com
.
aliyun
.
sts20150401
.
models
.
AssumeRoleResponse
assumeRoleResponse
=
client
.
assumeRoleWithOptions
(
assumeRoleRequest
,
runtime
);
JSONObject
rj
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
assumeRoleResponse
.
body
.
getCredentials
()));
rj
.
put
(
"web_js_link"
,
BUCKET_NAME
);
rj
.
put
(
"region"
,
REGION_ID
);
return
rj
;
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论