TANG JIANG 1 year ago
parent
commit
4e22d7b973

+ 22 - 3
src/Hotline.Api/Controllers/PushMessageController.cs

@@ -1,10 +1,15 @@
-using Hotline.Push;
+using Hotline.KnowledgeBase.Notifies;
+using Hotline.KnowledgeBase;
+using Hotline.Push;
 using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Push;
 using Hotline.Share.Dtos.Push;
 using MapsterMapper;
 using MapsterMapper;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc;
+using MediatR;
+using Hotline.Push.Notifies;
+using Hotline.Share.Enums.Push;
 
 
 namespace Hotline.Api.Controllers
 namespace Hotline.Api.Controllers
 {
 {
@@ -20,6 +25,7 @@ namespace Hotline.Api.Controllers
         /// <param name="messageRepository"></param>
         /// <param name="messageRepository"></param>
         /// <param name="mapper"></param>
         /// <param name="mapper"></param>
         /// <param name="pushDomainService"></param>
         /// <param name="pushDomainService"></param>
+        /// <param name="mediator"></param>
         public PushMessageController(IMessageRepository messageRepository, IMapper mapper, IPushDomainService pushDomainService)
         public PushMessageController(IMessageRepository messageRepository, IMapper mapper, IPushDomainService pushDomainService)
         {
         {
             _messageRepository = messageRepository;
             _messageRepository = messageRepository;
@@ -68,7 +74,21 @@ namespace Hotline.Api.Controllers
         public async Task<string> ReceiveObtain(string account, string pswd, string msgid, string sendtime, int msgcount, int state,
         public async Task<string> ReceiveObtain(string account, string pswd, string msgid, string sendtime, int msgcount, int state,
             string errormsg, int sfid, string telnumall, string sign)
             string errormsg, int sfid, string telnumall, string sign)
         {
         {
-            return await _pushDomainService.ReceiveObtain(account, pswd, msgid, sendtime, msgcount, state, errormsg, sfid, telnumall, sign);
+            ReceiveMessageDto receiveMessageDto = new()
+            {
+                account = account,
+                pswd = pswd,
+                msgid = msgid,
+                sendtime = sendtime,
+                msgcount = msgcount,
+                state = state,
+                errormsg = errormsg,
+                sfid = sfid,
+                telnumall = telnumall,
+                sign = sign
+            };
+
+            return await _pushDomainService.ReceiveObtain(receiveMessageDto);
         }
         }
         #endregion
         #endregion
 
 
@@ -93,7 +113,6 @@ namespace Hotline.Api.Controllers
 
 
             string strResult = "error,缺少参数";
             string strResult = "error,缺少参数";
 
 
-
             // 成功返回值必须是ok
             // 成功返回值必须是ok
             strResult = "ok";
             strResult = "ok";
             return strResult;
             return strResult;

+ 21 - 0
src/Hotline.Application/Push/PushMessageNotifyHandler.cs

@@ -0,0 +1,21 @@
+using Hotline.Push.Notifies;
+using MediatR;
+
+namespace Hotline.Application.Push
+{
+    public class PushMessageNotifyHandler : INotificationHandler<PushMessageNotify>
+    {
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="notification"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task Handle(PushMessageNotify notification, CancellationToken cancellationToken)
+        {
+            var data = notification.NotifyDto;
+        }
+    }
+}

+ 43 - 0
src/Hotline.Share/Dtos/Push/PushMessageNotifyDto.cs

@@ -0,0 +1,43 @@
+using Hotline.Share.Enums.Push;
+using System;
+using System.Collections.Generic;
+using System.Data.SqlTypes;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Share.Dtos.Push
+{
+    public class PushMessageNotifyDto
+    {
+        /// <summary>
+        /// 消息推送业务
+        /// </summary>        
+        public EPushBusiness PushBusiness { get; set; }
+
+        /// <summary>
+        /// 外部业务唯一编号
+        /// </summary>
+        public string ExternalId { get; set; }
+
+        /// <summary>
+        /// 接收手机号码
+        /// </summary>
+        public string TelNumber { get; set; }
+
+        /// <summary>
+        /// 关联工单编号
+        /// </summary>
+        public string? OrderId { get; set; }
+
+        /// <summary>
+        /// 短信回复内容
+        /// </summary>   
+        public string? SmsReplyContent { get; set; }
+
+        /// <summary>
+        /// 短信回复时间
+        /// </summary>
+        public DateTime? SmsReplyTime { get; set; }
+    }
+}

+ 83 - 0
src/Hotline.Share/Dtos/Push/ReceiveMessageDto.cs

@@ -0,0 +1,83 @@
+namespace Hotline.Share.Dtos.Push
+{
+    /// <summary>
+    /// 丰窝短信接收值
+    /// </summary>
+    public class ReceiveMessageDto
+    {
+        /// <summary>
+        /// 短信回传账号
+        /// </summary>
+        public string account { get; set; }
+
+        /// <summary>
+        /// 短信回传密码
+        /// </summary>
+        public string pswd { get; set; }
+
+        /// <summary>
+        /// 短信中心短信待发送ID,同短信发送接口返回值ID
+        /// </summary>
+        public string msgid { get; set; }
+
+        /// <summary>
+        /// 短信发送时间
+        /// </summary>
+        public string sendtime { get; set; }
+
+        /// <summary>
+        /// 发送短信使用的数量
+        /// </summary>
+        public int msgcount { get; set; }
+
+        /// <summary>
+        /// 发送状态:0:未发送  1:发送中  2:发送失败  3:发送成功
+        /// </summary>
+        public int state { get; set; }
+
+        /// <summary>
+        /// 错误消息
+        /// </summary>
+        public string errormsg { get; set; }
+
+        /// <summary>
+        /// 短信中心短信已发送ID
+        /// </summary>
+        public int sfid { get; set; }
+
+        /// <summary>
+        /// 手机号码
+        /// </summary>
+        public string telnumall { get; set; }
+
+        /// <summary>
+        /// 短信签名
+        /// </summary>
+        public string sign { get; set; }
+
+        /// <summary>
+        /// 回复短信内容
+        /// </summary>
+        public string msg { get; set; }
+
+        /// <summary>
+        /// 回复手机号码
+        /// </summary>
+        public string mobile { get; set; }
+
+        /// <summary>
+        /// 短信接收平台号码
+        /// </summary>
+        public string destcode { get; set; }
+
+        /// <summary>
+        /// 回复时间
+        /// </summary>
+        public string motime { get; set; }
+
+        /// <summary>
+        /// 短信平台回复短信ID
+        /// </summary>
+        public string fsfid { get; set; }
+    }
+}

+ 1 - 6
src/Hotline/KnowledgeBase/Notifies/GetKnowledgeInfoNotify.cs

@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using MediatR;
+using MediatR;
 
 
 namespace Hotline.KnowledgeBase.Notifies
 namespace Hotline.KnowledgeBase.Notifies
 {
 {

+ 9 - 11
src/Hotline/Push/IPushDomainService.cs

@@ -21,17 +21,15 @@ namespace Hotline.Push
         /// <summary>
         /// <summary>
         /// 短信发送状态回调接口
         /// 短信发送状态回调接口
         /// </summary>
         /// </summary>
-        /// <param name="account">短信回传账号</param>
-        /// <param name="pswd">短信回传密码</param>
-        /// <param name="msgid">短信中心短信待发送ID,同短信发送接口返回值ID</param>
-        /// <param name="sendtime">短信发送时间</param>
-        /// <param name="msgcount">发送短信使用的数量</param>
-        /// <param name="state">发送状态:0:未发送  1:发送中  2:发送失败  3:发送成功</param>
-        /// <param name="errormsg">错误消息</param>
-        /// <param name="sfid">短信中心短信已发送ID</param>
-        /// <param name="telnumall">手机号码</param>
-        /// <param name="sign">短信签名</param>
+        /// <param name="receiveMessageDto"></param>
         /// <returns></returns>
         /// <returns></returns>
-        Task<string> ReceiveObtain(string account, string pswd, string msgid, string sendtime, int msgcount, int state, string errormsg, int sfid, string telnumall, string sign);
+        Task<string> ReceiveObtain(ReceiveMessageDto receiveMessageDto);
+
+        /// <summary>
+        /// 短信接收
+        /// </summary>
+        /// <param name="receiveMessageDto"></param>
+        /// <returns></returns>
+        Task<string> ReceiveSms(ReceiveMessageDto receiveMessageDto);
     }
     }
 }
 }

+ 7 - 0
src/Hotline/Push/Notifies/PushMessageNotify.cs

@@ -0,0 +1,7 @@
+using Hotline.Share.Dtos.Push;
+using MediatR;
+
+namespace Hotline.Push.Notifies
+{
+    public record PushMessageNotify(PushMessageNotifyDto NotifyDto) : INotification;
+}

+ 62 - 23
src/Hotline/Push/PushDomainService.cs

@@ -1,6 +1,9 @@
-using Hotline.Share.Dtos.Push;
+using Hotline.Push.Notifies;
+using Hotline.Share.Dtos.Push;
 using Hotline.Share.Enums.Push;
 using Hotline.Share.Enums.Push;
 using MapsterMapper;
 using MapsterMapper;
+using MediatR;
+using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging;
@@ -24,6 +27,7 @@ public class PushDomainService : IPushDomainService, IScopeDependency
     private readonly ILogger<PushDomainService> _logger;
     private readonly ILogger<PushDomainService> _logger;
     private readonly IConfiguration _config;
     private readonly IConfiguration _config;
     private readonly SmsAccountInfo accountInfo = null;
     private readonly SmsAccountInfo accountInfo = null;
+    private readonly IMediator _mediator;
 
 
     /// <summary>
     /// <summary>
     /// 
     /// 
@@ -33,7 +37,9 @@ public class PushDomainService : IPushDomainService, IScopeDependency
     /// <param name="logger"></param>
     /// <param name="logger"></param>
     /// <param name="mapper"></param>
     /// <param name="mapper"></param>
     /// <param name="config"></param>
     /// <param name="config"></param>
-    public PushDomainService(IMessageRepository messageRepository, IHttpClientFactory httpClientFactory, ILogger<PushDomainService> logger, IMapper mapper, IConfiguration config)
+    /// <param name="mediator"></param>
+    public PushDomainService(IMessageRepository messageRepository, IHttpClientFactory httpClientFactory, ILogger<PushDomainService> logger
+        , IMapper mapper, IConfiguration config, IMediator mediator)
     {
     {
         _messageRepository = messageRepository;
         _messageRepository = messageRepository;
         _httpClientFactory = httpClientFactory;
         _httpClientFactory = httpClientFactory;
@@ -41,6 +47,7 @@ public class PushDomainService : IPushDomainService, IScopeDependency
         _mapper = mapper;
         _mapper = mapper;
         _config = config;
         _config = config;
         accountInfo = _config.GetSection("SmsAccountInfo").Get<SmsAccountInfo>();
         accountInfo = _config.GetSection("SmsAccountInfo").Get<SmsAccountInfo>();
+        _mediator = mediator;
     }
     }
 
 
     /// <summary>
     /// <summary>
@@ -137,42 +144,33 @@ public class PushDomainService : IPushDomainService, IScopeDependency
     /// <summary>
     /// <summary>
     /// 短信发送状态回调接口
     /// 短信发送状态回调接口
     /// </summary>
     /// </summary>
-    /// <param name="account">短信回传账号</param>
-    /// <param name="pswd">短信回传密码</param>
-    /// <param name="msgid">短信中心短信待发送ID,同短信发送接口返回值ID</param>
-    /// <param name="sendtime">短信发送时间</param>
-    /// <param name="msgcount">发送短信使用的数量</param>
-    /// <param name="state">发送状态:0:未发送  1:发送中  2:发送失败  3:发送成功</param>
-    /// <param name="errormsg">错误消息</param>
-    /// <param name="sfid">短信中心短信已发送ID</param>
-    /// <param name="telnumall">手机号码</param>
-    /// <param name="sign">短信签名</param>
+    /// <param name="receiveMessageDto"></param>
     /// <returns></returns>
     /// <returns></returns>
-    public async Task<string> ReceiveObtain(string account, string pswd, string msgid, string sendtime, int msgcount, int state, string errormsg, int sfid, string telnumall, string sign)
+    public async Task<string> ReceiveObtain(ReceiveMessageDto receiveMessageDto)
     {
     {
         string strResult = "error,缺少参数";
         string strResult = "error,缺少参数";
-        if (account != accountInfo.ReturnAccountUser || pswd != accountInfo.ReturnAccountPwd)
+        if (receiveMessageDto.account != accountInfo.ReturnAccountUser || receiveMessageDto.pswd != accountInfo.ReturnAccountPwd)
         {
         {
             strResult = "error,参数错误";
             strResult = "error,参数错误";
             return strResult;
             return strResult;
         }
         }
-        if (true == string.IsNullOrEmpty(account) || true == string.IsNullOrEmpty(pswd)
-            || true == string.IsNullOrEmpty(msgid) || true == string.IsNullOrEmpty(sendtime)
-            || msgcount <= 0 || state < 0)
+        if (true == string.IsNullOrEmpty(receiveMessageDto.account) || true == string.IsNullOrEmpty(receiveMessageDto.pswd)
+            || true == string.IsNullOrEmpty(receiveMessageDto.msgid) || true == string.IsNullOrEmpty(receiveMessageDto.sendtime)
+            || receiveMessageDto.msgcount <= 0 || receiveMessageDto.state < 0)
         {
         {
             strResult = "error,参数错误";
             strResult = "error,参数错误";
             return strResult;
             return strResult;
         }
         }
 
 
         //修改数据
         //修改数据
-        var data = await _messageRepository.GetAsync(p => p.SmsWaitSendingId == msgid);
+        var data = await _messageRepository.GetAsync(p => p.SmsWaitSendingId == receiveMessageDto.msgid);
         if (data != null)
         if (data != null)
         {
         {
-            data.SendTime = Convert.ToDateTime(sendtime);
-            data.MsgCount = msgcount;
-            data.SendState = (ESendState)state;
-            data.SmsSendingCompletedId = sfid + "";
-            data.Remark = errormsg;
+            data.SendTime = Convert.ToDateTime(receiveMessageDto.sendtime);
+            data.MsgCount = receiveMessageDto.msgcount;
+            data.SendState = (ESendState)receiveMessageDto.state;
+            data.SmsSendingCompletedId = receiveMessageDto.sfid + "";
+            data.Remark = receiveMessageDto.errormsg;
             await _messageRepository.UpdateAsync(data);
             await _messageRepository.UpdateAsync(data);
             // 成功返回值必须是ok
             // 成功返回值必须是ok
             strResult = "ok";
             strResult = "ok";
@@ -183,6 +181,47 @@ public class PushDomainService : IPushDomainService, IScopeDependency
         return strResult;
         return strResult;
     }
     }
 
 
+    /// <summary>
+    /// 短信接收
+    /// </summary>
+    /// <param name="receiveMessageDto"></param>
+    /// <returns></returns>
+    public async Task<string> ReceiveSms(ReceiveMessageDto receiveMessageDto)
+    {
+        string strResult = "error,缺少参数";
+        if (receiveMessageDto.account != accountInfo.ReturnAccountUser || receiveMessageDto.pswd != accountInfo.ReturnAccountPwd)
+        {
+            strResult = "error,参数错误";
+            return strResult;
+        }
+        if (true == string.IsNullOrEmpty(receiveMessageDto.account) || true == string.IsNullOrEmpty(receiveMessageDto.pswd)
+            || true == string.IsNullOrEmpty(receiveMessageDto.msg) || true == string.IsNullOrEmpty(receiveMessageDto.mobile)
+            || true == string.IsNullOrEmpty(receiveMessageDto.motime))
+        {
+            strResult = "error,参数错误";
+            return strResult;
+        }
+
+        var data = await _messageRepository.GetAsync(p => p.TelNumber == receiveMessageDto.mobile && p.IsSmsReply == false && p.SmsReplyTime == null);
+        if (data != null)
+        {
+            data.IsSmsReply = true;
+            data.SmsReplyTime = Convert.ToDateTime(receiveMessageDto.motime);
+            data.SmsReplyContent = receiveMessageDto.msg;
+            await _messageRepository.UpdateAsync(data);
+
+            //消息处理
+            await _mediator.Publish(new PushMessageNotify(_mapper.Map<PushMessageNotifyDto>(data)));
+            // 成功返回值必须是ok
+            strResult = "ok";
+        }
+        else
+            strResult = "error,调用失败";
+
+        return strResult;
+
+    }
+
     #region 私有方法
     #region 私有方法
 
 
     #region 短信发送
     #region 短信发送