2025-09-19 11:36:17 +08:00
|
|
|
|
using JiShe.ServicePro;
|
|
|
|
|
|
using JiShe.ServicePro.ApacheIoTDB.Provider.Options;
|
|
|
|
|
|
using JiShe.ServicePro.Consts;
|
|
|
|
|
|
using JiShe.ServicePro.Core;
|
|
|
|
|
|
using JiShe.ServicePro.Dto;
|
2025-10-16 17:25:50 +08:00
|
|
|
|
using JiShe.ServicePro.Encrypt;
|
2025-09-19 11:36:17 +08:00
|
|
|
|
using JiShe.ServicePro.Enums;
|
2025-05-27 16:16:07 +08:00
|
|
|
|
using JiShe.ServicePro.FreeRedisProvider;
|
|
|
|
|
|
using JiShe.ServicePro.FreeSqlProvider;
|
2025-09-19 11:36:17 +08:00
|
|
|
|
using JiShe.ServicePro.IoTDBManagement.TableModels;
|
2025-10-16 17:25:50 +08:00
|
|
|
|
using System.Xml.Linq;
|
2025-09-19 11:36:17 +08:00
|
|
|
|
using Volo.Abp;
|
2025-05-27 16:16:07 +08:00
|
|
|
|
|
2025-05-27 14:27:50 +08:00
|
|
|
|
namespace JiShe.IoT
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Inherit your application services from this class.
|
|
|
|
|
|
*/
|
|
|
|
|
|
public abstract class IoTAppService : ApplicationService
|
|
|
|
|
|
{
|
2025-05-27 16:16:07 +08:00
|
|
|
|
protected IFreeSqlProvider FreeSqlDbContext => LazyServiceProvider.LazyGetRequiredService<IFreeSqlProvider>();
|
2025-10-11 15:22:25 +08:00
|
|
|
|
protected IFreeRedisProvider FreeRedisProvider => LazyServiceProvider.LazyGetRequiredService<IFreeRedisProvider>();
|
2025-05-27 16:16:07 +08:00
|
|
|
|
|
2025-05-27 14:27:50 +08:00
|
|
|
|
protected IoTAppService()
|
|
|
|
|
|
{
|
|
|
|
|
|
LocalizationResource = typeof(IoTResource);
|
|
|
|
|
|
}
|
2025-09-19 11:36:17 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><>ȡ<EFBFBD>豸ң<E8B1B8><D2A3>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="iotDBOptions">IoTDBOptions</param>
|
|
|
|
|
|
/// <param name="input"><3E><><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD></param>
|
|
|
|
|
|
/// <param name="deviceInfo"><3E>豸<EFBFBD><E8B1B8>Ϣ</param>
|
|
|
|
|
|
/// <param name="messageBody"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
|
|
protected DeviceTelemetryPacketTaskInfo GetDeviceTelemetryPacketTaskInfo(IoTDBOptions iotDBOptions, OpenApiRequest input, DeviceCacheInfos deviceInfo,string messageBody)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (iotDBOptions == null || string.IsNullOrWhiteSpace(iotDBOptions.DataBaseName) || input == null || deviceInfo == null || string.IsNullOrWhiteSpace(messageBody))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new UserFriendlyException($"<22>豸ң<E8B1B8><D2A3>ָ<EFBFBD><EFBFBD><EEB4B4>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>쳣<EFBFBD><ECB3A3>");
|
|
|
|
|
|
}
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ݣ<EFBFBD><DDA3>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
|
|
|
|
|
|
ReceiveCommandInfoDto commandIssueInfo = input.Message.Deserialize<ReceiveCommandInfoDto>();
|
|
|
|
|
|
|
|
|
|
|
|
var oneNETIssueMessageEntity = new DeviceTelemetryPacketTaskInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
DataBaseName = iotDBOptions.DataBaseName,
|
|
|
|
|
|
DeviceType = $"{commandIssueInfo.DeviceType}",
|
|
|
|
|
|
DeviceAddress = commandIssueInfo.DeviceAddress,
|
|
|
|
|
|
IssueRawMessage = input.Serialize(),
|
|
|
|
|
|
IoTDataType = IoTDBDataTypeConst.Command,
|
|
|
|
|
|
TelemetryType = (int)commandIssueInfo.TelemetryType,
|
|
|
|
|
|
TelemetrySource = (int)commandIssueInfo.SourceType,
|
|
|
|
|
|
IoTPlatform = (int)commandIssueInfo.IoTPlatform,
|
|
|
|
|
|
IoTPlatformProductId = deviceInfo.IoTPlatformProductId,
|
|
|
|
|
|
IoTPlatformDeviceOpenInfo = deviceInfo.IoTPlatformDeviceOpenInfo,
|
|
|
|
|
|
IoTPlatformAccountId = deviceInfo.IoTPlatformAccountId,
|
|
|
|
|
|
AccountPhoneNumber = deviceInfo.AccountPhoneNumber,
|
|
|
|
|
|
IoTPlatformProductName = deviceInfo.IoTPlatformProductName,
|
|
|
|
|
|
IssuePayload = messageBody,
|
|
|
|
|
|
RetryCount = 0,
|
|
|
|
|
|
IssueStatus = (int)DeviceCommandIssueStatusEnum.Unprocessed
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return oneNETIssueMessageEntity;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-16 17:25:50 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Žӿ<C5BD><D3BF><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
/// <param name="input"><3E>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|
|
|
|
|
/// <param name="serverOptions"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
protected HttpDataResult<T> HandleOpenApiRequest<T>(OpenApiRequest input, ServerApplicationOptions serverOptions) where T : class
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(input.Message) || string.IsNullOrWhiteSpace(input.Nonce) || string.IsNullOrWhiteSpace(input.Signature))
|
|
|
|
|
|
{
|
|
|
|
|
|
return HttpDataResultExtensions.Failed<T>(null, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>", -1101);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (input.Timestamp <= 946656000000)//ʱ<><CAB1><EFBFBD><EFBFBD>С<EFBFBD><D0A1>2000<30>꣬<EFBFBD><EAA3AC>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|
|
|
|
|
{
|
|
|
|
|
|
return HttpDataResultExtensions.Failed<T>(null, "ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>쳣", -1102);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, serverOptions.SignatureToken);
|
|
|
|
|
|
if (verifySignatureReult == false)//ǩ<><C7A9>У<EFBFBD><D0A3>ʧ<EFBFBD><CAA7>
|
|
|
|
|
|
{
|
|
|
|
|
|
return HttpDataResultExtensions.Failed<T>(null, "ǩ<><C7A9>У<EFBFBD><D0A3>ʧ<EFBFBD><CAA7>", -1103);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
|
|
|
|
|
|
T messageBody = default;
|
|
|
|
|
|
string tempMessageBody = null;
|
|
|
|
|
|
if (serverOptions.IsAesEncrypted && !string.IsNullOrWhiteSpace(serverOptions.AesSecurityKey))
|
|
|
|
|
|
{
|
|
|
|
|
|
tempMessageBody = EncryptUtil.OpenApiDecrypto(input.Message, serverOptions.AesSecurityKey);
|
|
|
|
|
|
messageBody = tempMessageBody.Deserialize<T>();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
tempMessageBody = input.Message;
|
|
|
|
|
|
messageBody = input.Message.Deserialize<T>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (messageBody == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return HttpDataResultExtensions.Failed<T>(null, "<22><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>", -1104);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return HttpDataResultExtensions.Success(messageBody, tempMessageBody);
|
|
|
|
|
|
}
|
2025-05-27 14:27:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|