diff --git a/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj b/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj index 6306e4c..39eecb5 100644 --- a/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj +++ b/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj @@ -22,6 +22,7 @@ + diff --git a/BPA.SAAS.Manage.Application/System/AliyunOssServices.cs b/BPA.SAAS.Manage.Application/System/AliyunOssServices.cs new file mode 100644 index 0000000..5cb3938 --- /dev/null +++ b/BPA.SAAS.Manage.Application/System/AliyunOssServices.cs @@ -0,0 +1,27 @@ +using BPA.Aliyun.OSS.Options; +using BPA.SAAS.Manage.Application.System.Dtos; +using BPA.SAAS.Manage.Application.System.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.System +{ + [ApiDescriptionSettings("SYS", Tag = "获取阿里云参数")] + public class AliyunOssServices : ITransient, IDynamicApiController + { + IAliyunOssService _aliyunOssService; + public AliyunOssServices(IAliyunOssService aliyunOssService) + { + _aliyunOssService = aliyunOssService; + } + + [HttpPost("/api/systemconfig/GeneratePostPolicy"), ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task GeneratePostPolicyAsync(Aliyun0ssGeneratePostPolicyRequest request) + { + return await _aliyunOssService.GeneratePostPolicyAsync(request); + } + } +} diff --git a/BPA.SAAS.Manage.Application/System/Dtos/AliyunDto.cs b/BPA.SAAS.Manage.Application/System/Dtos/AliyunDto.cs new file mode 100644 index 0000000..f5583c9 --- /dev/null +++ b/BPA.SAAS.Manage.Application/System/Dtos/AliyunDto.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.System.Dtos +{ + public class Aliyun0ssGeneratePostPolicyRequest + { + /// + /// 根目录 + /// + [DisplayName("根目录")] + [Required(ErrorMessage = "[{0}]不能为空")] + public string Directory { get; set; } + + /// + /// 是否构建唯一目录 + /// + public bool BuildUniqueDirectory { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/System/Interface/IAliyunOssService.cs b/BPA.SAAS.Manage.Application/System/Interface/IAliyunOssService.cs new file mode 100644 index 0000000..e619ed5 --- /dev/null +++ b/BPA.SAAS.Manage.Application/System/Interface/IAliyunOssService.cs @@ -0,0 +1,15 @@ +using BPA.Aliyun.OSS.Options; +using BPA.SAAS.Manage.Application.System.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.System.Interface +{ + public interface IAliyunOssService + { + Task GeneratePostPolicyAsync(Aliyun0ssGeneratePostPolicyRequest request); + } +} diff --git a/BPA.SAAS.Manage.Application/System/Services/AliyunOssService.cs b/BPA.SAAS.Manage.Application/System/Services/AliyunOssService.cs new file mode 100644 index 0000000..69afe6f --- /dev/null +++ b/BPA.SAAS.Manage.Application/System/Services/AliyunOssService.cs @@ -0,0 +1,31 @@ +using BPA.Aliyun.OSS; +using BPA.Aliyun.OSS.Options; +using BPA.SAAS.Manage.Application.System.Dtos; +using BPA.SAAS.Manage.Application.System.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.System.Services +{ + public class AliyunOssService : IAliyunOssService, ITransient + { + private readonly ISqlSugarClient _db; + private AliyunOssClient _aliyunOssClient; + public AliyunOssService(ISqlSugarClient db, AliyunOssClient aliyunOssClient) + { + _db = db; + _aliyunOssClient = aliyunOssClient; + } + + public async Task GeneratePostPolicyAsync(Aliyun0ssGeneratePostPolicyRequest request) + { + var dir = request.Directory; + dir = !dir.EndsWith("/") ? dir + "/" : dir; + var data = await _aliyunOssClient.GeneratePostPolicyAsync(dir); + return data; + } + } +} diff --git a/BPA.SAAS.Manage.Comm/BPA.SAAS.Manage.Comm.csproj b/BPA.SAAS.Manage.Comm/BPA.SAAS.Manage.Comm.csproj index 2232f1b..d1bf158 100644 --- a/BPA.SAAS.Manage.Comm/BPA.SAAS.Manage.Comm.csproj +++ b/BPA.SAAS.Manage.Comm/BPA.SAAS.Manage.Comm.csproj @@ -7,6 +7,7 @@ + diff --git a/BPA.SAAS.Manage.Core/BPA.SAAS.Manage.Core.csproj b/BPA.SAAS.Manage.Core/BPA.SAAS.Manage.Core.csproj index 62a93b8..3b88b94 100644 --- a/BPA.SAAS.Manage.Core/BPA.SAAS.Manage.Core.csproj +++ b/BPA.SAAS.Manage.Core/BPA.SAAS.Manage.Core.csproj @@ -14,6 +14,7 @@ + diff --git a/BPA.SAAS.Manage.Web.Core/BPA.SAAS.Manage.Web.Core.csproj b/BPA.SAAS.Manage.Web.Core/BPA.SAAS.Manage.Web.Core.csproj index df24029..f38bf34 100644 --- a/BPA.SAAS.Manage.Web.Core/BPA.SAAS.Manage.Web.Core.csproj +++ b/BPA.SAAS.Manage.Web.Core/BPA.SAAS.Manage.Web.Core.csproj @@ -16,6 +16,7 @@ + diff --git a/BPA.SAAS.Manage.Web.Core/Startup.cs b/BPA.SAAS.Manage.Web.Core/Startup.cs index bcfaaa4..83e8973 100644 --- a/BPA.SAAS.Manage.Web.Core/Startup.cs +++ b/BPA.SAAS.Manage.Web.Core/Startup.cs @@ -1,10 +1,12 @@ -using BPA.MQTTClient; +using BPA.Aliyun.OSS; +using BPA.MQTTClient; using BPA.SAAS.Manage.Application.System.Dtos; using BPA.SAAS.Manage.Core; using FluentValidation.AspNetCore; using Furion; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using MQTTnet.Client.Connecting; @@ -70,6 +72,11 @@ namespace BPA.SAAS.Manage.Web.Core services.AddControllers() .AddInjectWithUnifyResult(); services.AddMvcFilter(); + services.AddAliyunOss(op => + { + App.Configuration.Bind("BPA:Aliyun:Oss", op); + }); + } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -78,7 +85,7 @@ namespace BPA.SAAS.Manage.Web.Core { app.UseDeveloperExceptionPage(); } - + app.UseHttpsRedirection(); app.UseRouting(); diff --git a/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj b/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj index c6dbf9e..da69600 100644 --- a/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj +++ b/BPA.SAAS.Manage.Web.Entry/BPA.SAAS.Manage.Web.Entry.csproj @@ -12,6 +12,7 @@ + diff --git a/BPA.SAAS.Manage.Web.Entry/appsettings.json b/BPA.SAAS.Manage.Web.Entry/appsettings.json index f21ef60..fd1d125 100644 --- a/BPA.SAAS.Manage.Web.Entry/appsettings.json +++ b/BPA.SAAS.Manage.Web.Entry/appsettings.json @@ -31,6 +31,20 @@ "UserName": "emqx_u_block", "Password": "emqx_p_admin8765490789" }, + "BPA": { + "Aliyun": { + "Oss": { + "AccessKeyId": "LTAI5tGkcsA6HmUL2EyNfYmq", + "AccessKeySecret": "gPCBqVHqnq17f2YikwdtsjExl1NRVF", + "Endpoint": "https://oss-cn-chengdu.aliyuncs.com", + "BucketName": "bpa", //"erphk", + "PresignedUriExpirationMinutes": 1440, + "PolicyExpirationMinutes": 1440, + "ProjectName": "hkerp", + "ServiceName": "test" + } + } + }, "order_url": "http://order", "wechat_url": "http://wechat" } \ No newline at end of file