From 6064d08e28a6fd480ec2e46b82b93c0e7e869fee Mon Sep 17 00:00:00 2001 From: Gary Jia Date: Mon, 16 Dec 2024 23:02:29 +0800 Subject: [PATCH 1/3] add tencent cloud sms --- framework/Volo.Abp.sln | 7 +++ .../Volo.Abp.Sms.TencentCloud/FodyWeavers.xml | 3 + .../Volo.Abp.Sms.TencentCloud/FodyWeavers.xsd | 30 +++++++++ .../Volo.Abp.Sms.TencentCloud.abppkg | 3 + ...o.Abp.Sms.TencentCloud.abppkg.analyze.json | 63 +++++++++++++++++++ .../Volo.Abp.Sms.TencentCloud.csproj | 30 +++++++++ .../TencentCloud/AbpSmsTencentCloudModule.cs | 15 +++++ .../TencentCloud/AbpTencentCloudSmsOptions.cs | 11 ++++ .../TencentCloud/TencentCloudSmsProperties.cs | 7 +++ .../Sms/TencentCloud/TencentCloudSmsSender.cs | 48 ++++++++++++++ 10 files changed, 217 insertions(+) create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xml create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xsd create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg.analyze.json create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudModule.cs create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs create mode 100644 framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index ca1a85fd8d..eafe579a13 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -473,6 +473,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BlobStoring.Google EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.ExceptionHandling.Tests", "test\Volo.Abp.ExceptionHandling.Tests\Volo.Abp.ExceptionHandling.Tests.csproj", "{E50739A7-5E2F-4EB5-AEA9-554115CB9613}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Sms.TencentCloud", "src\Volo.Abp.Sms.TencentCloud\Volo.Abp.Sms.TencentCloud.csproj", "{BE7109C5-7368-4688-8557-4A15D3F4776A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1411,6 +1413,10 @@ Global {E50739A7-5E2F-4EB5-AEA9-554115CB9613}.Debug|Any CPU.Build.0 = Debug|Any CPU {E50739A7-5E2F-4EB5-AEA9-554115CB9613}.Release|Any CPU.ActiveCfg = Release|Any CPU {E50739A7-5E2F-4EB5-AEA9-554115CB9613}.Release|Any CPU.Build.0 = Release|Any CPU + {BE7109C5-7368-4688-8557-4A15D3F4776A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE7109C5-7368-4688-8557-4A15D3F4776A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE7109C5-7368-4688-8557-4A15D3F4776A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE7109C5-7368-4688-8557-4A15D3F4776A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1649,6 +1655,7 @@ Global {DEEB5200-BBF9-464D-9B7E-8FC035A27E94} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {40FB8907-9CF7-44D0-8B5F-538AC6DAF8B9} = {447C8A77-E5F0-4538-8687-7383196D04EA} {E50739A7-5E2F-4EB5-AEA9-554115CB9613} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {BE7109C5-7368-4688-8557-4A15D3F4776A} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xml b/framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xml new file mode 100644 index 0000000000..2ad59ce186 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xsd b/framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xsd new file mode 100644 index 0000000000..ffa6fc4b78 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/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.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg new file mode 100644 index 0000000000..f4bad072d2 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg @@ -0,0 +1,3 @@ +{ + "role": "lib.framework" +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg.analyze.json b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg.analyze.json new file mode 100644 index 0000000000..83fe6d66b9 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg.analyze.json @@ -0,0 +1,63 @@ +{ + "name": "Volo.Abp.Sms.TencentCloud", + "hash": "", + "contents": [ + { + "namespace": "Volo.Abp.Sms.TencentCloud", + "dependsOnModules": [ + { + "declaringAssemblyName": "Volo.Abp.Sms", + "namespace": "Volo.Abp.Sms", + "name": "AbpSmsModule" + } + ], + "implementingInterfaces": [ + { + "name": "IAbpModule", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IAbpModule" + }, + { + "name": "IOnPreApplicationInitialization", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IOnPreApplicationInitialization" + }, + { + "name": "IOnApplicationInitialization", + "namespace": "Volo.Abp", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.IOnApplicationInitialization" + }, + { + "name": "IOnPostApplicationInitialization", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IOnPostApplicationInitialization" + }, + { + "name": "IOnApplicationShutdown", + "namespace": "Volo.Abp", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.IOnApplicationShutdown" + }, + { + "name": "IPreConfigureServices", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IPreConfigureServices" + }, + { + "name": "IPostConfigureServices", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IPostConfigureServices" + } + ], + "contentType": "abpModule", + "name": "AbpSmsTencentCloudModule", + "summary": null + } + ] +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj new file mode 100644 index 0000000000..0aeef75e61 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj @@ -0,0 +1,30 @@ + + + + + + netstandard2.0;netstandard2.1;net8.0;net9.0 + enable + Nullable + Volo.Abp.Sms.TencentCloud + Volo.Abp.Sms.TencentCloud + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + + + + + + + + diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudModule.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudModule.cs new file mode 100644 index 0000000000..b846a53e9d --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudModule.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Sms.TencentCloud; + +[DependsOn(typeof(AbpSmsModule))] +public class AbpSmsTencentCloudModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure(configuration.GetSection("AbpTencentCloudSms")); + } +} diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs new file mode 100644 index 0000000000..eb0158b78b --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs @@ -0,0 +1,11 @@ +namespace Volo.Abp.Sms.TencentCloud; + +public class AbpTencentCloudSmsOptions +{ + public string SmsSdkAppId { get; set; } = default!; + public string SecretKey { get; set; } = default!; + public string SecretId { get; set; } = default!; + public string Endpoint { get; set; } = "sms.tencentcloudapi.com"; + public string Region { get; set; } = "ap-guangzhou"; + +} diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs new file mode 100644 index 0000000000..ee198b71cc --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.Sms.TencentCloud; + +public static class TencentCloudSmsProperties +{ + public const string SignName = "SignName"; + public const string TemplateId = "TemplateId"; +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs new file mode 100644 index 0000000000..bf09ad6f20 --- /dev/null +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using TencentCloud.Common; +using TencentCloud.Common.Profile; +using TencentCloud.Sms.V20210111; +using TencentCloud.Sms.V20210111.Models; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Sms.TencentCloud; + +public class TencentCloudSmsSender : ISmsSender, ITransientDependency +{ + protected AbpTencentCloudSmsOptions Options { get; } + + public TencentCloudSmsSender(IOptionsMonitor options) + { + Options = options.CurrentValue; + } + + public async Task SendAsync(SmsMessage smsMessage) + { + var client = CreateClient(); + + await client.SendSms(new SendSmsRequest + { + SmsSdkAppId = Options.SmsSdkAppId, + SignName = smsMessage.Properties.GetOrDefault(TencentCloudSmsProperties.SignName) as string, + TemplateId = smsMessage.Properties.GetOrDefault(TencentCloudSmsProperties.TemplateId) as string, + TemplateParamSet = smsMessage.Text.Split(','), + PhoneNumberSet = [smsMessage.PhoneNumber] + }); + } + + protected virtual SmsClient CreateClient() + { + var cred = new Credential { + SecretId = Options.SecretId, + SecretKey = Options.SecretKey + }; + var clientProfile = new ClientProfile(); + clientProfile.HttpProfile = new HttpProfile() + { + Endpoint = Options.Endpoint + }; + return new SmsClient(cred,Options.Region,clientProfile); + } +} From 905ff36d7f6fc3662a8968f882fdb0dc8743f2dd Mon Sep 17 00:00:00 2001 From: Gary Jia Date: Mon, 16 Dec 2024 23:33:57 +0800 Subject: [PATCH 2/3] add tencent cloud sms test --- Directory.Packages.props | 3 +- framework/Volo.Abp.sln | 7 ++++ .../Volo.Abp.Sms.TencentCloud.csproj | 8 ++--- .../Sms/TencentCloud/TencentCloudSmsSender.cs | 3 +- .../Volo.Abp.Sms.TencentCloud.Tests.abppkg | 3 ++ .../Volo.Abp.Sms.TencentCloud.Tests.csproj | 26 ++++++++++++++ .../AbpSmsTencentCloudTestBase.cs | 11 ++++++ .../AbpSmsTencentCloudTestsModule.cs | 17 +++++++++ .../TencentCloudSmsSenderTests.cs | 36 +++++++++++++++++++ .../appsettings.json | 13 +++++++ 10 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json diff --git a/Directory.Packages.props b/Directory.Packages.props index 0602fe2658..9acb8f8bf7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -168,6 +168,7 @@ + @@ -177,4 +178,4 @@ - + \ No newline at end of file diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index eafe579a13..f716082008 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -475,6 +475,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.ExceptionHandling. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Sms.TencentCloud", "src\Volo.Abp.Sms.TencentCloud\Volo.Abp.Sms.TencentCloud.csproj", "{BE7109C5-7368-4688-8557-4A15D3F4776A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Sms.TencentCloud.Tests", "test\Volo.Abp.Sms.TencenCloud.Tests\Volo.Abp.Sms.TencentCloud.Tests.csproj", "{C753DDD6-5699-45F8-8669-08CE0BB816DE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1417,6 +1419,10 @@ Global {BE7109C5-7368-4688-8557-4A15D3F4776A}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE7109C5-7368-4688-8557-4A15D3F4776A}.Release|Any CPU.ActiveCfg = Release|Any CPU {BE7109C5-7368-4688-8557-4A15D3F4776A}.Release|Any CPU.Build.0 = Release|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1656,6 +1662,7 @@ Global {40FB8907-9CF7-44D0-8B5F-538AC6DAF8B9} = {447C8A77-E5F0-4538-8687-7383196D04EA} {E50739A7-5E2F-4EB5-AEA9-554115CB9613} = {447C8A77-E5F0-4538-8687-7383196D04EA} {BE7109C5-7368-4688-8557-4A15D3F4776A} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {C753DDD6-5699-45F8-8669-08CE0BB816DE} = {447C8A77-E5F0-4538-8687-7383196D04EA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj index 0aeef75e61..3077ff392e 100644 --- a/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj @@ -18,13 +18,9 @@ - - - - - + - + diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs index bf09ad6f20..f0befb4af3 100644 --- a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs @@ -22,7 +22,7 @@ public class TencentCloudSmsSender : ISmsSender, ITransientDependency { var client = CreateClient(); - await client.SendSms(new SendSmsRequest + var result = await client.SendSms(new SendSmsRequest() { SmsSdkAppId = Options.SmsSdkAppId, SignName = smsMessage.Properties.GetOrDefault(TencentCloudSmsProperties.SignName) as string, @@ -30,6 +30,7 @@ public class TencentCloudSmsSender : ISmsSender, ITransientDependency TemplateParamSet = smsMessage.Text.Split(','), PhoneNumberSet = [smsMessage.PhoneNumber] }); + } protected virtual SmsClient CreateClient() diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg new file mode 100644 index 0000000000..a686451fbc --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg @@ -0,0 +1,3 @@ +{ + "role": "lib.test" +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj new file mode 100644 index 0000000000..cd63f915d1 --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj @@ -0,0 +1,26 @@ + + + + + + net9.0 + + + + + + + + + + + + + + + + Always + + + + diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs new file mode 100644 index 0000000000..dfc666f21f --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs @@ -0,0 +1,11 @@ +using Volo.Abp.Testing; + +namespace Volo.Abp.Sms.TencentCloud; + +public class AbpSmsTencentCloudTestBase : AbpIntegratedTest +{ + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } +} diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs new file mode 100644 index 0000000000..f53cef85eb --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Sms.TencentCloud; + +[DependsOn(typeof(AbpSmsTencentCloudModule))] +public class AbpSmsTencentCloudTestsModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure( + configuration.GetSection("AbpTencentCloudSms") + ); + } +} diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs new file mode 100644 index 0000000000..9198f9b86d --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs @@ -0,0 +1,36 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Volo.Abp.Sms.TencentCloud; + +public class TencentCloudSmsSenderTests : AbpSmsTencentCloudTestBase +{ + private readonly ISmsSender _smsSender; + private readonly IConfiguration _configuration; + + public TencentCloudSmsSenderTests() + { + _configuration = GetRequiredService(); + _smsSender = GetRequiredService(); + } + + [Fact] + public async Task SendSms_Test() + { + var config = _configuration.GetSection("AbpTencentCloudSms"); + + // Please fill in the real parameters in the appsettings.json file. + if (config["SecretId"] == "") + { + return; + } + + var msg = new SmsMessage(config["TargetPhoneNumber"], + config["TemplateParam"]); + msg.Properties.Add(TencentCloudSmsProperties.SignName, config["SignName"]); + msg.Properties.Add(TencentCloudSmsProperties.TemplateId, config["TemplateId"]); + + await _smsSender.SendAsync(msg); + } +} diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json new file mode 100644 index 0000000000..44d4611caf --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json @@ -0,0 +1,13 @@ +{ + "AbpTencentCloudSms": { + "SecretId": "", + "SecretKey": "", + "Region": "", + "SmsSdkAppId": "", + "Endpoint": "", + "TargetPhoneNumber": "", + "SignName": "", + "TemplateId": "", + "TemplateParam": "" + } +} \ No newline at end of file From 6cfd5af71ad50af676368a9a1732de74e27003ce Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 17 Dec 2024 16:06:27 +0800 Subject: [PATCH 3/3] Added `Volo.Abp.Sms.TencentCloud` to `common.ps1`. --- .../TencentCloud/AbpTencentCloudSmsOptions.cs | 5 ++++- .../TencentCloud/TencentCloudSmsProperties.cs | 1 + .../Sms/TencentCloud/TencentCloudSmsSender.cs | 18 ++++++++++-------- .../AbpSmsTencentCloudTestsModule.cs | 4 +--- nupkg/common.ps1 | 1 + 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs index eb0158b78b..cec86d9b36 100644 --- a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs @@ -3,9 +3,12 @@ namespace Volo.Abp.Sms.TencentCloud; public class AbpTencentCloudSmsOptions { public string SmsSdkAppId { get; set; } = default!; + public string SecretKey { get; set; } = default!; + public string SecretId { get; set; } = default!; + public string Endpoint { get; set; } = "sms.tencentcloudapi.com"; - public string Region { get; set; } = "ap-guangzhou"; + public string Region { get; set; } = "ap-guangzhou"; } diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs index ee198b71cc..7253a85ba6 100644 --- a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs @@ -3,5 +3,6 @@ public static class TencentCloudSmsProperties { public const string SignName = "SignName"; + public const string TemplateId = "TemplateId"; } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs index f0befb4af3..fa3c585576 100644 --- a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs @@ -18,11 +18,11 @@ public class TencentCloudSmsSender : ISmsSender, ITransientDependency Options = options.CurrentValue; } - public async Task SendAsync(SmsMessage smsMessage) + public virtual async Task SendAsync(SmsMessage smsMessage) { var client = CreateClient(); - var result = await client.SendSms(new SendSmsRequest() + await client.SendSms(new SendSmsRequest() { SmsSdkAppId = Options.SmsSdkAppId, SignName = smsMessage.Properties.GetOrDefault(TencentCloudSmsProperties.SignName) as string, @@ -30,20 +30,22 @@ public class TencentCloudSmsSender : ISmsSender, ITransientDependency TemplateParamSet = smsMessage.Text.Split(','), PhoneNumberSet = [smsMessage.PhoneNumber] }); - } protected virtual SmsClient CreateClient() { - var cred = new Credential { + var credential = new Credential + { SecretId = Options.SecretId, SecretKey = Options.SecretKey }; - var clientProfile = new ClientProfile(); - clientProfile.HttpProfile = new HttpProfile() + var clientProfile = new ClientProfile { - Endpoint = Options.Endpoint + HttpProfile = new HttpProfile + { + Endpoint = Options.Endpoint + } }; - return new SmsClient(cred,Options.Region,clientProfile); + return new SmsClient(credential, Options.Region, clientProfile); } } diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs index f53cef85eb..5062c18867 100644 --- a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs @@ -10,8 +10,6 @@ public class AbpSmsTencentCloudTestsModule : AbpModule { var configuration = context.Services.GetConfiguration(); - Configure( - configuration.GetSection("AbpTencentCloudSms") - ); + Configure(configuration.GetSection("AbpTencentCloudSms")); } } diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 860644dc4b..89264d0b07 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -232,6 +232,7 @@ $projects = ( "framework/src/Volo.Abp.Settings", "framework/src/Volo.Abp.Sms", "framework/src/Volo.Abp.Sms.Aliyun", + "framework/src/Volo.Abp.Sms.TencentCloud", "framework/src/Volo.Abp.Specifications", "framework/src/Volo.Abp.TestBase", "framework/src/Volo.Abp.TextTemplating",