From 21dd36de64b998deb58dbde81835152b1d11890b Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Thu, 16 Oct 2025 17:25:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=98=8E=E7=BB=86=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=89=A9=E5=B1=95=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=AE=BE=E5=A4=87=E7=89=A9=E6=A8=A1=E5=9E=8B=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JiShe.ServicePro | 2 +- .../BusinessSystemAggregationService.cs | 58 ++----------------- src/JiShe.IoT.Application/IoTAppService.cs | 50 ++++++++++++++++ .../OneNETAggregationService.cs | 3 +- .../EntityFrameworkCore/IoTDbContext.cs | 1 + 5 files changed, 59 insertions(+), 55 deletions(-) diff --git a/JiShe.ServicePro b/JiShe.ServicePro index 4ffdef6..5eee6ae 160000 --- a/JiShe.ServicePro +++ b/JiShe.ServicePro @@ -1 +1 @@ -Subproject commit 4ffdef6823df61822903a7e087553260fa7254ae +Subproject commit 5eee6ae6ecdae8325f89c8a1bff2007062388dd8 diff --git a/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs b/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs index 5329868..31da3cd 100644 --- a/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs +++ b/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs @@ -24,7 +24,7 @@ namespace JiShe.IoT.BusinessSystemAggregation /// public class BusinessSystemAggregationService(IOptions options, IReliableRedisPubSubService redisPubSubService, IDeviceAppService deviceAppService, IIoTDBDataChannelManageService ioTDBDataChannelManageService, IOptions _ioTDBOptions, ITreeModelService treeModelService, IDeviceAggregationService deviceAggregationService, ILogger _logger) : IoTAppService, IBusinessSystemAggregationService { - ServerApplicationOptions srverOptions = options.Value; + ServerApplicationOptions serverOptions = options.Value; IoTDBOptions ioTDBOptions = _ioTDBOptions.Value; /// @@ -37,7 +37,7 @@ namespace JiShe.IoT.BusinessSystemAggregation try { - var handleResult = HandleOpenApiRequest(input); + var handleResult = HandleOpenApiRequest(input, serverOptions); if (handleResult.Success == false) { return handleResult; @@ -127,7 +127,7 @@ namespace JiShe.IoT.BusinessSystemAggregation { try { - var handleResult = HandleOpenApiRequest(input); + var handleResult = HandleOpenApiRequest(input, serverOptions); if (handleResult.Success == false) { return HttpDataResultExtensions.Failed>(null, handleResult.Message, handleResult.LocationCode); @@ -214,7 +214,7 @@ namespace JiShe.IoT.BusinessSystemAggregation { try { - var handleResult = HandleOpenApiRequest(input); + var handleResult = HandleOpenApiRequest(input, serverOptions); if (handleResult.Success == false) { return HttpDataResultExtensions.Failed(handleResult.Message, handleResult.LocationCode); @@ -246,54 +246,6 @@ namespace JiShe.IoT.BusinessSystemAggregation { return HttpDataResultExtensions.Failed($"查询设备数据失败,发送异常:{ex.Message}", -106); } - } - - - /// - /// 处理开放接口请求 - /// - /// - /// - /// - private HttpDataResult HandleOpenApiRequest(OpenApiRequest input) where T : class - { - if (string.IsNullOrWhiteSpace(input.Message) || string.IsNullOrWhiteSpace(input.Message) || string.IsNullOrWhiteSpace(input.Signature)) - { - return HttpDataResultExtensions.Failed(null, "请求参数不能为空", -1101); - } - - if (input.Timestamp <= 946656000000)//时间戳小于2000年,视为错误 - { - return HttpDataResultExtensions.Failed(null, "时间戳异常", -1102); - } - - bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.SignatureToken); - if (verifySignatureReult == false)//签名校验失败 - { - return HttpDataResultExtensions.Failed(null, "签名校验失败", -1103); - } - - - //判断是否需要解密 - T messageBody = default; - string tempMessageBody = null; - if (srverOptions.IsAesEncrypted && !string.IsNullOrWhiteSpace(srverOptions.AesSecurityKey)) - { - tempMessageBody = EncryptUtil.OpenApiDecrypto(input.Message, srverOptions.AesSecurityKey); - messageBody = tempMessageBody.Deserialize(); - } - else - { - tempMessageBody = input.Message; - messageBody = input.Message.Deserialize(); - } - - if (messageBody == null) - { - return HttpDataResultExtensions.Failed(null, "获取数据体失败", -1104); - } - - return HttpDataResultExtensions.Success(messageBody, tempMessageBody); - } + } } } diff --git a/src/JiShe.IoT.Application/IoTAppService.cs b/src/JiShe.IoT.Application/IoTAppService.cs index ddb0f5e..65aa64c 100644 --- a/src/JiShe.IoT.Application/IoTAppService.cs +++ b/src/JiShe.IoT.Application/IoTAppService.cs @@ -3,10 +3,12 @@ using JiShe.ServicePro.ApacheIoTDB.Provider.Options; using JiShe.ServicePro.Consts; using JiShe.ServicePro.Core; using JiShe.ServicePro.Dto; +using JiShe.ServicePro.Encrypt; using JiShe.ServicePro.Enums; using JiShe.ServicePro.FreeRedisProvider; using JiShe.ServicePro.FreeSqlProvider; using JiShe.ServicePro.IoTDBManagement.TableModels; +using System.Xml.Linq; using Volo.Abp; namespace JiShe.IoT @@ -71,5 +73,53 @@ namespace JiShe.IoT throw; } } + + /// + /// Žӿ + /// + /// + /// ӿ + /// + /// + protected HttpDataResult HandleOpenApiRequest(OpenApiRequest input, ServerApplicationOptions serverOptions) where T : class + { + if (string.IsNullOrWhiteSpace(input.Message) || string.IsNullOrWhiteSpace(input.Nonce) || string.IsNullOrWhiteSpace(input.Signature)) + { + return HttpDataResultExtensions.Failed(null, "Ϊ", -1101); + } + + if (input.Timestamp <= 946656000000)//ʱС2000꣬Ϊ + { + return HttpDataResultExtensions.Failed(null, "ʱ쳣", -1102); + } + + bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, serverOptions.SignatureToken); + if (verifySignatureReult == false)//ǩУʧ + { + return HttpDataResultExtensions.Failed(null, "ǩУʧ", -1103); + } + + + //жǷҪ + T messageBody = default; + string tempMessageBody = null; + if (serverOptions.IsAesEncrypted && !string.IsNullOrWhiteSpace(serverOptions.AesSecurityKey)) + { + tempMessageBody = EncryptUtil.OpenApiDecrypto(input.Message, serverOptions.AesSecurityKey); + messageBody = tempMessageBody.Deserialize(); + } + else + { + tempMessageBody = input.Message; + messageBody = input.Message.Deserialize(); + } + + if (messageBody == null) + { + return HttpDataResultExtensions.Failed(null, "ȡʧ", -1104); + } + + return HttpDataResultExtensions.Success(messageBody, tempMessageBody); + } } } diff --git a/src/JiShe.IoT.Application/OneNETAggregation/OneNETAggregationService.cs b/src/JiShe.IoT.Application/OneNETAggregation/OneNETAggregationService.cs index 93785c7..4087a00 100644 --- a/src/JiShe.IoT.Application/OneNETAggregation/OneNETAggregationService.cs +++ b/src/JiShe.IoT.Application/OneNETAggregation/OneNETAggregationService.cs @@ -127,7 +127,8 @@ namespace JiShe.IoT.OneNETAggregation } var rawMessage = pageList.Serialize(); - var signatureResult = EncryptUtil.OpenApiSignature(rawMessage, DateTimeOffset.UtcNow.AddSeconds(3).ToUnixTimeMilliseconds(), serverOptions.SignatureToken); + long timestamp = serverOptions.GetOpenApiSignatureTimeStamp(); + var signatureResult = EncryptUtil.OpenApiSignature(rawMessage, timestamp, serverOptions.SignatureToken); return HttpDataResultExtensions.Success(rawMessage, signatureResult.Item1, signatureResult.Item2); } diff --git a/src/JiShe.IoT.EntityFrameworkCore/EntityFrameworkCore/IoTDbContext.cs b/src/JiShe.IoT.EntityFrameworkCore/EntityFrameworkCore/IoTDbContext.cs index 912ba5f..f1634ee 100644 --- a/src/JiShe.IoT.EntityFrameworkCore/EntityFrameworkCore/IoTDbContext.cs +++ b/src/JiShe.IoT.EntityFrameworkCore/EntityFrameworkCore/IoTDbContext.cs @@ -66,6 +66,7 @@ namespace JiShe.IoT.EntityFrameworkCore // 设备管理 public DbSet DeviceManagementInfo { get; set; } + public DbSet DeviceThingModelInfo { get; set; } // CTWing管理 public DbSet CTWingAccountInfo { get; set; }