阿里云配置
This commit is contained in:
parent
0d7c6d9dfa
commit
9e597970f9
@ -96,7 +96,14 @@ public class AliyunSmsService : ITransient
|
|||||||
TemplateParam = templateParam
|
TemplateParam = templateParam
|
||||||
};
|
};
|
||||||
|
|
||||||
// 3. 准备日志实体
|
// 3. 准备运行时配置 (包括重试机制)
|
||||||
|
var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions
|
||||||
|
{
|
||||||
|
Autoretry = true,
|
||||||
|
MaxAttempts = 3 // 异常重试最多3次
|
||||||
|
};
|
||||||
|
|
||||||
|
// 4. 准备日志实体
|
||||||
var log = new SysSmsLog
|
var log = new SysSmsLog
|
||||||
{
|
{
|
||||||
Phone = phone,
|
Phone = phone,
|
||||||
@ -107,10 +114,10 @@ public class AliyunSmsService : ITransient
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 4. 发送请求
|
// 5. 发送请求
|
||||||
var response = await _client.SendSmsAsync(request);
|
var response = await _client.SendSmsWithOptionsAsync(request, runtime);
|
||||||
|
|
||||||
// 5. 处理响应
|
// 6. 处理响应
|
||||||
log.ResponseCode = response.Body.Code;
|
log.ResponseCode = response.Body.Code;
|
||||||
log.ResponseMessage = response.Body.Message;
|
log.ResponseMessage = response.Body.Message;
|
||||||
log.RequestId = response.Body.RequestId;
|
log.RequestId = response.Body.RequestId;
|
||||||
@ -127,7 +134,7 @@ public class AliyunSmsService : ITransient
|
|||||||
// 阿里云SDK异常
|
// 阿里云SDK异常
|
||||||
log.Success = false;
|
log.Success = false;
|
||||||
log.Exception = $"Code: {error.Code}, Message: {error.Message}, Data: {JsonConvert.SerializeObject(error.Data)}";
|
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("短信服务异常,请稍后重试");
|
throw Oops.Bah("短信服务异常,请稍后重试");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -140,8 +147,11 @@ public class AliyunSmsService : ITransient
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// 6. 日志持久化
|
// 7. 日志持久化
|
||||||
await _smsLogRepository.InsertAsync(log);
|
if (_smsLogRepository != null)
|
||||||
|
{
|
||||||
|
await _smsLogRepository.InsertAsync(log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4418,11 +4418,6 @@
|
|||||||
名次
|
名次
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:YD_Event.Application.Event.Dtos.CertificateDetailDto">
|
|
||||||
<summary>
|
|
||||||
证书详细信息DTO
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="T:YD_Event.Application.Event.Dtos.CertificateExportDto">
|
<member name="T:YD_Event.Application.Event.Dtos.CertificateExportDto">
|
||||||
<summary>
|
<summary>
|
||||||
证书导出DTO
|
证书导出DTO
|
||||||
|
|||||||
@ -147,8 +147,10 @@
|
|||||||
},
|
},
|
||||||
// 阿里云短信配置
|
// 阿里云短信配置
|
||||||
"ALiYunSMS": {
|
"ALiYunSMS": {
|
||||||
|
"AccessKeyId": "LTAI5tPMqz7kp2QUfz2Eb8L2",
|
||||||
|
"AccessKeySecret": "your_access_key_secret",
|
||||||
"Endpoint": "dysmsapi.aliyuncs.com",
|
"Endpoint": "dysmsapi.aliyuncs.com",
|
||||||
"Sign": "oVpeH1PpDUnWTcBrUSSYkQNS4Fex8Y",
|
"Sign": "上海市跳绳协会",
|
||||||
"Template": "SMS_254100608"
|
"Template": "SMS_254100608"
|
||||||
},
|
},
|
||||||
// 阿里云ORC识别
|
// 阿里云ORC识别
|
||||||
|
|||||||
@ -104,7 +104,14 @@ public class AliyunSmsService : ITransient
|
|||||||
TemplateParam = templateParam
|
TemplateParam = templateParam
|
||||||
};
|
};
|
||||||
|
|
||||||
// 3. 准备日志实体
|
// 3. 准备运行时配置 (包括重试机制)
|
||||||
|
var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions
|
||||||
|
{
|
||||||
|
Autoretry = true,
|
||||||
|
MaxAttempts = 3 // 异常重试最多3次
|
||||||
|
};
|
||||||
|
|
||||||
|
// 4. 准备日志实体
|
||||||
var log = new SysSmsLog
|
var log = new SysSmsLog
|
||||||
{
|
{
|
||||||
Phone = phone,
|
Phone = phone,
|
||||||
@ -115,10 +122,10 @@ public class AliyunSmsService : ITransient
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 4. 发送请求
|
// 5. 发送请求
|
||||||
var response = await _client.SendSmsAsync(request);
|
var response = await _client.SendSmsWithOptionsAsync(request, runtime);
|
||||||
|
|
||||||
// 5. 处理响应
|
// 6. 处理响应
|
||||||
log.ResponseCode = response.Body.Code;
|
log.ResponseCode = response.Body.Code;
|
||||||
log.ResponseMessage = response.Body.Message;
|
log.ResponseMessage = response.Body.Message;
|
||||||
log.RequestId = response.Body.RequestId;
|
log.RequestId = response.Body.RequestId;
|
||||||
@ -135,7 +142,7 @@ public class AliyunSmsService : ITransient
|
|||||||
// 阿里云SDK异常
|
// 阿里云SDK异常
|
||||||
log.Success = false;
|
log.Success = false;
|
||||||
log.Exception = $"Code: {error.Code}, Message: {error.Message}, Data: {JsonConvert.SerializeObject(error.Data)}";
|
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("短信服务异常,请稍后重试");
|
throw Oops.Bah("短信服务异常,请稍后重试");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -148,8 +155,11 @@ public class AliyunSmsService : ITransient
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// 6. 日志持久化
|
// 7. 日志持久化
|
||||||
await _smsLogRepository.InsertAsync(log);
|
if (_smsLogRepository != null)
|
||||||
|
{
|
||||||
|
await _smsLogRepository.InsertAsync(log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user