chore: add documentation comments and stylecop rules
This commit is contained in:
@@ -13,8 +13,6 @@ namespace TakeoutSaaS.Module.Sms.Services;
|
||||
public sealed class AliyunSmsSender(IHttpClientFactory httpClientFactory, IOptionsMonitor<SmsOptions> optionsMonitor, ILogger<AliyunSmsSender> logger)
|
||||
: ISmsSender
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;
|
||||
|
||||
/// <inheritdoc />
|
||||
public SmsProviderKind Provider => SmsProviderKind.Aliyun;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ public sealed class TencentSmsSender(IHttpClientFactory httpClientFactory, IOpti
|
||||
/// <inheritdoc />
|
||||
public async Task<SmsSendResult> SendAsync(SmsSendRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 1. 读取配置并处理 Mock
|
||||
var options = optionsMonitor.CurrentValue;
|
||||
if (options.UseMock)
|
||||
{
|
||||
@@ -34,6 +35,7 @@ public sealed class TencentSmsSender(IHttpClientFactory httpClientFactory, IOpti
|
||||
return new SmsSendResult { Success = true, Message = "Mocked" };
|
||||
}
|
||||
|
||||
// 2. 构建请求负载与签名所需字段
|
||||
var tencent = options.Tencent;
|
||||
var payload = BuildPayload(request, tencent);
|
||||
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
@@ -44,6 +46,7 @@ public sealed class TencentSmsSender(IHttpClientFactory httpClientFactory, IOpti
|
||||
var stringToSign = BuildStringToSign(canonicalRequest, timestamp, date);
|
||||
var signature = Sign(stringToSign, tencent.SecretKey, date);
|
||||
|
||||
// 3. 构建 HTTP 请求
|
||||
using var httpClient = httpClientFactory.CreateClient(nameof(TencentSmsSender));
|
||||
using var httpRequest = new HttpRequestMessage(HttpMethod.Post, tencent.Endpoint)
|
||||
{
|
||||
@@ -58,6 +61,7 @@ public sealed class TencentSmsSender(IHttpClientFactory httpClientFactory, IOpti
|
||||
httpRequest.Headers.Add("Authorization",
|
||||
$"TC3-HMAC-SHA256 Credential={tencent.SecretId}/{date}/{Service}/tc3_request, SignedHeaders=content-type;host, Signature={signature}");
|
||||
|
||||
// 4. 发送请求并读取响应
|
||||
var response = await httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
|
||||
var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -67,6 +71,7 @@ public sealed class TencentSmsSender(IHttpClientFactory httpClientFactory, IOpti
|
||||
return new SmsSendResult { Success = false, Message = content };
|
||||
}
|
||||
|
||||
// 5. 解析响应
|
||||
using var doc = JsonDocument.Parse(content);
|
||||
var root = doc.RootElement.GetProperty("Response");
|
||||
var status = root.GetProperty("SendStatusSet")[0];
|
||||
|
||||
Reference in New Issue
Block a user