97 lines
4.2 KiB
C#
97 lines
4.2 KiB
C#
using JiShe.ServicePro.Core;
|
||
using JiShe.ServicePro.Encrypt;
|
||
|
||
namespace JiShe.IoT;
|
||
|
||
public class Program
|
||
{
|
||
public static async Task<int> Main(string[] args)
|
||
{
|
||
try
|
||
{
|
||
//var options = new Yitter.IdGenerator.IdGeneratorOptions(2);
|
||
//Yitter.IdGenerator.YitIdHelper.SetIdGenerator(options);
|
||
//long nanosecondsFromSnowflakeId = ServicePro.Core.TimestampHelper.NextUnixNanosecondsFromSnowflakeId();
|
||
//long nanosecondsDateOffset = ServicePro.Core.TimestampHelper.ToUnixTimeNanoseconds(DateTimeOffset.UtcNow);
|
||
|
||
BusinessSystemAggregation.Dto.BatchQueryDeviceDataInfoInput batchQueryDeviceDataInfoInput = new BusinessSystemAggregation.Dto.BatchQueryDeviceDataInfoInput()
|
||
{
|
||
DeviceType = ServicePro.Enums.DeviceTypeEnum.SUB_DEVICE,
|
||
DeviceAddresses = new List<string>()
|
||
{
|
||
"000000000001"
|
||
},
|
||
BeginTime = new DateTime(2025,10,29),
|
||
EndTime = new DateTime(2025, 10, 31),
|
||
IoTDataType = "Data",
|
||
};
|
||
OpenApiRequest openApiRequest = new OpenApiRequest()
|
||
{
|
||
Message = batchQueryDeviceDataInfoInput.Serialize(),
|
||
Signature = "admin:admin123",
|
||
Timestamp = 1762185062034,
|
||
Nonce = "44110100",
|
||
};
|
||
|
||
var signature = EncryptUtil.OpenApiSignature(openApiRequest.Message, openApiRequest.Timestamp, "SIcPQnpMgaFDmNlIjNmzq5smshz7cKrh", openApiRequest.Nonce);
|
||
openApiRequest.Signature = signature.Item2;
|
||
|
||
string signatureSTR = openApiRequest.Serialize();
|
||
|
||
|
||
//string text = Convert.ToBase64String(Encoding.UTF8.GetBytes("admin:admin123"));
|
||
Log.Information("JiShe.IoT.HttpApi.Host.");
|
||
var builder = WebApplication.CreateBuilder(args);
|
||
builder.Host
|
||
.AddAppSettingsSecretsJson()
|
||
.UseAutofac()
|
||
.UseSerilog((context, loggerConfiguration) =>
|
||
{
|
||
SerilogToEsExtensions.SetSerilogConfiguration(
|
||
loggerConfiguration,
|
||
context.Configuration);
|
||
})
|
||
.ConfigureAppConfiguration((context, builder) =>
|
||
{
|
||
var env = context.HostingEnvironment.EnvironmentName;
|
||
Log.Information("当前环境 :" + env);
|
||
string[] filePathArray = new string[] { Environment.CurrentDirectory, "configs" };
|
||
string jsonPath = Path.Combine(filePathArray);
|
||
|
||
builder.AddJsonFile(Path.Combine(jsonPath, "appsettings.json"), false, true);
|
||
builder.AddJsonFile(Path.Combine(jsonPath, $"appsettings.{env}.json"), false, true);
|
||
});
|
||
|
||
await builder.AddApplicationAsync<JiShe.IoT.IoTHttpApiHostModule>();
|
||
builder.WebHost.ConfigureKestrel((context, options) =>
|
||
{
|
||
options.Limits.MaxRequestBodySize = 100 * 1024 * 1024; // 100MB null不受限制
|
||
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
|
||
options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(1);
|
||
|
||
//获取或设置请求正文的最小数据速率(字节/秒)。将此属性设置为NULL表示不应强制执行最小数据速率。////获取或设置请求正文的最小数据速率(字节/秒)。将此属性设置为NULL表示不应强制执行最小数据速率。
|
||
options.Limits.MinRequestBodyDataRate = null;//new MinDataRate(bytesPerSecond: 2048, gracePeriod: TimeSpan.FromSeconds(10));
|
||
|
||
});
|
||
builder.WebHost.UseUrls($"http://+:10500");
|
||
var app = builder.Build();
|
||
await app.InitializeApplicationAsync();
|
||
await app.RunAsync();
|
||
return 0;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex is HostAbortedException)
|
||
{
|
||
throw;
|
||
}
|
||
|
||
Log.Fatal(ex, "Host terminated unexpectedly!");
|
||
return 1;
|
||
}
|
||
finally
|
||
{
|
||
await Log.CloseAndFlushAsync();
|
||
}
|
||
}
|
||
} |