Files
TakeoutSaaS.TenantApi/src/Modules/TakeoutSaaS.Module.Sms/Services/AliyunSmsSender.cs

35 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using TakeoutSaaS.Module.Sms.Abstractions;
using TakeoutSaaS.Module.Sms.Models;
using TakeoutSaaS.Module.Sms.Options;
namespace TakeoutSaaS.Module.Sms.Services;
/// <summary>
/// 阿里云短信发送实现(简化版,占位可扩展正式签名流程)。
/// </summary>
public sealed class AliyunSmsSender(IHttpClientFactory httpClientFactory, IOptionsMonitor<SmsOptions> optionsMonitor, ILogger<AliyunSmsSender> logger)
: ISmsSender
{
/// <inheritdoc />
public SmsProviderKind Provider => SmsProviderKind.Aliyun;
/// <inheritdoc />
public Task<SmsSendResult> SendAsync(SmsSendRequest request, CancellationToken cancellationToken = default)
{
var options = optionsMonitor.CurrentValue;
if (options.UseMock)
{
logger.LogInformation("Mock 发送阿里云短信到 {Phone}, Template:{Template}", request.PhoneNumber, request.TemplateCode);
return Task.FromResult(new SmsSendResult { Success = true, Message = "Mocked" });
}
// 预留 HttpClient便于后续接入阿里云正式签名请求
using var httpClient = httpClientFactory.CreateClient(nameof(AliyunSmsSender));
// 占位:保留待接入阿里云正式签名流程,当前返回未实现。
logger.LogWarning("阿里云短信尚未启用,请配置腾讯云或开启 UseMock。");
return Task.FromResult(new SmsSendResult { Success = false, Message = "Aliyun SMS not enabled" });
}
}