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.
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using AlibabaCloud.OpenApiClient.Models;
|
|
using AlibabaCloud.SDK.Dysmsapi20170525;
|
|
using AlibabaCloud.SDK.Dysmsapi20170525.Models;
|
|
using Microsoft.Extensions.Logging;
|
|
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
|
|
{
|
|
private readonly ILogger<AliyunSmsHandler> _logger;
|
|
|
|
public AliyunSmsHandler(ILogger<AliyunSmsHandler> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |