Kaynağa Gözat

修改短信推送类型

tangjiang 10 ay önce
ebeveyn
işleme
2518ad9c07

+ 12 - 0
src/Hotline.Api/Controllers/PushMessageController.cs

@@ -68,6 +68,18 @@ namespace Hotline.Api.Controllers
             return await _messageCodeDomainService.VerifyWhitelistAsync(UserName);
         }
 
+        /// <summary>
+        /// 修改短信状态
+        /// </summary>
+        /// <param name="messageDto"></param>
+        /// <param name="cancellation"></param>
+        /// <returns></returns>
+        [HttpPost("update-send-sms-state")]
+        [AllowAnonymous]
+        public async Task UpdateSendSmsState(PushReceiveMessageDto messageDto, CancellationToken cancellation)
+        {
+            await _pushDomainService.PushMsgUpdateStateNewAsync(messageDto, cancellation);
+        }
 
         //[HttpGet("checkdcode")]
         //public async Task CheckdCode(string UserName, string phoneNum, string Code)

+ 31 - 5
src/Hotline.Api/Controllers/TestController.cs

@@ -16,6 +16,7 @@ using Hotline.FlowEngine.Workflows;
 using Hotline.Identity.Roles;
 using Hotline.Import;
 using Hotline.Orders;
+using Hotline.Push.Notifies;
 using Hotline.Realtimes;
 using Hotline.Repository.SqlSugar;
 using Hotline.Repository.SqlSugar.System;
@@ -26,7 +27,9 @@ using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.FlowEngine;
 using Hotline.Share.Dtos.Order;
 using Hotline.Share.Dtos.Realtime;
+using Hotline.Share.Dtos.SendSms;
 using Hotline.Share.Enums.FlowEngine;
+using Hotline.Share.Enums.Push;
 using Hotline.Share.Enums.Settings;
 using Hotline.Share.Mq;
 using Hotline.Tools;
@@ -44,6 +47,7 @@ using NewRock.Sdk;
 using NewRock.Sdk.Security;
 using SqlSugar;
 using SqlSugar.SplitTableExtensions;
+using StackExchange.Redis;
 using Tr.Sdk;
 using XC.RSAUtil;
 using XF.Domain.Authentications;
@@ -75,7 +79,7 @@ public class TestController : BaseController
     private readonly IBlacklistDomainService _blacklistDomainService;
     private readonly IIvrDomainService _ivrDomainService;
     private readonly ISugarUnitOfWork<HotlineDbContext> _uow;
-    private readonly IRepository<Role> _roleRepository;
+    private readonly IRepository<Identity.Roles.Role> _roleRepository;
     private readonly IMediator _mediator;
 
     private readonly IDistributedLock _distributedLock;
@@ -98,6 +102,7 @@ public class TestController : BaseController
     private readonly IRepository<SystemOrganize> _systemOrganizeRepository;
     private readonly IOrderRepository _orderRepository;
     private readonly IMapper _mapper;
+    private readonly IOptionsSnapshot<SendSmsConfiguration> _sendSmsConfiguration;
 
 
     //private readonly ITypedCache<List<User>> _cache;
@@ -118,7 +123,7 @@ public class TestController : BaseController
         IBlacklistDomainService blacklistDomainService,
         IIvrDomainService ivrDomainService,
         ISugarUnitOfWork<HotlineDbContext> uow,
-        IRepository<Role> roleRepository,
+        IRepository<Identity.Roles.Role> roleRepository,
         IMediator mediator,
         IDistributedLock distributedLock,
         IRepository<OrderUrge> orderUrgeRepository,
@@ -136,7 +141,10 @@ public class TestController : BaseController
         //IRepository<WorkflowStepHandler> workflowStepHandleRepository,
         IRepository<SystemOrganize> systemOrganizeRepository,
         IOrderRepository orderRepository,
-        IMapper mapper
+        IMapper mapper,
+
+
+   IOptionsSnapshot<SendSmsConfiguration> sendSmsConfiguration
         )
     {
         _logger = logger;
@@ -169,11 +177,29 @@ public class TestController : BaseController
         _orderRepository = orderRepository;
         _orderRepository = orderRepository;
         _mapper = mapper;
+        _sendSmsConfiguration = sendSmsConfiguration;
     }
 
     [HttpGet("testo")]
+    [AllowAnonymous]
     public async Task<OpenResponse> TestOrigin()
     {
+        var messageDto = new Share.Dtos.Push.MessageDto
+        {
+            PushBusiness = EPushBusiness.OrderAccept,
+            ExternalId = "123456789",
+            OrderId = "123456789",
+            PushPlatform = EPushPlatform.Sms,
+            Remark =" order.Title",
+            Name ="张三",
+            TemplateCode = "1005",
+            Params = new List<string>() { "20240610000022", "12345" },
+            TelNumber = "13683420932",
+
+        };
+        await _mediator.Publish(new PushMessageNotify(messageDto), HttpContext.RequestAborted);
+
+        var t = _sendSmsConfiguration.Value.Url;
         var now = DateTime.Now.ToString();
         return OpenResponse.Ok(now);
     }
@@ -316,7 +342,7 @@ public class TestController : BaseController
     [HttpGet("pgsql")]
     public async Task<string> Pgsql()
     {
-        var role = new Role
+        var role = new Identity.Roles.Role
         {
             Name = $"test_role_{TimeOnly.FromDateTime(DateTime.Now)}",
             DisplayName = "test_role_display",
@@ -331,7 +357,7 @@ public class TestController : BaseController
 
     [AllowAnonymous]
     [HttpGet("roles")]
-    public async Task<List<Role>> GetRoles()
+    public async Task<List<Identity.Roles.Role>> GetRoles()
     {
         using var lockManager = new LockManager(_distributedLock, $"{nameof(TestController)}.{nameof(GetRoles)}");
         lockManager.InvokeInLock(() => { Console.WriteLine("do something"); }, TimeSpan.FromSeconds(10));

+ 3 - 1
src/Hotline.Api/StartupExtensions.cs

@@ -20,6 +20,7 @@ using XF.Utility.MQ;
 using Hotline.Ai.Jths;
 using Hotline.Api.Sdk;
 using Hotline.YbEnterprise.Sdk;
+using Hotline.Share.Dtos.SendSms;
 
 namespace Hotline.Api;
 
@@ -41,7 +42,8 @@ internal static class StartupExtensions
         services.Configure<IdentityConfiguration>(d => configuration.GetSection(nameof(IdentityConfiguration)).Bind(d));
         services.Configure<CallCenterConfiguration>(d => configuration.GetSection(nameof(CallCenterConfiguration)).Bind(d));
         services.Configure<AiVisitConfig>(d => configuration.GetSection("AiVisit").Bind(d));
-        
+        services.Configure<SendSmsConfiguration>(d => configuration.GetSection("SendSms").Bind(d));
+
         // Add services to the container.
         services
             .BatchInjectServices()

+ 7 - 3
src/Hotline.Api/config/appsettings.Development.json

@@ -29,7 +29,7 @@
   },
   "Swagger": true,
   "Cors": {
-    "Origins": [ "http://localhost:8888", "http://admin.hotline.fw.com", "http://localhost:80","http://localhost:8113" ]
+    "Origins": [ "http://localhost:8888", "http://admin.hotline.fw.com", "http://localhost:80", "http://localhost:8113" ]
   },
   "IdentityConfiguration": {
     "Password": {
@@ -130,7 +130,7 @@
       "AreaCode": "511500"
     },
     "WebPortal": {
-     // "SystemSettingsTheme": "class=gray2",
+      // "SystemSettingsTheme": "class=gray2",
       "SystemSettingsTheme": ""
     },
     //业务系统附件上传配置
@@ -207,7 +207,7 @@
   "AiVisit": {
     "Url": "http://118.122.73.80:19061",
     "Appkey": "MTAwMDAx",
-    "ServiceVersion": "V1.0.0", //接口版本号
+    "ServiceVersion": "V1.0.0" //接口版本号
     //"SceneUid": "MTAwMDAxVW7cUNRwRegsLGqb0pvXCU", //场景ID
     //"RuleUid": "MTAwMDAxUbQsuOcmS5ApRyHGyWQr7g", //现有规则ID
     //"VisitFromNameKey": "OC_SCENE_VAR_FIELD14", //来电名称       //开发环境 :OC_SCENE_VAR_FIELD14  //生产环境:OC_SCENE_VAR_FIELD12
@@ -233,6 +233,10 @@
     "ClientId": "1462598736",
     "ClientSecret": "6nZtVK4rKfnsncGymUHB",
     "TenantId": "000000"
+  },
+
+  "SendSms": {
+    "Url": "http://localhost:50108/api/v1/PushMessage/addwaitmsg"
   }
 
 

+ 4 - 1
src/Hotline.Api/config/appsettings.json

@@ -106,7 +106,7 @@
   "AiVisit": {
     "Url": "http://118.122.73.80:19061",
     "Appkey": "MTAwMDAx",
-    "ServiceVersion": "V1.0.0", //接口版本号
+    "ServiceVersion": "V1.0.0" //接口版本号
     //"SceneUid": "MTAwMDAxVW7cUNRwRegsLGqb0pvXCU", //场景ID
     //"RuleUid": "MTAwMDAxUbQsuOcmS5ApRyHGyWQr7g", //现有规则ID
     //"VisitFromNameKey": "OC_SCENE_VAR_FIELD14", //来电名称       //开发环境 :OC_SCENE_VAR_FIELD14  //生产环境:OC_SCENE_VAR_FIELD12
@@ -128,5 +128,8 @@
     "ClientId": "1476116956",
     "ClientSecret": "6NVnvmsFSC8d3qwgBZmN",
     "TenantId": "000000"
+  },
+  "SendSms": {
+    "Url": "http://localhost:50108/api/v1/PushMessage/addwaitmsg"
   }
 }

+ 7 - 0
src/Hotline.Share/Dtos/SendSms/SendSmsConfiguration.cs

@@ -0,0 +1,7 @@
+namespace Hotline.Share.Dtos.SendSms
+{
+    public class SendSmsConfiguration
+    {
+        public string Url { get; set; }
+    }
+}

+ 13 - 0
src/Hotline.Share/Dtos/SendSms/SendSmsReponse.cs

@@ -0,0 +1,13 @@
+namespace Hotline.Share.Dtos.SendSms
+{
+    public class SendSmsReponse
+    {
+        public int code { get; set; }
+
+        public string message { get; set; }
+
+        public string error { get; set; }
+
+        public SendSmsReponse result { get; set; }
+    }
+}

+ 7 - 1
src/Hotline/Push/FWMessage/IPushDomainService.cs

@@ -20,6 +20,12 @@ namespace Hotline.Push.FWMessage
         /// <returns></returns>
         Task PushMsgUpdateStateAsync(PushReceiveMessageDto dto, CancellationToken cancellation);
 
-
+        /// <summary>
+        /// 修改短信推送状态
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <param name="cancellation"></param>
+        /// <returns></returns>
+        Task PushMsgUpdateStateNewAsync(PushReceiveMessageDto dto, CancellationToken cancellation);
     }
 }

+ 103 - 2
src/Hotline/Push/FWMessage/PushDomainService.cs

@@ -1,9 +1,16 @@
 using DotNetCore.CAP;
 using Hotline.Share.Dtos.Push;
+using Hotline.Share.Dtos.SendSms;
 using Hotline.Share.Enums.Push;
 using MapsterMapper;
 using MediatR;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using System.Net;
+using System.Net.Http.Json;
 using System.Text.RegularExpressions;
+using System.Xml;
 using XF.Domain.Dependency;
 using XF.Domain.Exceptions;
 using XF.Domain.Repository;
@@ -21,6 +28,9 @@ public class PushDomainService : IPushDomainService, IScopeDependency
     private readonly IMediator _mediator;
     private readonly IRepository<MessageTemplate> _messageTemplateRepository;
     private readonly ICapPublisher _capPublisher;
+    private readonly IHttpClientFactory _httpClientFactory;
+    private readonly ILogger<PushDomainService> _logger;
+    private readonly IOptionsSnapshot<SendSmsConfiguration> _sendSmsConfiguration;
 
     /// <summary>
     /// 
@@ -30,17 +40,27 @@ public class PushDomainService : IPushDomainService, IScopeDependency
     /// <param name="mediator"></param>
     /// <param name="messageTemplateRepository"></param>
     /// <param name="capPublisher"></param>
+    /// <param name="httpClientFactory"></param>
+    /// <param name="logger"></param>
+    /// <param name="sendSmsConfiguration"></param>
     public PushDomainService(IRepository<Message> messageRepository,
         IMapper mapper,
         IMediator mediator,
         IRepository<MessageTemplate> messageTemplateRepository,
-        ICapPublisher capPublisher)
+        ICapPublisher capPublisher,
+        IHttpClientFactory httpClientFactory,
+        ILogger<PushDomainService> logger,
+     IOptionsSnapshot<SendSmsConfiguration> sendSmsConfiguration
+        )
     {
         _messageRepository = messageRepository;
         _mapper = mapper;
         _mediator = mediator;
         _messageTemplateRepository = messageTemplateRepository;
         _capPublisher = capPublisher;
+        _httpClientFactory = httpClientFactory;
+        _logger = logger;
+        _sendSmsConfiguration = sendSmsConfiguration;
     }
     #endregion
 
@@ -100,7 +120,7 @@ public class PushDomainService : IPushDomainService, IScopeDependency
             TelNumber = message.TelNumber
         };
 
-        await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.SendSms, pushMessage, cancellationToken: cancellation);
+        await ExecuteAsync<PushMessageDto, SendSmsReponse>(_sendSmsConfiguration.Value.Url, pushMessage, cancellationToken: cancellation);
     }
 
     /// <summary>
@@ -143,6 +163,87 @@ public class PushDomainService : IPushDomainService, IScopeDependency
         }
     }
 
+    /// <summary>
+    /// 修改短信推送状态
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <param name="cancellation"></param>
+    /// <returns></returns>
+    public async Task PushMsgUpdateStateNewAsync(PushReceiveMessageDto dto, CancellationToken cancellation)
+    {
+        var data = await _messageRepository.GetAsync(p => p.Id == dto.ExternalId, cancellation);
+        if (data != null)
+        {
+            data.SmsWaitSendingId = dto.SmsWaitSendingId;
+            data.Status = EPushStatus.Success;
+            data.SendTime = Convert.ToDateTime(dto.SendTime);
+            data.SendState = dto.SendState;
+            data.MsgCount = dto.MsgCount;
+            data.SmsSendingCompletedId = dto.SmsSendingCompletedId;
+            data.IsSmsReply = dto.IsSmsReply;
+            data.SmsReplyTime = Convert.ToDateTime(dto.SmsReplyTime);
+            data.SmsReplyContent = dto.SmsReplyContent;
+            await _messageRepository.UpdateAsync(data, cancellation);
+        }
+    }
 
+    /// <summary>
+    /// 
+    /// </summary>
+    /// <typeparam name="TRequest"></typeparam>
+    /// <typeparam name="TResponse"></typeparam>
+    /// <param name="path"></param>
+    /// <param name="request"></param>
+    /// <param name="clientInitialize"></param>
+    /// <param name="cancellationToken"></param>
+    /// <returns></returns>
+    private async Task<TResponse?> ExecuteAsync<TRequest, TResponse>(string path, TRequest request,
+            Action<HttpClient>? clientInitialize = null, CancellationToken cancellationToken = default)
+    {
+        var client = _httpClientFactory.CreateClient("sendwaitsms");
+        clientInitialize?.Invoke(client);
 
+        using var responseMessage = await client.PostAsJsonAsync(path, request, cancellationToken);
+        responseMessage.EnsureSuccessStatusCode();
+        var result = await responseMessage.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken);
+        return result;
+    }
+
+
+    #region http请求
+
+    /// <summary>
+    /// 封装使用HttpClient调用WebService
+    /// </summary>
+    /// <param name="url">URL地址</param>
+    /// <param name="content">参数</param>
+    /// <returns></returns>
+    private async Task<string> PostHelper(string url, HttpContent content)
+    {
+        _logger.LogInformation($"准备推送短信, {nameof(PostHelper)}");
+        var result = string.Empty;
+        try
+        {
+            using var client = _httpClientFactory.CreateClient();
+            using (var response = await client.PostAsync(url, content))
+            {
+                if (response.StatusCode == HttpStatusCode.OK)
+                {
+                    result = await response.Content.ReadAsStringAsync();
+                    XmlDocument doc = new XmlDocument();
+                    doc.LoadXml(result);
+                    result = doc.InnerText;
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            _logger.LogError(ex.InnerException?.Message);
+            result = ex.Message;
+        }
+        _logger.LogInformation($"推送响应:{result}");
+        return result;
+    }
+
+    #endregion
 }