提交 764e15bd authored 作者: 李秋林's avatar 李秋林

获取阿里云sts_token,返回ducket、region

上级 1139fb66
package com.wangxiaolu.promotion.controller.yun; package com.wangxiaolu.promotion.controller.yun;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.wangxiaolu.promotion.result.basedata.R; import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.utils.AliyunUtils; import com.wangxiaolu.promotion.utils.AliyunUtils;
...@@ -36,7 +37,7 @@ public class AliyunGetToken { ...@@ -36,7 +37,7 @@ public class AliyunGetToken {
@GetMapping("/sts_token") @GetMapping("/sts_token")
public R getStsToken() { public R getStsToken() {
try { try {
String stsToken = aliyunUtils.getStsToken(); JSONObject stsToken = aliyunUtils.getStsToken();
return R.success(stsToken); return R.success(stsToken);
} catch (Exception e) { } catch (Exception e) {
return R.fail(e.getMessage()); return R.fail(e.getMessage());
......
...@@ -3,6 +3,7 @@ package com.wangxiaolu.promotion.utils; ...@@ -3,6 +3,7 @@ package com.wangxiaolu.promotion.utils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.common.utils.BinaryUtil; import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.sts20150401.models.AssumeRoleResponseBody;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
...@@ -182,7 +183,7 @@ public class AliyunUtils { ...@@ -182,7 +183,7 @@ public class AliyunUtils {
} }
} }
public String getStsToken() throws Exception { public JSONObject getStsToken() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(OSS_ACCESS_KEY_ID) .setAccessKeyId(OSS_ACCESS_KEY_ID)
.setAccessKeySecret(OSS_ACCESS_KEY_SECRET); .setAccessKeySecret(OSS_ACCESS_KEY_SECRET);
...@@ -195,8 +196,11 @@ public class AliyunUtils { ...@@ -195,8 +196,11 @@ public class AliyunUtils {
.setRoleSessionName("000516"); .setRoleSessionName("000516");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
com.aliyun.sts20150401.models.AssumeRoleResponse assumeRoleResponse = client.assumeRoleWithOptions(assumeRoleRequest, runtime); com.aliyun.sts20150401.models.AssumeRoleResponse assumeRoleResponse = client.assumeRoleWithOptions(assumeRoleRequest, runtime);
return assumeRoleResponse.body.getCredentials().getSecurityToken();
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论