58 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}
}