diff --git a/SlnMesnac.TouchSocket/Back.cs b/SlnMesnac.TouchSocket/Back.cs new file mode 100644 index 0000000..2e8df36 --- /dev/null +++ b/SlnMesnac.TouchSocket/Back.cs @@ -0,0 +1,13 @@ +using System; + +namespace SlnMesnac.TouchSocket +{ + public class Back + { + public int Code { get; set; } =200; + public string msg { get; set; } = "操作成功"; + public string timestamp { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); + } + + +} \ No newline at end of file diff --git a/SlnMesnac.TouchSocket/ScanLogSocket.cs b/SlnMesnac.TouchSocket/ScanLogSocket.cs new file mode 100644 index 0000000..a11f854 --- /dev/null +++ b/SlnMesnac.TouchSocket/ScanLogSocket.cs @@ -0,0 +1,30 @@ +using System; + +public class ScanLogSocket +{ + /// + /// + /// + + + public DateTime CreateTime + { + get + { + DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(timestamp); + return dateTimeOffset.UtcDateTime; + } + } + + public long timestamp { get; set; } + + public int data_type { get; set; } + + public string ffid { get; set; } + + public string code { get; set; } + + public string ocr { get; set; } + + public string url { get; set; } +} \ No newline at end of file diff --git a/SlnMesnac.TouchSocket/ScanStatusSocket.cs b/SlnMesnac.TouchSocket/ScanStatusSocket.cs new file mode 100644 index 0000000..ce8c42d --- /dev/null +++ b/SlnMesnac.TouchSocket/ScanStatusSocket.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +public class ScanStatusSocket +{ + public DateTime CreateTime + { + get + { + DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(timestamp); + return dateTimeOffset.UtcDateTime; + } + } + + public long timestamp { get; set; } + + public int data_type { get; set; } + + public int is_alarm { get; set; } + + public List device_status { get; set; } +} \ No newline at end of file diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs index 70f8afc..86b0710 100644 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ b/SlnMesnac.TouchSocket/TcpServer.cs @@ -2,8 +2,11 @@ using System; using System.Collections.Generic; using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using TouchSocket.Core; using TouchSocket.Sockets; +using JsonSerializer = System.Text.Json.JsonSerializer; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -74,7 +77,30 @@ namespace SlnMesnac.TouchSocket byte[] receivedBuffer = new byte[e.ByteBlock.Len]; Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len); ReceivedClientBufferEvent?.Invoke(receivedBuffer); + + int dataType = 0; + var jObject = JObject.Parse(mes); + if (jObject.TryGetValue("data_type", out var value)) + { + dataType=value.Value(); + } + + if (dataType == 1) + { + ScanStatusSocket scanStatus= JsonConvert.DeserializeObject(mes); + } + else + { + if (dataType == 2) + { + ScanLogSocket scanStatus= JsonConvert.DeserializeObject(mes); + } + } + + // DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(timestamp); + // DateTime dateTime = dateTimeOffset.UtcDateTime; + client.SendAsync(mes); return EasyTask.CompletedTask; };