sunpengfei
2025-08-06 c97916f276a328fa70696a8582dc0c23144424f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Auth.Sts;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Furion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
 
namespace FlexJobApi.Core
{
    /// <summary>
    /// 阿里云OSS工具
    /// </summary>
    public static class AliyunOSSUtils
    {
        public static GetAliyunOSSAcsQueryResult GetOSSAcs()
        {
            var options = App.GetOptions<AliyunOptions>().OSS;
            IClientProfile profile = DefaultProfile.GetProfile(options.RegionId, options.AccessKeyId, options.AccessSecret);
            DefaultAcsClient client = new DefaultAcsClient(profile);
            AssumeRoleRequest request = new AssumeRoleRequest();
 
            request.Method = MethodType.POST;
            request.RoleArn = options.RoleArn;
            request.RoleSessionName = options.RoleSessionName;
            request.Policy = options.Policy;
            request.DurationSeconds = options.DurationSeconds;
            AssumeRoleResponse response = client.GetAcsResponse(request);
            var result = new GetAliyunOSSAcsQueryResult()
            {
                Expiration = response.Credentials.Expiration,
                OssAccessKeyId = response.Credentials.AccessKeyId,
                OssAccessSecret = response.Credentials.AccessKeySecret,
                SecurityToken = response.Credentials.SecurityToken,
                RequestId = response.RequestId
            };
            return result;
        }
    }
}