|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
public ILogger<TencentSmsHandler> Logger { get; set; }
|
|
|
|
|
|
|
|
|
|
public TencentSmsHandler()
|
|
|
|
|
{
|
|
|
|
|
Logger = NullLogger<TencentSmsHandler>.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|