This commit is contained in:
tongfei
2024-03-30 13:32:15 +08:00
parent 23e4cdb50c
commit 24799c5ff9
2 changed files with 41 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ namespace WMS.Web.Domain.IService
/// <param name="phoneNumbers"></param>
/// <param name="content"></param>
/// <returns></returns>
bool SendSms(string phoneNumbers, string content);
Result SendSms(string phoneNumbers, string content);
/// <summary>
/// 邮箱发送

View File

@@ -67,7 +67,7 @@ namespace WMS.Web.Domain.Services
/// <param name="phoneNumbers"></param>
/// <param name="content"></param>
/// <returns></returns>
public bool SendSms(string phoneNumbers, string content)
public Result SendSms(string phoneNumbers, string content)
{
// 构造短信请求
SendSmsRequest request = new SendSmsRequest();
@@ -81,18 +81,29 @@ namespace WMS.Web.Domain.Services
{
// 发送短信
SendSmsResponse response = client.GetAcsResponse(request);
_logger.LogInformation($"短信发送消息:成功->短信签名:{_smsOptions.SignName}->手机号码:" + phoneNumbers + " 内容:" + content);
return true;
//isv.PARAM_LENGTH_LIMIT
if (response.Code == "OK")
{
_logger.LogInformation($"短信发送消息:成功->短信签名:{_smsOptions.SignName}->手机号码:" + phoneNumbers + " 内容:" + content);
return Result.ReSuccess();
}
else
{
_logger.LogInformation($"短信发送消息:失败->原因:{response.Message}->短信签名:{_smsOptions.SignName}->手机号码:" + phoneNumbers + " 内容:" + content);
return Result.ReFailure(response.Code,6000);
}
}
catch (ServerException e)
{
_logger.LogInformation($"短信发送消息Server失败:{e.ErrorMessage}->手机号码:" + phoneNumbers + " 内容:" + content);
return false;
return Result.ReFailure(e.ErrorMessage, 6000);
}
catch (ClientException e)
{
_logger.LogInformation($"短信发送消息Client失败:{e.ErrorMessage}->手机号码:" + phoneNumbers + " 内容:" + content);
return false;
return Result.ReFailure(e.ErrorMessage, 6000);
}
}
@@ -240,7 +251,18 @@ namespace WMS.Web.Domain.Services
//邮箱
await this.SendEmail(item.EmailList, content, item.CustomerName);
//短信
this.SendSms(item.PhoneNumbers, content);
var sms_result= this.SendSms(item.PhoneNumbers, content);
//内容过长-分段发送
if (!sms_result.IsSuccess && sms_result.Message== "isv.PARAM_LENGTH_LIMIT")
{
//分段发送以字数480长度分段
var contentParts= this.SplitContent(content, 480);
foreach (var partContent in contentParts)
{
this.SendSms(item.PhoneNumbers, partContent);
}
}
}
//任务明细:修改的
var tasksDetails = await _inStockTaskRepositories.GetDetailsList(update_taskDetailsIds.Distinct().ToList());
@@ -265,5 +287,17 @@ namespace WMS.Web.Domain.Services
}
}
// 将消息分割成多个部分
public List<string> SplitContent(string content, int maxLength)
{
List<string> parts = new List<string>();
for (int i = 0; i < content.Length; i += maxLength)
{
parts.Add(content.Substring(i, Math.Min(maxLength, content.Length - i)));
}
return parts;
}
}
}