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 _logger; public AliyunSmsHandler(ILogger 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); } }