diff --git a/YD_Event.Application/Sms/AliyunSmsService.cs b/YD_Event.Application/Sms/AliyunSmsService.cs
index 11f7cd0..7083e16 100644
--- a/YD_Event.Application/Sms/AliyunSmsService.cs
+++ b/YD_Event.Application/Sms/AliyunSmsService.cs
@@ -96,7 +96,14 @@ public class AliyunSmsService : ITransient
TemplateParam = templateParam
};
- // 3. 准备日志实体
+ // 3. 准备运行时配置 (包括重试机制)
+ var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions
+ {
+ Autoretry = true,
+ MaxAttempts = 3 // 异常重试最多3次
+ };
+
+ // 4. 准备日志实体
var log = new SysSmsLog
{
Phone = phone,
@@ -107,10 +114,10 @@ public class AliyunSmsService : ITransient
try
{
- // 4. 发送请求
- var response = await _client.SendSmsAsync(request);
+ // 5. 发送请求
+ var response = await _client.SendSmsWithOptionsAsync(request, runtime);
- // 5. 处理响应
+ // 6. 处理响应
log.ResponseCode = response.Body.Code;
log.ResponseMessage = response.Body.Message;
log.RequestId = response.Body.RequestId;
@@ -127,7 +134,7 @@ public class AliyunSmsService : ITransient
// 阿里云SDK异常
log.Success = false;
log.Exception = $"Code: {error.Code}, Message: {error.Message}, Data: {JsonConvert.SerializeObject(error.Data)}";
- _logger.LogError(error, "阿里云短信发送异常");
+ _logger.LogError(error, "阿里云短信发送异常: {Message}, Recommend: {Recommend}", error.Message, error.Data != null && error.Data.Contains("Recommend") ? error.Data["Recommend"] : "");
throw Oops.Bah("短信服务异常,请稍后重试");
}
catch (Exception ex)
@@ -140,8 +147,11 @@ public class AliyunSmsService : ITransient
}
finally
{
- // 6. 日志持久化
- await _smsLogRepository.InsertAsync(log);
+ // 7. 日志持久化
+ if (_smsLogRepository != null)
+ {
+ await _smsLogRepository.InsertAsync(log);
+ }
}
}
diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml
index bcfb897..0a104fc 100644
--- a/YD_Event.Application/YD_Event.Application.xml
+++ b/YD_Event.Application/YD_Event.Application.xml
@@ -4418,11 +4418,6 @@
名次
-
-
- 证书详细信息DTO
-
-
证书导出DTO
diff --git a/YD_Event.Application/applicationsettings.json b/YD_Event.Application/applicationsettings.json
index c76ca72..ce4bb05 100644
--- a/YD_Event.Application/applicationsettings.json
+++ b/YD_Event.Application/applicationsettings.json
@@ -147,8 +147,10 @@
},
// 阿里云短信配置
"ALiYunSMS": {
+ "AccessKeyId": "LTAI5tPMqz7kp2QUfz2Eb8L2",
+ "AccessKeySecret": "your_access_key_secret",
"Endpoint": "dysmsapi.aliyuncs.com",
- "Sign": "oVpeH1PpDUnWTcBrUSSYkQNS4Fex8Y",
+ "Sign": "上海市跳绳协会",
"Template": "SMS_254100608"
},
// 阿里云ORC识别
diff --git a/YD_Event.Core/Infrastructure/Aliyun/Sms/AliyunSmsService.cs b/YD_Event.Core/Infrastructure/Aliyun/Sms/AliyunSmsService.cs
index 266d3fd..6529c2c 100644
--- a/YD_Event.Core/Infrastructure/Aliyun/Sms/AliyunSmsService.cs
+++ b/YD_Event.Core/Infrastructure/Aliyun/Sms/AliyunSmsService.cs
@@ -104,7 +104,14 @@ public class AliyunSmsService : ITransient
TemplateParam = templateParam
};
- // 3. 准备日志实体
+ // 3. 准备运行时配置 (包括重试机制)
+ var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions
+ {
+ Autoretry = true,
+ MaxAttempts = 3 // 异常重试最多3次
+ };
+
+ // 4. 准备日志实体
var log = new SysSmsLog
{
Phone = phone,
@@ -115,10 +122,10 @@ public class AliyunSmsService : ITransient
try
{
- // 4. 发送请求
- var response = await _client.SendSmsAsync(request);
+ // 5. 发送请求
+ var response = await _client.SendSmsWithOptionsAsync(request, runtime);
- // 5. 处理响应
+ // 6. 处理响应
log.ResponseCode = response.Body.Code;
log.ResponseMessage = response.Body.Message;
log.RequestId = response.Body.RequestId;
@@ -135,7 +142,7 @@ public class AliyunSmsService : ITransient
// 阿里云SDK异常
log.Success = false;
log.Exception = $"Code: {error.Code}, Message: {error.Message}, Data: {JsonConvert.SerializeObject(error.Data)}";
- _logger.LogError(error, "阿里云短信发送异常");
+ _logger.LogError(error, "阿里云短信发送异常: {Message}, Recommend: {Recommend}", error.Message, error.Data != null && error.Data.Contains("Recommend") ? error.Data["Recommend"] : "");
throw Oops.Bah("短信服务异常,请稍后重试");
}
catch (Exception ex)
@@ -148,8 +155,11 @@ public class AliyunSmsService : ITransient
}
finally
{
- // 6. 日志持久化
- await _smsLogRepository.InsertAsync(log);
+ // 7. 日志持久化
+ if (_smsLogRepository != null)
+ {
+ await _smsLogRepository.InsertAsync(log);
+ }
}
}