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.

64 lines
1.9 KiB
C#

using Microsoft.Extensions.Logging;
using NPin.Framework.Upms.Domain.Shared.Enums;
using NPin.Framework.Upms.Domain.Shared.Model;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Sms.V20210111;
using TencentCloud.Sms.V20210111.Models;
using Volo.Abp.DependencyInjection;
namespace NPin.Framework.Upms.Domain.Sms.Handler;
public class TencentSmsHandler : ISms, ISingletonDependency
{
private readonly ILogger<AliyunSmsHandler> _logger;
public TencentSmsHandler(ILogger<AliyunSmsHandler> logger)
{
_logger = logger;
}
public SmsProviderTypeEnum ProviderType => SmsProviderTypeEnum.Tencent;
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
{
PhoneNumberSet = phoneNumbers.Split(','),
SignName = template.SignName,
TemplateId = template.TemplateCode,
TemplateParamSet = templateParam as string[]
};
var response = await client.SendSms(sendSmsRequest);
// TODO 判断结果
_logger.LogDebug(response.ToString());
}
private SmsClient CreateClient(SmsProvider provider)
{
var cred = new Credential
{
SecretId = provider.AccessKeyId,
SecretKey = provider.AccessKeySecret,
};
var httpProfile = new HttpProfile
{
Endpoint = provider.Endpoint,
};
var clientProfile = new ClientProfile()
{
HttpProfile = httpProfile
};
return new SmsClient(cred, provider.Region, clientProfile);
}
}