Browse Source

add tencent cloud sms

pull/21651/head
Gary Jia 2 years ago
parent
commit
6064d08e28
No known key found for this signature in database GPG Key ID: 6160CAEE492F0D35
  1. 7
      framework/Volo.Abp.sln
  2. 3
      framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xml
  3. 30
      framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xsd
  4. 3
      framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg
  5. 63
      framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg.analyze.json
  6. 30
      framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj
  7. 15
      framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudModule.cs
  8. 11
      framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/AbpTencentCloudSmsOptions.cs
  9. 7
      framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsProperties.cs
  10. 48
      framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs

7
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}

3
framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false"/>
</Weavers>

30
framework/src/Volo.Abp.Sms.TencentCloud/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

3
framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.abppkg

@ -0,0 +1,3 @@
{
"role": "lib.framework"
}

63
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
}
]
}

30
framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0;net9.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.Sms.TencentCloud</AssemblyName>
<PackageId>Volo.Abp.Sms.TencentCloud</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Sms\Volo.Abp.Sms.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="TencentCloudSDK" />
</ItemGroup>
<ItemGroup>
<PackageVersion Update="TencentCloudSDK" Version="3.0.1142" />
</ItemGroup>
</Project>

15
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<AbpTencentCloudSmsOptions>(configuration.GetSection("AbpTencentCloudSms"));
}
}

11
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";
}

7
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";
}

48
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<AbpTencentCloudSmsOptions> 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);
}
}
Loading…
Cancel
Save