You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using AlibabaCloud.OpenApiClient.Models;
|
|
using AlibabaCloud.SDK.Dysmsapi20170525;
|
|
using AlibabaCloud.SDK.Dysmsapi20170525.Models;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Newtonsoft.Json;
|
|
using NPin.Framework.Upms.Domain.Shared.Enums;
|
|
using NPin.Framework.Upms.Domain.Shared.Model;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace NPin.Framework.Upms.Domain.Sms.Handler;
|
|
|
|
public class AliyunSmsHandler : ISms, ISingletonDependency
|
|
{
|
|
public ILogger<AliyunSmsHandler> Logger { get; set; }
|
|
|
|
public AliyunSmsHandler()
|
|
{
|
|
Logger = NullLogger<AliyunSmsHandler>.Instance;
|
|
}
|
|
|
|
public SmsProviderTypeEnum ProviderType => SmsProviderTypeEnum.Aliyun;
|
|
|
|
public async Task SendSmsAsync(SmsConfigModel config, SmsSettings settings, string phoneNumbers,
|
|
object templateParam)
|
|
{
|
|
var client = CreateClient(config.GetProvider(settings));
|
|
var template = config.GetTemplate(settings);
|
|
|
|
var sendSmsRequest = new SendSmsRequest
|
|
{
|
|
PhoneNumbers = phoneNumbers,
|
|
SignName = template.SignName,
|
|
TemplateCode = template.TemplateCode,
|
|
TemplateParam = JsonConvert.SerializeObject(templateParam)
|
|
};
|
|
|
|
var response = await client.SendSmsAsync(sendSmsRequest);
|
|
|
|
// TODO 判断结果
|
|
Logger.LogDebug(response.ToString());
|
|
}
|
|
|
|
private Client CreateClient(SmsProvider provider)
|
|
{
|
|
var config = new Config()
|
|
{
|
|
AccessKeyId = provider.AccessKeyId,
|
|
AccessKeySecret = provider.AccessKeySecret,
|
|
Endpoint = provider.Endpoint,
|
|
RegionId = provider.Region,
|
|
};
|
|
return new Client(config);
|
|
}
|
|
} |