mirror of https://github.com/abpframework/abp.git
12 changed files with 239 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait /> |
|||
</Weavers> |
|||
@ -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> |
|||
@ -0,0 +1,24 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<Import Project="..\..\..\configureawait.props"/> |
|||
<Import Project="..\..\..\common.props"/> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.Sms.Aliyun</AssemblyName> |
|||
<PackageId>Volo.Abp.Sms.Aliyun</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="AlibabaCloud.SDK.Dysmsapi20170525" Version="1.0.2"/> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -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; } |
|||
} |
|||
} |
|||
@ -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<AbpAliyunSmsOptions>(configuration.GetSection("AbpAliyunSms")); |
|||
} |
|||
} |
|||
} |
|||
@ -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<AbpAliyunSmsOptions> 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 |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.test.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
<RootNamespace /> |
|||
<UserSecretsId>9f0d2c00-80c1-435b-bfab-2c39c8249091</UserSecretsId> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Sms.Aliyun\Volo.Abp.Sms.Aliyun.csproj" /> |
|||
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" /> |
|||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="$(MicrosoftPackageVersion)" /> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Remove="appsettings.json" /> |
|||
<Content Include="appsettings.json"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</Content> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,12 @@ |
|||
using Volo.Abp.Testing; |
|||
|
|||
namespace Volo.Abp.Sms.Aliyun |
|||
{ |
|||
public class AbpSmsAliyunTestBase : AbpIntegratedTest<AbpSmsAliyunTestsModule> |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
} |
|||
@ -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<AbpAliyunSmsOptions>( |
|||
configuration.GetSection("AbpAliyunSms") |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -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<IConfiguration>(); |
|||
_smsSender = GetRequiredService<ISmsSender>(); |
|||
} |
|||
|
|||
[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); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
{ |
|||
"AbpAliyunSms": { |
|||
"AccessKeySecret": "<Enter your AccessKeySecret from Aliyun>", |
|||
"AccessKeyId": "<Enter your AccessKeyId from Aliyun>", |
|||
"EndPoint": "<Enter your EndPoint from Aliyun>", |
|||
"TargetPhoneNumber": "<Enter the target phone number to receive the SMS>", |
|||
"SignName": "<Enter the SignName from Aliyun>", |
|||
"TemplateCode": "<Enter the TemplateCode you need to send>", |
|||
"TemplateParam": "<Enter the template parameters>" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue