|
@@ -2,12 +2,13 @@
|
|
using MapsterMapper;
|
|
using MapsterMapper;
|
|
using MediatR;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
+using Microsoft.Extensions.Logging;
|
|
using Push.Share.Dtos;
|
|
using Push.Share.Dtos;
|
|
using Push.Share.Dtos.FWMessage;
|
|
using Push.Share.Dtos.FWMessage;
|
|
using Push.Share.Enums;
|
|
using Push.Share.Enums;
|
|
|
|
+using Push.YiBin.Dtos;
|
|
using System.Net;
|
|
using System.Net;
|
|
using System.Xml;
|
|
using System.Xml;
|
|
-using Microsoft.Extensions.Logging;
|
|
|
|
using XF.Domain.Cache;
|
|
using XF.Domain.Cache;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Exceptions;
|
|
using XF.Domain.Exceptions;
|
|
@@ -30,6 +31,8 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
private readonly ITypedCache<CacheWaitSendId> _cacheWaitSendId;
|
|
private readonly ITypedCache<CacheWaitSendId> _cacheWaitSendId;
|
|
private readonly ICapPublisher _capPublisher;
|
|
private readonly ICapPublisher _capPublisher;
|
|
private readonly ILogger<PushDomainService> _logger;
|
|
private readonly ILogger<PushDomainService> _logger;
|
|
|
|
+ private readonly IRepository<WaitMessage> _waitMessageRepository;
|
|
|
|
+ private readonly FwClient _fwClient;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
///
|
|
///
|
|
@@ -45,7 +48,9 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
, IMapper mapper, IConfiguration config, IMediator mediator,
|
|
, IMapper mapper, IConfiguration config, IMediator mediator,
|
|
ITypedCache<CacheWaitSendId> cacheWaitSendId,
|
|
ITypedCache<CacheWaitSendId> cacheWaitSendId,
|
|
ICapPublisher capPublisher,
|
|
ICapPublisher capPublisher,
|
|
- ILogger<PushDomainService> logger)
|
|
|
|
|
|
+ ILogger<PushDomainService> logger,
|
|
|
|
+ IRepository<WaitMessage> waitMessageRepository,
|
|
|
|
+ FwClient fwClient)
|
|
{
|
|
{
|
|
_messageRepository = messageRepository;
|
|
_messageRepository = messageRepository;
|
|
_httpClientFactory = httpClientFactory;
|
|
_httpClientFactory = httpClientFactory;
|
|
@@ -56,10 +61,104 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
_cacheWaitSendId = cacheWaitSendId;
|
|
_cacheWaitSendId = cacheWaitSendId;
|
|
_capPublisher = capPublisher;
|
|
_capPublisher = capPublisher;
|
|
_logger = logger;
|
|
_logger = logger;
|
|
|
|
+ _waitMessageRepository = waitMessageRepository;
|
|
|
|
+ _fwClient = fwClient;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 短信写入待发表
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="dto"></param>
|
|
|
|
+ /// <param name="cancellation"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task<Reponse> AddWaitMessage(WaitMessage dto, CancellationToken cancellation)
|
|
|
|
+ {
|
|
|
|
+ Reponse reponse = new Reponse() { Code = 1 };
|
|
|
|
+ if (dto == null)
|
|
|
|
+ {
|
|
|
|
+ reponse.Message = "消息不能为空!";
|
|
|
|
+ return reponse;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (string.IsNullOrEmpty(dto.ClientId))
|
|
|
|
+ {
|
|
|
|
+ reponse.Message = "发送平台不能为空!";
|
|
|
|
+ return reponse;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (string.IsNullOrEmpty(dto.TelNumber))
|
|
|
|
+ {
|
|
|
|
+ reponse.Message = "短信接收号码不能为空!";
|
|
|
|
+ return reponse;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (string.IsNullOrEmpty(dto.Name))
|
|
|
|
+ {
|
|
|
|
+ reponse.Message = "接收姓名不能为空!";
|
|
|
|
+ return reponse;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (string.IsNullOrEmpty(dto.Content))
|
|
|
|
+ {
|
|
|
|
+ reponse.Message = "短信内容不能为空!";
|
|
|
|
+ return reponse;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var id = await _waitMessageRepository.AddAsync(dto, cancellation);
|
|
|
|
+ if (string.IsNullOrEmpty(id))
|
|
|
|
+ {
|
|
|
|
+ reponse.Message = "新增失败!";
|
|
|
|
+ return reponse;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ reponse.Code = 0;
|
|
|
|
+ reponse.Message = "新增成功!";
|
|
|
|
+ return reponse;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 短信发送
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="messageDto"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task<Message> PushNewAsync(Share.Dtos.MessageDto messageDto)
|
|
|
|
+ {
|
|
|
|
+ var message = _mapper.Map<Message>(messageDto);
|
|
|
|
+ int WaitSendId = GenerateWaitSendId();
|
|
|
|
+ message.WaitSendId = WaitSendId;
|
|
|
|
+
|
|
|
|
+ _logger.LogInformation($"取到WaitSendId值:{WaitSendId}");
|
|
|
|
+
|
|
|
|
+ //调用短信发送业务
|
|
|
|
+ var strResult = await SmsSend(messageDto, WaitSendId);
|
|
|
|
+
|
|
|
|
+ //处理返回值
|
|
|
|
+ if (true == strResult.Contains("ok,")) // ok,35797257
|
|
|
|
+ {
|
|
|
|
+ string[] strArray = strResult.Split(',');
|
|
|
|
+ if (2 == strArray.Length)
|
|
|
|
+ {
|
|
|
|
+ // 短信服务中心返回 IFSFWID,用于短信发送状态接收时匹配
|
|
|
|
+ message.SmsWaitSendingId = strArray[1];
|
|
|
|
+ message.SendState = ESendState.Sending;
|
|
|
|
+ message.Status = EPushStatus.Success;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ message.Reason = strResult;
|
|
|
|
+ message.Status = EPushStatus.Failed;
|
|
|
|
+ }
|
|
|
|
+ return message;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
#region 短信发送
|
|
#region 短信发送
|
|
|
|
|
|
@@ -69,7 +168,7 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
/// <param name="messageDto"></param>
|
|
/// <param name="messageDto"></param>
|
|
/// <param name="cancellation"></param>
|
|
/// <param name="cancellation"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public async Task PushAsync(MessageDto messageDto, CancellationToken cancellation)
|
|
|
|
|
|
+ public async Task PushAsync(Share.Dtos.MessageDto messageDto, CancellationToken cancellation)
|
|
{
|
|
{
|
|
if (messageDto == null)
|
|
if (messageDto == null)
|
|
throw UserFriendlyException.SameMessage("消息不能为空!");
|
|
throw UserFriendlyException.SameMessage("消息不能为空!");
|
|
@@ -196,11 +295,19 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
data.Reason = receiveMessageDto.errormsg;
|
|
data.Reason = receiveMessageDto.errormsg;
|
|
await _messageRepository.UpdateAsync(data);
|
|
await _messageRepository.UpdateAsync(data);
|
|
|
|
|
|
- if (data.ClientId == "Hotline")
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- var dataPush = _mapper.Map<PushMessageDto>(data);
|
|
|
|
- dataPush.Type = "1";
|
|
|
|
- await _capPublisher.PublishAsync(Push.Share.EventNames.UpdateSendSmsState, dataPush, cancellationToken: default);
|
|
|
|
|
|
+ if (data.ClientId == "Hotline")
|
|
|
|
+ {
|
|
|
|
+ var dataPush = _mapper.Map<PushMessageDto>(data);
|
|
|
|
+ dataPush.Type = "1";
|
|
|
|
+ await _fwClient.RequestNoTokenAsync<Reponse>("api/v1/PushMessage/update-send-sms-state", "Post", System.Text.Json.JsonSerializer.Serialize(dataPush), cancellationToken: default);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ throw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 成功返回值必须是ok
|
|
// 成功返回值必须是ok
|
|
@@ -266,7 +373,7 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
/// 短信发送
|
|
/// 短信发送
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- private async Task<string> SmsSend(MessageDto messageDto, int WaitSendId)
|
|
|
|
|
|
+ private async Task<string> SmsSend(Share.Dtos.MessageDto messageDto, int WaitSendId)
|
|
{
|
|
{
|
|
_logger.LogInformation("准备短信推送");
|
|
_logger.LogInformation("准备短信推送");
|
|
string strResult;
|
|
string strResult;
|