58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
|
|
using JiShe.IoT.OneNETAggregation.Dto;
|
|||
|
|
using JiShe.ServicePro;
|
|||
|
|
using JiShe.ServicePro.Encrypt;
|
|||
|
|
using JiShe.ServicePro.Enums;
|
|||
|
|
using JiShe.ServicePro.Kafka.Consts;
|
|||
|
|
using JiShe.ServicePro.Kafka.Producer;
|
|||
|
|
using JiShe.ServicePro.ServerOptions;
|
|||
|
|
using Microsoft.Extensions.Options;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Xml.Linq;
|
|||
|
|
|
|||
|
|
namespace JiShe.IoT.BusinessSystemAggregation
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 业务系统聚合服务
|
|||
|
|
/// </summary>
|
|||
|
|
public class BusinessSystemAggregationService(IOptions<ServerApplicationOptions> options, IKafkaProducerService _producerService) :IoTAppService, IBusinessSystemAggregationService
|
|||
|
|
{
|
|||
|
|
ServerApplicationOptions srverOptions = options.Value;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 接收业务系统指令信息,缓存进Kafka
|
|||
|
|
/// </summary>
|
|||
|
|
[AllowAnonymous]
|
|||
|
|
public async Task<HttpDataResult> ReceiveCommandInfoAsync(OpenApiRequest input)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.VerifySignatureToken);
|
|||
|
|
if (verifySignatureReult == false)//签名校验失败
|
|||
|
|
{
|
|||
|
|
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("签名校验失败", -101, ResponeResultEnum.NotAllowed);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (string.IsNullOrWhiteSpace(input.Message))
|
|||
|
|
{
|
|||
|
|
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("指令下发内容不能为空", -102, ResponeResultEnum.Fail);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//将指令存储Kafka中
|
|||
|
|
await _producerService.ProduceAsync(KafkaTopicConsts.OneNETCommandIssuedEventName, $"{GuidGenerator.Create()}", input);
|
|||
|
|
|
|||
|
|
return HttpDataResultExtensions.Success("指令下发Kafka成功");
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|