diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 8c2670fa27..d1288de62d 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -361,6 +361,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Tests", "test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.EventBus.Abstractions", "src\Volo.Abp.EventBus.Abstractions\Volo.Abp.EventBus.Abstractions.csproj", "{8FDB3BF7-AD89-43F6-8DEB-C3E29B8801FE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Sms.Aliyun", "src\Volo.Abp.Sms.Aliyun\Volo.Abp.Sms.Aliyun.csproj", "{ACFBA3FB-18CE-4655-9D14-1F1F5C3DFC30}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Sms.Aliyun.Tests", "test\Volo.Abp.Sms.Aliyun.Tests\Volo.Abp.Sms.Aliyun.Tests.csproj", "{DADEA538-3CA1-4ADE-A7E6-EF77A0CE4401}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1075,6 +1079,14 @@ Global {8FDB3BF7-AD89-43F6-8DEB-C3E29B8801FE}.Debug|Any CPU.Build.0 = Debug|Any CPU {8FDB3BF7-AD89-43F6-8DEB-C3E29B8801FE}.Release|Any CPU.ActiveCfg = Release|Any CPU {8FDB3BF7-AD89-43F6-8DEB-C3E29B8801FE}.Release|Any CPU.Build.0 = Release|Any CPU + {ACFBA3FB-18CE-4655-9D14-1F1F5C3DFC30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ACFBA3FB-18CE-4655-9D14-1F1F5C3DFC30}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ACFBA3FB-18CE-4655-9D14-1F1F5C3DFC30}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ACFBA3FB-18CE-4655-9D14-1F1F5C3DFC30}.Release|Any CPU.Build.0 = Release|Any CPU + {DADEA538-3CA1-4ADE-A7E6-EF77A0CE4401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DADEA538-3CA1-4ADE-A7E6-EF77A0CE4401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DADEA538-3CA1-4ADE-A7E6-EF77A0CE4401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DADEA538-3CA1-4ADE-A7E6-EF77A0CE4401}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1257,6 +1269,8 @@ Global {00D07595-993C-40FC-BD90-0DD6331414D3} = {447C8A77-E5F0-4538-8687-7383196D04EA} {A37BFEB5-7C57-4CDC-93B8-B5CE4BB9ACE1} = {447C8A77-E5F0-4538-8687-7383196D04EA} {8FDB3BF7-AD89-43F6-8DEB-C3E29B8801FE} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {ACFBA3FB-18CE-4655-9D14-1F1F5C3DFC30} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {DADEA538-3CA1-4ADE-A7E6-EF77A0CE4401} = {447C8A77-E5F0-4538-8687-7383196D04EA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.Sms.Aliyun/FodyWeavers.xml b/framework/src/Volo.Abp.Sms.Aliyun/FodyWeavers.xml new file mode 100644 index 0000000000..00e1d9a1c1 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.Aliyun/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.Aliyun/FodyWeavers.xsd b/framework/src/Volo.Abp.Sms.Aliyun/FodyWeavers.xsd new file mode 100644 index 0000000000..3f3946e282 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.Aliyun/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.Aliyun/Volo.Abp.Sms.Aliyun.csproj b/framework/src/Volo.Abp.Sms.Aliyun/Volo.Abp.Sms.Aliyun.csproj new file mode 100644 index 0000000000..cae6301daf --- /dev/null +++ b/framework/src/Volo.Abp.Sms.Aliyun/Volo.Abp.Sms.Aliyun.csproj @@ -0,0 +1,24 @@ + + + + + + netstandard2.0 + Volo.Abp.Sms.Aliyun + Volo.Abp.Sms.Aliyun + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + + + + diff --git a/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AbpAliyunSmsOptions.cs b/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AbpAliyunSmsOptions.cs new file mode 100644 index 0000000000..4560e5249e --- /dev/null +++ b/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AbpAliyunSmsOptions.cs @@ -0,0 +1,11 @@ +namespace Volo.Abp.Sms.Aliyun +{ + public class AbpAliyunSmsOptions + { + public string AccessKeySecret { get; set; } + + public string AccessKeyId { get; set; } + + public string EndPoint { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AbpSmsAliyunModule.cs b/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AbpSmsAliyunModule.cs new file mode 100644 index 0000000000..c1ad646981 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AbpSmsAliyunModule.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Sms.Aliyun +{ + [DependsOn(typeof(AbpSmsModule))] + public class AbpSmsAliyunModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure(configuration.GetSection("AbpAliyunSms")); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AliyunSmsSender.cs b/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AliyunSmsSender.cs new file mode 100644 index 0000000000..d9d5f797eb --- /dev/null +++ b/framework/src/Volo.Abp.Sms.Aliyun/Volo/Abp/Sms/Aliyun/AliyunSmsSender.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; +using AliyunClient = AlibabaCloud.SDK.Dysmsapi20170525.Client; +using AliyunConfig = AlibabaCloud.OpenApiClient.Models.Config; +using AliyunSendSmsRequest = AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest; + +namespace Volo.Abp.Sms.Aliyun +{ + public class AliyunSmsSender : ISmsSender, ITransientDependency + { + protected AbpAliyunSmsOptions Options { get; } + + public AliyunSmsSender(IOptionsSnapshot options) + { + Options = options.Value; + } + + public async Task SendAsync(SmsMessage smsMessage) + { + var client = CreateClient(); + + await client.SendSmsAsync(new AliyunSendSmsRequest + { + PhoneNumbers = smsMessage.PhoneNumber, + SignName = smsMessage.Properties.GetOrDefault("SignName") as string, + TemplateCode = smsMessage.Properties.GetOrDefault("TemplateCode") as string, + TemplateParam = smsMessage.Text + }); + } + + private AliyunClient CreateClient() + { + return new(new AliyunConfig + { + AccessKeyId = Options.AccessKeyId, + AccessKeySecret = Options.AccessKeySecret, + Endpoint = Options.EndPoint + }); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo.Abp.Sms.Aliyun.Tests.csproj b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo.Abp.Sms.Aliyun.Tests.csproj new file mode 100644 index 0000000000..d98dd7329a --- /dev/null +++ b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo.Abp.Sms.Aliyun.Tests.csproj @@ -0,0 +1,26 @@ + + + + + + net5.0 + + 9f0d2c00-80c1-435b-bfab-2c39c8249091 + + + + + + + + + + + + + + Always + + + + diff --git a/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AbpSmsAliyunTestBase.cs b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AbpSmsAliyunTestBase.cs new file mode 100644 index 0000000000..976dcda0fd --- /dev/null +++ b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AbpSmsAliyunTestBase.cs @@ -0,0 +1,12 @@ +using Volo.Abp.Testing; + +namespace Volo.Abp.Sms.Aliyun +{ + public class AbpSmsAliyunTestBase : AbpIntegratedTest + { + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AbpSmsAliyunTestsModule.cs b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AbpSmsAliyunTestsModule.cs new file mode 100644 index 0000000000..6213ef160a --- /dev/null +++ b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AbpSmsAliyunTestsModule.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Sms.Aliyun +{ + [DependsOn(typeof(AbpSmsAliyunModule))] + public class AbpSmsAliyunTestsModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure( + configuration.GetSection("AbpAliyunSms") + ); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AliyunSmsSender_Tests.cs b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AliyunSmsSender_Tests.cs new file mode 100644 index 0000000000..667aa30e42 --- /dev/null +++ b/framework/test/Volo.Abp.Sms.Aliyun.Tests/Volo/Abp/Sms/Aliyun/AliyunSmsSender_Tests.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Volo.Abp.Sms.Aliyun +{ + public class AliyunSmsSender_Tests : AbpSmsAliyunTestBase + { + private readonly ISmsSender _smsSender; + private readonly IConfiguration _configuration; + + public AliyunSmsSender_Tests() + { + _configuration = GetRequiredService(); + _smsSender = GetRequiredService(); + } + + [Fact] + public async Task SendSms_Test() + { + var config = _configuration.GetSection("AbpAliyunSms"); + + var msg = new SmsMessage(config["TargetPhoneNumber"], + config["TemplateParam"]); + msg.Properties.Add("SignName", config["SignName"]); + msg.Properties.Add("TemplateCode", config["TemplateCode"]); + + await _smsSender.SendAsync(msg); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Sms.Aliyun.Tests/appsettings.json b/framework/test/Volo.Abp.Sms.Aliyun.Tests/appsettings.json new file mode 100644 index 0000000000..c4370a2928 --- /dev/null +++ b/framework/test/Volo.Abp.Sms.Aliyun.Tests/appsettings.json @@ -0,0 +1,11 @@ +{ + "AbpAliyunSms": { + "AccessKeySecret": "", + "AccessKeyId": "", + "EndPoint": "", + "TargetPhoneNumber": "", + "SignName": "", + "TemplateCode": "", + "TemplateParam": "" + } +} \ No newline at end of file