@@ -332,3 +332,4 @@ ASALocalRun/ | |||
/src/JT808.DotNetty.Admin/tools/protoc-gen-grpc-web-1.0.3-windows-x86_64.exe | |||
/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/.config/dotnet-tools.json | |||
/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/wwwroot/logs/JT808.Gateway | |||
/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/wwwroot/logs/JT808.Gateway |
@@ -35,7 +35,7 @@ namespace JT808.Gateway.NBIotSimpleClient.Jobs | |||
var address = Dns.GetHostAddresses("jtt808.ctwing.cn"); | |||
JT808TcpClient client1 = await jT808TcpClientFactory.Create(new JT808DeviceConfig(sim, address[0].ToString(), 6001, version:JT808Version.JTT2019), cancellationToken); | |||
await Task.Delay(1000); | |||
var p1 = JT808MsgId.终端注册.Create(sim, new JT808_0x0100() | |||
var p1 = JT808MsgId._0x0100.Create(sim, new JT808_0x0100() | |||
{ | |||
PlateNo = "粤A12346", | |||
PlateColor = 0, | |||
@@ -62,7 +62,7 @@ namespace JT808.Gateway.NBIotSimpleClient.Jobs | |||
if (!string.IsNullOrEmpty(deviceInfo.Code)) | |||
{ | |||
//2.终端鉴权 | |||
await client1.SendAsync(JT808MsgId.终端鉴权.Create(sim, new JT808_0x0102() | |||
await client1.SendAsync(JT808MsgId._0x0102.Create(sim, new JT808_0x0102() | |||
{ | |||
Code= deviceInfo.Code, | |||
})); | |||
@@ -80,7 +80,7 @@ namespace JT808.Gateway.NBIotSimpleClient.Jobs | |||
{ | |||
if (deviceInfo.Successed) | |||
{ | |||
await client1.SendAsync(JT808MsgId.位置信息汇报.Create(sim, new JT808_0x0200() | |||
await client1.SendAsync(JT808MsgId._0x0200.Create(sim, new JT808_0x0200() | |||
{ | |||
Lat = 110000 + i, | |||
Lng = 100000 + i, | |||
@@ -94,7 +94,7 @@ namespace JT808.Gateway.NBIotSimpleClient.Jobs | |||
} | |||
} | |||
i++; | |||
await Task.Delay(5000); | |||
await Task.Delay(5000, cancellationToken); | |||
} | |||
}, cancellationToken); | |||
} | |||
@@ -46,7 +46,7 @@ namespace JT808.Gateway.NBIotSimpleClient.Services | |||
{ | |||
foreach(var package in ReceviePackageService.BlockingCollection.GetConsumingEnumerable(cancellationToken)) | |||
{ | |||
if(package.Header.MsgId == JT808MsgId.终端注册应答.ToUInt16Value()) | |||
if(package.Header.MsgId == JT808MsgId._0x8100.ToUInt16Value()) | |||
{ | |||
if (package.Bodies is JT808_0x8100 body) | |||
{ | |||
@@ -57,13 +57,13 @@ namespace JT808.Gateway.NBIotSimpleClient.Services | |||
Logger.LogInformation($"{package.Header.TerminalPhoneNo}-{body.Code}-success"); | |||
} | |||
} | |||
else if (package.Header.MsgId == JT808MsgId.平台通用应答.ToValue()) | |||
else if (package.Header.MsgId == JT808MsgId._0x8001.ToValue()) | |||
{ | |||
if(package.Bodies is JT808_0x8001 body) | |||
{ | |||
if(body.AckMsgId== JT808MsgId.终端鉴权.ToUInt16Value()) | |||
if(body.AckMsgId== JT808MsgId._0x0102.ToUInt16Value()) | |||
{ | |||
if(body.JT808PlatformResult== JT808PlatformResult.成功) | |||
if(body.JT808PlatformResult== JT808PlatformResult.succeed) | |||
{ | |||
if (DeviceInfoService.DeviceInfos.TryGetValue(package.Header.TerminalPhoneNo, out var deviceInfo)) | |||
{ | |||
@@ -81,7 +81,7 @@ namespace JT808.Gateway.NBIotSimpleClient.Services | |||
{ | |||
} | |||
}, cancellationToken); | |||
}); | |||
return Task.CompletedTask; | |||
} | |||
@@ -26,7 +26,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
JT808TcpClient client1 = await jT808TcpClientFactory.Create(new JT808DeviceConfig(sim, "127.0.0.1", 808,version: JT808Version.JTT2011), cancellationToken); | |||
await Task.Delay(2000); | |||
//1.终端注册 | |||
await client1.SendAsync(JT808MsgId.终端注册.Create(sim, new JT808_0x0100() | |||
await client1.SendAsync(JT808MsgId._0x0100.Create(sim, new JT808_0x0100() | |||
{ | |||
PlateNo = "粤A12345", | |||
PlateColor = 2, | |||
@@ -37,7 +37,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
TerminalModel = "Koike001" | |||
})); | |||
//2.终端鉴权 | |||
await client1.SendAsync(JT808MsgId.终端鉴权.Create(sim, new JT808_0x0102() | |||
await client1.SendAsync(JT808MsgId._0x0102.Create(sim, new JT808_0x0102() | |||
{ | |||
Code = "1234" | |||
})); | |||
@@ -46,7 +46,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
{ | |||
var i = 0; | |||
//3.每5秒发一次 | |||
await client1.SendAsync(JT808MsgId.位置信息汇报.Create(sim, new JT808_0x0200() | |||
await client1.SendAsync(JT808MsgId._0x0200.Create(sim, new JT808_0x0200() | |||
{ | |||
Lat = 110000 + i, | |||
Lng = 100000 + i, | |||
@@ -58,9 +58,9 @@ namespace JT808.Gateway.SimpleClient.Services | |||
StatusFlag = 10 | |||
})); | |||
i++; | |||
await Task.Delay(5000); | |||
await Task.Delay(5000, cancellationToken); | |||
} | |||
}, cancellationToken); | |||
}); | |||
} | |||
public Task StopAsync(CancellationToken cancellationToken) | |||
@@ -26,7 +26,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
JT808TcpClient client1 = await jT808TcpClientFactory.Create(new JT808DeviceConfig(sim, "127.0.0.1", 808,version: JT808Version.JTT2013), cancellationToken); | |||
await Task.Delay(2000); | |||
//1.终端注册 | |||
await client1.SendAsync(JT808MsgId.终端注册.Create(sim, new JT808_0x0100() | |||
await client1.SendAsync(JT808MsgId._0x0100.Create(sim, new JT808_0x0100() | |||
{ | |||
PlateNo = "粤A12345", | |||
PlateColor = 2, | |||
@@ -37,7 +37,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
TerminalModel = "Koike001" | |||
})); | |||
//2.终端鉴权 | |||
await client1.SendAsync(JT808MsgId.终端鉴权.Create(sim, new JT808_0x0102() | |||
await client1.SendAsync(JT808MsgId._0x0102.Create(sim, new JT808_0x0102() | |||
{ | |||
Code = "1234" | |||
})); | |||
@@ -46,7 +46,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
{ | |||
var i = 0; | |||
//3.每5秒发一次 | |||
await client1.SendAsync(JT808MsgId.位置信息汇报.Create(sim, new JT808_0x0200() | |||
await client1.SendAsync(JT808MsgId._0x0200.Create(sim, new JT808_0x0200() | |||
{ | |||
Lat = 110000 + i, | |||
Lng = 100000 + i, | |||
@@ -58,9 +58,9 @@ namespace JT808.Gateway.SimpleClient.Services | |||
StatusFlag = 10 | |||
})); | |||
i++; | |||
await Task.Delay(5000); | |||
await Task.Delay(5000, cancellationToken); | |||
} | |||
}, cancellationToken); | |||
}); | |||
} | |||
public Task StopAsync(CancellationToken cancellationToken) | |||
@@ -26,7 +26,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
JT808TcpClient client1 = await jT808TcpClientFactory.Create(new JT808DeviceConfig(sim, "127.0.0.1", 808, version:JT808Version.JTT2019), cancellationToken); | |||
await Task.Delay(2000); | |||
//1.终端注册 | |||
await client1.SendAsync(JT808MsgId.终端注册.Create2019(sim, new JT808_0x0100() | |||
await client1.SendAsync(JT808MsgId._0x0100.Create2019(sim, new JT808_0x0100() | |||
{ | |||
PlateNo = "粤A12346", | |||
PlateColor = 2, | |||
@@ -37,7 +37,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
TerminalModel = "Koike002" | |||
})); | |||
//2.终端鉴权 | |||
await client1.SendAsync(JT808MsgId.终端鉴权.Create2019(sim, new JT808_0x0102() | |||
await client1.SendAsync(JT808MsgId._0x0102.Create2019(sim, new JT808_0x0102() | |||
{ | |||
Code = "6666", | |||
IMEI="123456", | |||
@@ -49,7 +49,7 @@ namespace JT808.Gateway.SimpleClient.Services | |||
{ | |||
var i = 0; | |||
//3.每5秒发一次 | |||
await client1.SendAsync(JT808MsgId.位置信息汇报.Create2019(sim, new JT808_0x0200() | |||
await client1.SendAsync(JT808MsgId._0x0200.Create2019(sim, new JT808_0x0200() | |||
{ | |||
Lat = 110000 + i, | |||
Lng = 100000 + i, | |||
@@ -61,9 +61,9 @@ namespace JT808.Gateway.SimpleClient.Services | |||
StatusFlag = 10 | |||
})); | |||
i++; | |||
await Task.Delay(5000); | |||
await Task.Delay(5000, cancellationToken); | |||
} | |||
}, cancellationToken); | |||
}); | |||
} | |||
public Task StopAsync(CancellationToken cancellationToken) | |||
@@ -34,8 +34,7 @@ namespace JT808.Gateway.SimpleQueueServer | |||
.AddServerKafkaMsgReplyConsumer(hostContext.Configuration) | |||
.AddServerKafkaSessionProducer(hostContext.Configuration) | |||
.AddTcp() | |||
.AddUdp() | |||
.AddHttp(); | |||
.AddUdp(); | |||
}); | |||
await serverHostBuilder.RunConsoleAsync(); | |||
@@ -40,7 +40,7 @@ namespace JT808.Gateway.SimpleServer | |||
services.AddSingleton<JT808SessionService>(); | |||
services.AddSingleton<IJT808SessionProducer, JT808SessionProducer>(); | |||
services.AddSingleton<IJT808SessionConsumer, JT808SessionConsumer>(); | |||
services.AddJT808Configure() | |||
services.AddJT808Configure() | |||
.AddGateway(hostContext.Configuration) | |||
.AddMessageHandler<JT808MessageHandlerImpl>() | |||
.AddMsgLogging<JT808MsgLogging>() | |||
@@ -48,7 +48,6 @@ namespace JT808.Gateway.SimpleServer | |||
.AddTransmit(hostContext.Configuration) | |||
.AddTcp() | |||
.AddUdp() | |||
.AddHttp() | |||
.Builder(); | |||
}); | |||
@@ -62,7 +62,7 @@ namespace JT808.Gateway.Kafka | |||
logger.LogError(ex, TopicName); | |||
} | |||
} | |||
}, Cts.Token); | |||
}); | |||
} | |||
public void Subscribe() | |||
{ | |||
@@ -61,7 +61,7 @@ namespace JT808.Gateway.Kafka | |||
logger.LogError(ex, TopicName); | |||
} | |||
} | |||
}, Cts.Token); | |||
}); | |||
} | |||
public void Subscribe() | |||
@@ -61,7 +61,7 @@ namespace JT808.Gateway.Kafka | |||
logger.LogError(ex, TopicName); | |||
} | |||
} | |||
}, Cts.Token); | |||
}); | |||
} | |||
public void Subscribe() | |||
@@ -62,7 +62,7 @@ namespace JT808.Gateway.Kafka | |||
logger.LogError(ex, TopicName); | |||
} | |||
} | |||
}, Cts.Token); | |||
}); | |||
} | |||
public void Subscribe() | |||
@@ -1,6 +1,7 @@ | |||
using JT808.Gateway.Abstractions.Dtos; | |||
using JT808.Gateway.WebApiClientTool; | |||
using System.Net.Http; | |||
using System.Net.Http.Json; | |||
using System.Text.Json; | |||
using System.Threading.Tasks; | |||
@@ -22,8 +23,7 @@ namespace JT808.Gateway.NormalHosting.Customs | |||
var request = new HttpRequestMessage(HttpMethod.Get, index1); | |||
var response = await HttpClient.SendAsync(request); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<string>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<string>>(); | |||
return value; | |||
} | |||
} | |||
@@ -41,8 +41,8 @@ namespace JT808.Gateway.NormalHosting.Jobs | |||
HexData= "7E02000026123456789012007D02000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D01137E" | |||
}); | |||
Logger.LogInformation($"[GetIndex Ext]:{JsonSerializer.Serialize(result1)}"); | |||
Logger.LogInformation($"[GetTcpAtomicCounter]:{JsonSerializer.Serialize(result2)}"); | |||
Logger.LogInformation($"[GetTcpSessionAll]:{JsonSerializer.Serialize(result3)}"); | |||
Logger.LogInformation($"[GetTcpSessionAll]:{JsonSerializer.Serialize(result2)}"); | |||
Logger.LogInformation($"[UnificationSend]:{JsonSerializer.Serialize(result3)}"); | |||
Thread.Sleep(3000); | |||
} | |||
}, cancellationToken); | |||
@@ -31,6 +31,8 @@ namespace JT808.Gateway.NormalHosting | |||
{ | |||
static void Main(string[] args) | |||
{ | |||
//ref:https://andrewlock.net/exploring-dotnet-6-part-2-comparing-webapplicationbuilder-to-the-generic-host/ | |||
//the new hotness in .NET 6. | |||
var builder = WebApplication.CreateBuilder(); | |||
builder.Host.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
@@ -95,7 +97,9 @@ namespace JT808.Gateway.NormalHosting | |||
}); | |||
var app = builder.Build(); | |||
app.UseRouting(); | |||
app.UseCors(); | |||
app.MapControllers().RequireCors("jt808"); | |||
app.Run(); | |||
@@ -3,7 +3,8 @@ | |||
"LogLevel": { | |||
"Default": "Debug", | |||
"Microsoft.AspNetCore.Mvc": "Information", | |||
"Microsoft.AspNetCore.Server.Kestrel": "Information" | |||
"Microsoft.AspNetCore.Server.Kestrel": "Information", | |||
"Microsoft.Extensions.Http.*": "Information" | |||
} | |||
}, | |||
"JT808Configuration": { | |||
@@ -1,4 +1,4 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||
<PropertyGroup> | |||
<OutputType>Exe</OutputType> | |||
@@ -17,6 +17,9 @@ using JT808.Gateway.Kafka; | |||
using JT808.Gateway.WebApiClientTool; | |||
using JT808.Gateway.QueueHosting.Impl; | |||
using JT808.Gateway.MsgIdHandler; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Hosting; | |||
using JT808.Gateway.Abstractions.Configurations; | |||
namespace JT808.Gateway.QueueHosting | |||
{ | |||
@@ -24,7 +27,8 @@ namespace JT808.Gateway.QueueHosting | |||
{ | |||
static async Task Main(string[] args) | |||
{ | |||
var serverHostBuilder = new HostBuilder() | |||
var serverHostBuilder = Host.CreateDefaultBuilder() | |||
.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory) | |||
@@ -73,8 +77,42 @@ namespace JT808.Gateway.QueueHosting | |||
services.AddHostedService<CallHttpClientJob>(); | |||
//客户端测试 | |||
services.AddHostedService<UpJob>(); | |||
}) | |||
.ConfigureWebHostDefaults(webBuilder => { | |||
webBuilder.UseKestrel((app, ksOptions) => | |||
{ | |||
//1.配置webapi端口监听 | |||
var jT808Configuration = app.Configuration.GetSection(nameof(JT808Configuration)).Get<JT808Configuration>(); | |||
ksOptions.ListenAnyIP(jT808Configuration.WebApiPort); | |||
}) | |||
.UseStartup<Startup>(); | |||
}); | |||
await serverHostBuilder.RunConsoleAsync(); | |||
} | |||
} | |||
public class Startup | |||
{ | |||
public Startup(IConfiguration configuration) | |||
{ | |||
Configuration = configuration; | |||
} | |||
public IConfiguration Configuration { get; } | |||
public void ConfigureServices(IServiceCollection services) | |||
{ | |||
services.AddControllers(); | |||
} | |||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |||
{ | |||
app.UseRouting(); | |||
app.UseEndpoints(endpoints => | |||
{ | |||
endpoints.MapControllers(); | |||
}); | |||
} | |||
} | |||
} |
@@ -1,4 +1,12 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Debug", | |||
"Microsoft.Extensions.Http.*": "Information", | |||
"Microsoft.AspNetCore.Routing": "Warning", | |||
"Microsoft.AspNetCore.*": "Warning" | |||
} | |||
}, | |||
"JT808Configuration": { | |||
"TcpPort": 808, | |||
"UdpPort": 808, | |||
@@ -2,7 +2,6 @@ | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<IsPackable>false</IsPackable> | |||
</PropertyGroup> | |||
@@ -4,6 +4,7 @@ using System; | |||
using System.Buffers.Text; | |||
using System.Collections.Generic; | |||
using System.Net.Http; | |||
using System.Net.Http.Json; | |||
using System.Text; | |||
using System.Text.Json; | |||
using System.Threading.Tasks; | |||
@@ -36,12 +37,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<bool>> UnificationSend(JT808UnificationSendRequestDto parameter) | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.UnificationSend); | |||
request.Content = new StringContent(JsonSerializer.Serialize(parameter)); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.UnificationSend, parameter); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<bool>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>(); | |||
return value; | |||
} | |||
@@ -54,8 +52,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
var request = new HttpRequestMessage(HttpMethod.Get, JT808GatewayConstants.JT808WebApiRouteTable.SessionTcpGetAll); | |||
var response = await HttpClient.SendAsync(request); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<List<JT808TcpSessionInfoDto>>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<List<JT808TcpSessionInfoDto>>>(); | |||
return value; | |||
} | |||
@@ -66,12 +63,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<JT808TcpSessionInfoDto>> QueryTcpSessionByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter) | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.QueryTcpSessionByTerminalPhoneNo); | |||
request.Content = new StringContent(JsonSerializer.Serialize(parameter)); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.QueryTcpSessionByTerminalPhoneNo, parameter); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<JT808TcpSessionInfoDto>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808TcpSessionInfoDto>>(); | |||
return value; | |||
} | |||
@@ -82,12 +76,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<bool>> RemoveTcpByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter) | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.SessionRemoveByTerminalPhoneNo); | |||
request.Content = new StringContent(JsonSerializer.Serialize(parameter)); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.SessionRemoveByTerminalPhoneNo, parameter); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<bool>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>(); | |||
return value; | |||
} | |||
@@ -97,11 +88,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<List<JT808UdpSessionInfoDto>>> GetUdpSessionAll() | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Get, JT808GatewayConstants.JT808WebApiRouteTable.SessionUdpGetAll); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.GetAsync(JT808GatewayConstants.JT808WebApiRouteTable.SessionUdpGetAll); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<List<JT808UdpSessionInfoDto>>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<List<JT808UdpSessionInfoDto>>>(); | |||
return value; | |||
} | |||
@@ -112,12 +101,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<JT808UdpSessionInfoDto>> QueryUdpSessionByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter) | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.QueryUdpSessionByTerminalPhoneNo); | |||
request.Content = new StringContent(JsonSerializer.Serialize(parameter)); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.QueryUdpSessionByTerminalPhoneNo, parameter); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<JT808UdpSessionInfoDto>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808UdpSessionInfoDto>>(); | |||
return value; | |||
} | |||
@@ -128,12 +114,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<bool>> RemoveUdpByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter) | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.RemoveUdpByTerminalPhoneNo); | |||
request.Content = new StringContent(JsonSerializer.Serialize(parameter)); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.RemoveUdpByTerminalPhoneNo,parameter); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<bool>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>(); | |||
return value; | |||
} | |||
@@ -144,12 +127,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<bool>> BlacklistAdd(JT808TerminalPhoneNoDto parameter) | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.BlacklistAdd); | |||
request.Content = new StringContent(JsonSerializer.Serialize(parameter)); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.BlacklistAdd, parameter); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<bool>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>(); | |||
return value; | |||
} | |||
@@ -160,12 +140,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<bool>> BlacklistRemove(JT808TerminalPhoneNoDto parameter) | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.BlacklistRemove); | |||
request.Content = new StringContent(JsonSerializer.Serialize(parameter)); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.BlacklistRemove, parameter); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<bool>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>(); | |||
return value; | |||
} | |||
@@ -175,11 +152,9 @@ namespace JT808.Gateway.WebApiClientTool | |||
/// <returns></returns> | |||
public async ValueTask<JT808ResultDto<List<string>>> GetBlacklistAll() | |||
{ | |||
var request = new HttpRequestMessage(HttpMethod.Get, JT808GatewayConstants.JT808WebApiRouteTable.BlacklistGet); | |||
var response = await HttpClient.SendAsync(request); | |||
var response = await HttpClient.GetAsync(JT808GatewayConstants.JT808WebApiRouteTable.BlacklistGet); | |||
response.EnsureSuccessStatusCode(); | |||
var data = await response.Content.ReadAsStreamAsync(); | |||
var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<List<string>>>(data); | |||
var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<List<string>>>(); | |||
return value; | |||
} | |||
} | |||
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Net.Http.Headers; | |||
using System.Text; | |||
namespace JT808.Gateway.WebApiClientTool | |||
@@ -26,6 +27,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Add("token", token); | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.BaseAddress = webapiUri; | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
}) | |||
@@ -43,6 +45,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
{ | |||
serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | |||
c.BaseAddress = new Uri(configuration.GetSection("JT808WebApiClientToolConfig:Uri").Get<string>()); | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
@@ -61,6 +64,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
{ | |||
jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | |||
c.BaseAddress = new Uri(configuration.GetSection("JT808WebApiClientToolConfig:Uri").Get<string>()); | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
@@ -80,6 +84,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
{ | |||
jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.DefaultRequestHeaders.Add("token", token); | |||
c.BaseAddress = webapiUri; | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
@@ -100,6 +105,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
{ | |||
serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.DefaultRequestHeaders.Add("token", token); | |||
c.BaseAddress = webapiUri; | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
@@ -119,6 +125,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
{ | |||
serviceDescriptors.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | |||
c.BaseAddress = new Uri(configuration.GetSection("JT808WebApiClientToolConfig:Uri").Get<string>()); | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
@@ -138,6 +145,7 @@ namespace JT808.Gateway.WebApiClientTool | |||
{ | |||
jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.DefaultRequestHeaders.Add("token", configuration.GetSection("JT808WebApiClientToolConfig:Token").Get<string>()); | |||
c.BaseAddress = new Uri(configuration.GetSection("JT808WebApiClientToolConfig:Uri").Get<string>()); | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
@@ -158,11 +166,11 @@ namespace JT808.Gateway.WebApiClientTool | |||
{ | |||
jT808Builder.Services.AddHttpClient("JT808WebApiClientTool", c => | |||
{ | |||
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |||
c.DefaultRequestHeaders.Add("token", token); | |||
c.BaseAddress = webapiUri; | |||
c.Timeout = TimeSpan.FromSeconds(timeout); | |||
}) | |||
.AddTypedClient<TJT808HttpClient>(); | |||
}).AddTypedClient<TJT808HttpClient>(); | |||
return jT808Builder; | |||
} | |||
} | |||
@@ -80,9 +80,13 @@ namespace JT808.Gateway | |||
{ | |||
Logger.LogError(ex, "Receive MessageFrom Async"); | |||
} | |||
catch (SocketException ex) | |||
{ | |||
//Logger.LogWarning(ex, $"Socket Error"); | |||
} | |||
catch (Exception ex) | |||
{ | |||
Logger.LogError(ex, $"Received Bytes"); | |||
Logger.LogError(ex, $"Service Error"); | |||
} | |||
finally | |||
{ | |||
@@ -84,7 +84,7 @@ namespace JT808.Gateway | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpGet] | |||
[Route("/Tcp/Session/GetAll")] | |||
[Route("Tcp/Session/GetAll")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<List<JT808TcpSessionInfoDto>>> SessionTcpGetAll() | |||
{ | |||
@@ -116,7 +116,7 @@ namespace JT808.Gateway | |||
/// <param name="parameter"></param> | |||
/// <returns></returns> | |||
[HttpPost] | |||
[Route("/Tcp/Session/QuerySessionByTerminalPhoneNo")] | |||
[Route("Tcp/Session/QuerySessionByTerminalPhoneNo")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<JT808TcpSessionInfoDto>> QueryTcpSessionByTerminalPhoneNo([FromBody] JT808TerminalPhoneNoDto parameter) | |||
{ | |||
@@ -147,7 +147,7 @@ namespace JT808.Gateway | |||
/// <param name="parameter"></param> | |||
/// <returns></returns> | |||
[HttpPost] | |||
[Route("/Tcp/Session/RemoveByTerminalPhoneNo")] | |||
[Route("Tcp/Session/RemoveByTerminalPhoneNo")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<bool>> SessionTcpRemoveByTerminalPhoneNo([FromBody] JT808TerminalPhoneNoDto parameter) | |||
{ | |||
@@ -172,7 +172,7 @@ namespace JT808.Gateway | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpGet] | |||
[Route("/Udp/Session/GetAll")] | |||
[Route("Udp/Session/GetAll")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<List<JT808UdpSessionInfoDto>>> SessionUdpGetAll() | |||
{ | |||
@@ -197,13 +197,14 @@ namespace JT808.Gateway | |||
} | |||
return resultDto; | |||
} | |||
/// <summary> | |||
/// 会话服务-通过设备终端号查询对应会话 | |||
/// </summary> | |||
/// <param name="parameter"></param> | |||
/// <returns></returns> | |||
[HttpPost] | |||
[Route("/Udp/Session/QuerySessionByTerminalPhoneNo")] | |||
[Route("Udp/Session/QuerySessionByTerminalPhoneNo")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<JT808UdpSessionInfoDto>> QueryUdpSessionByTerminalPhoneNo([FromBody] JT808TerminalPhoneNoDto parameter) | |||
{ | |||
@@ -234,7 +235,7 @@ namespace JT808.Gateway | |||
/// <param name="parameter"></param> | |||
/// <returns></returns> | |||
[HttpPost] | |||
[Route("/Udp/Session/RemoveByTerminalPhoneNo")] | |||
[Route("Udp/Session/RemoveByTerminalPhoneNo")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<bool>> SessionUdpRemoveByTerminalPhoneNo([FromBody] JT808TerminalPhoneNoDto parameter) | |||
{ | |||
@@ -259,7 +260,7 @@ namespace JT808.Gateway | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpPost] | |||
[Route("/Blacklist/Add")] | |||
[Route("Blacklist/Add")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<bool>> BlacklistAdd([FromBody] JT808TerminalPhoneNoDto parameter) | |||
{ | |||
@@ -284,7 +285,7 @@ namespace JT808.Gateway | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpPost] | |||
[Route("/Blacklist/Remove")] | |||
[Route("Blacklist/Remove")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<bool>> BlacklistRemove([FromBody] JT808TerminalPhoneNoDto parameter) | |||
{ | |||
@@ -309,7 +310,7 @@ namespace JT808.Gateway | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpGet] | |||
[Route("/Blacklist/GetAll")] | |||
[Route("Blacklist/GetAll")] | |||
[JT808Token] | |||
public ActionResult<JT808ResultDto<List<string>>> BlacklistGetAll() | |||
{ | |||