diff --git a/Waste.Application/ThirdApiInfo/Dtos/ThirdApiInfoDto.cs b/Waste.Application/ThirdApiInfo/Dtos/ThirdApiInfoDto.cs
index 0d85865..525cd78 100644
--- a/Waste.Application/ThirdApiInfo/Dtos/ThirdApiInfoDto.cs
+++ b/Waste.Application/ThirdApiInfo/Dtos/ThirdApiInfoDto.cs
@@ -57,6 +57,35 @@ namespace Waste.Application.ThirdApiInfo
/// 串口号
///
public string serialno { get; set; } = "/dev/ttyS1";
+ ///
+ /// websocket地址
+ ///
+ public string WebSocketUrl { get; set; } = "wss://api.device.suzhou.ljflytjl.cn/device_rpc";
+
+ ///
+ /// 时间戳
+ ///
+ public int timestamp { get; set; }
+ ///
+ /// 随机数
+ ///
+ public int noncestr { get; set; }
+ ///
+ /// 用户ID
+ ///
+ public string UserId { get; set; }
+ ///
+ /// secret
+ ///
+ public string Secret { get; set; }
+ ///
+ /// secrethash
+ ///
+ public string SecretHash { get; set; }
+ ///
+ /// 设备ID
+ ///
+ public string DeviceId { get; set; } = "";
}
///
diff --git a/Waste.Application/ThirdApiInfo/OpenService.cs b/Waste.Application/ThirdApiInfo/OpenService.cs
index f00f328..f596519 100644
--- a/Waste.Application/ThirdApiInfo/OpenService.cs
+++ b/Waste.Application/ThirdApiInfo/OpenService.cs
@@ -99,16 +99,11 @@ namespace Waste.Application.ThirdApiInfo
var trashhex = data.data.Substring(16, 10);
var typehex = data.data.Substring(28, 16);
var weighthex = data.data.Substring(46, data.data.Length - 46);
- returndata.trash = trashhex;
+ returndata.trash = Convert.ToInt64(trashhex).ToString(); //垃圾桶编号使用10进制
var type = GetChsFromHex(typehex);
var weight = GetChsFromHex(weighthex);
returndata.type = TrashType(type);
returndata.Weight = weight.ToDouble();
- ////检查体重是否为整数如:10.0这样的情况,需要去除小数点后的数据
- //if (returndata.Weight == ((int)returndata.Weight).ToDouble())
- //{
- // returndata.Weight = returndata.Weight.ToDouble(0);
- //}
returndata.IsSuccessed = true;
string[] paramlist = new string[] {
returndata.Weight.ToString(),returndata.trash,returndata.type.ToString(),returndata.ScanningTime.ToString(),returndata.status.ToString()
@@ -150,26 +145,6 @@ namespace Waste.Application.ThirdApiInfo
});
var logger = App.GetService();
logger.AddLogger($"发送的数据:{returndata.ToJson()}", 1);
- //上传垃圾数据
- //if (returndata.Weight > 0)
- //{
- // if (devicesecret != null && !string.IsNullOrEmpty(devicesecret.Secret)
- // && !string.IsNullOrEmpty(devicesecret.SecretHash)
- // && !string.IsNullOrEmpty(devicesecret.DevId))
- // {
- // await _suZhouService.PostGarbagesAsync(new GarbagePltC2SDto
- // {
- // Weight = returndata.Weight,
- // secret = devicesecret.Secret,
- // secrethash = devicesecret.SecretHash,
- // ScanningTime = timestamp,
- // DStatus = 0,
- // deviceid = devicesecret.DevId,
- // Trash = returndata.trash,
- // Type = returndata.type
- // });
- // }
- //}
}
return new ResultInfo(ResultState.SUCCESS, "success", returndata);
}
@@ -299,8 +274,22 @@ namespace Waste.Application.ThirdApiInfo
}
var data = new DevRegInfoResponseDto
{
- status = 0
+ status = 0,
+ WebSocketUrl = App.Configuration["SZDevPlatSetting:SocketUrl"]
};
+ //获取授权信息
+ var devicesecret = await dbClient.Queryable().FirstAsync(x => x.DeviceId == device.Id);
+ if (devicesecret != null && !string.IsNullOrEmpty(devicesecret.Secret)
+ && !string.IsNullOrEmpty(devicesecret.SecretHash)
+ && !string.IsNullOrEmpty(devicesecret.DevId))
+ {
+ data.timestamp = _suZhouService.GetTimestamp();
+ data.noncestr = _suZhouService.GetNonce();
+ data.UserId = UserId;
+ data.Secret = devicesecret.Secret;
+ data.SecretHash = devicesecret.SecretHash;
+ data.DeviceId = devicesecret.DeviceId.ToString();
+ }
return new ResultInfo(ResultState.SUCCESS, "success", data);
}
private int TrashType(string type)
diff --git a/Waste.Application/Waste.Application.xml b/Waste.Application/Waste.Application.xml
index a20af6e..b760e86 100644
--- a/Waste.Application/Waste.Application.xml
+++ b/Waste.Application/Waste.Application.xml
@@ -2005,6 +2005,41 @@
串口号
+
+
+ websocket地址
+
+
+
+
+ 时间戳
+
+
+
+
+ 随机数
+
+
+
+
+ 用户ID
+
+
+
+
+ secret
+
+
+
+
+ secrethash
+
+
+
+
+ 设备ID
+
+
获取设备信息请求数据,并上报数据
diff --git a/Waste.Web.Core/Startup.cs b/Waste.Web.Core/Startup.cs
index 01b439d..3cf1a19 100644
--- a/Waste.Web.Core/Startup.cs
+++ b/Waste.Web.Core/Startup.cs
@@ -48,6 +48,8 @@ namespace Waste.Web.Core
services.AddSingleton();
MyHttpContext.serviceCollection = services;
#endregion
+ //添加即时通讯
+ // services.AddSignalR();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
@@ -83,8 +85,11 @@ namespace Waste.Web.Core
app.UseInject();
+
app.UseEndpoints(endpoints =>
{
+ //注册集线器
+ // endpoints.MapHubs();
//endpoints.MapGet("/index.html", async context => {
// await context.Response.WriteAsync("Hello");
//});
diff --git a/Waste.Web.Entry/Pages/Socket/Test.cshtml b/Waste.Web.Entry/Pages/Socket/Test.cshtml
index 54db55b..8718c81 100644
--- a/Waste.Web.Entry/Pages/Socket/Test.cshtml
+++ b/Waste.Web.Entry/Pages/Socket/Test.cshtml
@@ -47,7 +47,7 @@
});
$(".js-connect").on("click", function () {
var val = {
- "protocol": "messagepack",
+ "protocol": "json",
"version":1
};
var data = JSON.stringify(val);
diff --git a/Waste.Web.Entry/Pages/Socket/Test.cshtml.cs b/Waste.Web.Entry/Pages/Socket/Test.cshtml.cs
index b71c977..a3da5f4 100644
--- a/Waste.Web.Entry/Pages/Socket/Test.cshtml.cs
+++ b/Waste.Web.Entry/Pages/Socket/Test.cshtml.cs
@@ -1,17 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.WebSockets;
+using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
+using Waste.Application;
namespace Waste.Web.Entry.Pages.Socket
{
public class TestModel : PageModel
{
- public void OnGet()
+ private readonly ILoggerService _loggerService;
+ public TestModel(ILoggerService loggerService)
{
+ _loggerService = loggerService;
+ }
+ public async Task OnGetAsync()
+ {
+ await OnGetTestAsync();
+ }
+ public async Task OnGetTestAsync()
+ {
+ string BaseUrl = "wss://api.device.suzhou.ljflytjl.cn/device_rpc";
+ ClientWebSocket client = new ClientWebSocket();
+ client.Options.AddSubProtocol("protocol1");
+ client.Options.SetRequestHeader("device", "08d9588d-4796-48f9-8c5b-f28f271b51d0");
+ client.Options.SetRequestHeader("secret", "bfbaf98fb5b343b2");
+ client.Options.SetRequestHeader("time", GetTimestamp().ToString());
+ client.Options.SetRequestHeader("os", "12");
+ client.Options.SetRequestHeader("script", "2");
+ client.Options.SetRequestHeader("baseProgrameLang", "10");
+ client.Options.SetRequestHeader("dev", "true");
+ await client.ConnectAsync(new Uri(BaseUrl), CancellationToken.None);
+ Console.WriteLine("Connect success");
+
+ await client.SendAsync(new ArraySegment(AddSeparator(Encoding.UTF8.GetBytes(@"{""protocol"":""json"", ""version"":1}")))
+ , WebSocketMessageType.Text, true, CancellationToken.None);//ְ
+ Console.WriteLine("Send success");
+
+ var buffer = new ArraySegment(new byte[1024]);
+ while (client.State == WebSocketState.Open)
+ {
+ var bytes = Encoding.UTF8.GetBytes(@"{
+ ""type"": 6
+ }");//Զ̵ log
+ await client.SendAsync(new ArraySegment(AddSeparator(bytes)), WebSocketMessageType.Text, true, CancellationToken.None);
+
+
+ await client.ReceiveAsync(buffer, CancellationToken.None);
+ byte[] databytes = new byte[buffer.Count];
+ for(int i = buffer.Offset; i < (buffer.Offset + buffer.Count); i++)
+ {
+ var aa = buffer.Array[i];
+ databytes[i] = aa;
+ }
+ var str = Encoding.UTF8.GetString(databytes);
+ //
+ _loggerService.AddLogger(str, 1);
+ Console.WriteLine(str);
+ }
+ }
+
+ private static byte[] AddSeparator(byte[] data)
+ {
+ List t = new List(data) { 0x1e };//0x1e record separator
+ return t.ToArray();
+ }
+ private static byte[] RemoveSeparator(byte[] data)
+ {
+ List t = new List(data);
+ t.Remove(0x1e);
+ return t.ToArray();
+ }
+ ///
+ /// ȡʱ
+ ///
+ ///
+ private int GetTimestamp()
+ {
+ DateTime dateTimeStart = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));
+ int timestamp = Convert.ToInt32((DateTime.Now - dateTimeStart).TotalSeconds);
+ return timestamp;
+ }
+ ///
+ /// ȡ
+ ///
+ ///
+ private int GetNonce()
+ {
+ var random = new Random();
+ int nonce = random.Next(1, Int32.MaxValue);
+ return nonce;
}
}
}
diff --git a/Waste.Web.Entry/Properties/PublishProfiles/waste.ybhdmob.com.pubxml.user b/Waste.Web.Entry/Properties/PublishProfiles/waste.ybhdmob.com.pubxml.user
index 78371ac..1ce11e0 100644
--- a/Waste.Web.Entry/Properties/PublishProfiles/waste.ybhdmob.com.pubxml.user
+++ b/Waste.Web.Entry/Properties/PublishProfiles/waste.ybhdmob.com.pubxml.user
@@ -5,6 +5,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<_PublishTargetUrl>D:\webpublish\waste.ybhdmob.com
- True|2021-08-03T03:16:02.7897282Z;True|2021-08-02T16:39:27.2332369+08:00;True|2021-08-02T15:07:40.7995318+08:00;True|2021-08-02T14:32:29.6885424+08:00;True|2021-08-02T14:31:18.6578543+08:00;True|2021-08-02T14:27:57.1301002+08:00;True|2021-08-02T10:55:40.3542370+08:00;True|2021-08-02T09:44:28.0994056+08:00;True|2021-08-01T13:49:38.4071985+08:00;True|2021-08-01T13:36:45.5372120+08:00;True|2021-08-01T11:00:19.6165520+08:00;True|2021-08-01T10:38:51.4029710+08:00;True|2021-07-31T20:27:53.6583811+08:00;True|2021-07-31T18:35:23.4214441+08:00;True|2021-07-31T17:34:14.0712243+08:00;True|2021-07-31T14:50:43.2065556+08:00;True|2021-07-30T17:59:30.2223340+08:00;True|2021-07-30T17:57:35.9412910+08:00;True|2021-07-30T17:07:58.3305971+08:00;True|2021-07-30T17:04:10.9244859+08:00;True|2021-07-30T17:02:12.1943634+08:00;True|2021-07-30T16:16:22.2838331+08:00;True|2021-07-30T15:05:26.5664155+08:00;True|2021-07-30T14:57:59.1966108+08:00;True|2021-07-30T14:54:25.8172908+08:00;True|2021-07-30T14:52:20.9209995+08:00;True|2021-07-30T14:35:29.5239463+08:00;True|2021-07-30T09:32:38.2676032+08:00;True|2021-07-30T09:14:42.6170851+08:00;True|2021-07-29T19:06:09.1449349+08:00;True|2021-06-11T08:16:29.9542894+08:00;True|2021-06-04T14:46:02.2707457+08:00;True|2021-06-02T15:08:52.8245632+08:00;True|2021-06-02T15:05:50.3614099+08:00;True|2021-06-02T14:59:32.3690948+08:00;True|2021-06-02T14:10:25.1182836+08:00;True|2021-06-02T14:09:54.9215833+08:00;True|2021-06-01T10:41:54.9488501+08:00;True|2021-06-01T10:38:56.0283198+08:00;True|2021-05-28T13:59:02.2308877+08:00;True|2021-05-28T11:56:26.6796406+08:00;True|2021-05-28T11:28:00.4087907+08:00;True|2021-05-27T16:18:09.5993838+08:00;True|2021-05-27T16:07:31.3484951+08:00;True|2021-05-27T11:30:37.9119310+08:00;True|2021-05-27T11:28:35.5374674+08:00;True|2021-05-27T08:00:09.1625592+08:00;True|2021-05-26T20:42:17.0852150+08:00;True|2021-05-26T20:36:49.7527415+08:00;True|2021-05-25T17:57:31.8791293+08:00;True|2021-05-25T13:49:29.6488978+08:00;True|2021-05-25T13:48:24.6686105+08:00;True|2021-05-25T13:25:41.2512493+08:00;True|2021-05-24T17:55:33.3800078+08:00;True|2021-05-20T14:35:30.6957985+08:00;True|2021-05-20T13:17:22.6192995+08:00;True|2021-05-20T10:51:38.1268169+08:00;True|2021-05-19T19:50:03.7000224+08:00;True|2021-05-19T19:44:27.2518811+08:00;True|2021-05-19T19:43:26.5916681+08:00;True|2021-05-19T19:36:29.3197365+08:00;True|2021-05-19T19:30:00.3802430+08:00;True|2021-05-19T17:55:23.7939835+08:00;True|2021-05-19T11:05:17.9043392+08:00;True|2021-05-19T10:19:38.4839988+08:00;True|2021-05-19T10:17:19.7430612+08:00;True|2021-05-19T10:13:23.0031721+08:00;True|2021-05-19T10:06:03.9881599+08:00;True|2021-05-18T14:39:03.8876574+08:00;True|2021-05-18T14:23:46.9818836+08:00;True|2021-05-18T14:19:56.2382079+08:00;True|2021-05-18T11:29:53.5497590+08:00;True|2021-05-18T11:16:18.0123853+08:00;True|2021-05-17T18:59:52.4159105+08:00;True|2021-05-17T18:53:37.9438984+08:00;True|2021-05-17T18:48:14.9625161+08:00;True|2021-05-17T17:46:03.7723404+08:00;True|2021-05-17T17:14:20.2312990+08:00;True|2021-05-17T16:44:34.5837616+08:00;True|2021-05-17T16:25:20.1087804+08:00;True|2021-05-17T11:35:27.9388562+08:00;
+ True|2021-08-10T23:54:57.1322848Z;True|2021-08-10T10:16:40.7495389+08:00;True|2021-08-03T11:16:02.7897282+08:00;True|2021-08-02T16:39:27.2332369+08:00;True|2021-08-02T15:07:40.7995318+08:00;True|2021-08-02T14:32:29.6885424+08:00;True|2021-08-02T14:31:18.6578543+08:00;True|2021-08-02T14:27:57.1301002+08:00;True|2021-08-02T10:55:40.3542370+08:00;True|2021-08-02T09:44:28.0994056+08:00;True|2021-08-01T13:49:38.4071985+08:00;True|2021-08-01T13:36:45.5372120+08:00;True|2021-08-01T11:00:19.6165520+08:00;True|2021-08-01T10:38:51.4029710+08:00;True|2021-07-31T20:27:53.6583811+08:00;True|2021-07-31T18:35:23.4214441+08:00;True|2021-07-31T17:34:14.0712243+08:00;True|2021-07-31T14:50:43.2065556+08:00;True|2021-07-30T17:59:30.2223340+08:00;True|2021-07-30T17:57:35.9412910+08:00;True|2021-07-30T17:07:58.3305971+08:00;True|2021-07-30T17:04:10.9244859+08:00;True|2021-07-30T17:02:12.1943634+08:00;True|2021-07-30T16:16:22.2838331+08:00;True|2021-07-30T15:05:26.5664155+08:00;True|2021-07-30T14:57:59.1966108+08:00;True|2021-07-30T14:54:25.8172908+08:00;True|2021-07-30T14:52:20.9209995+08:00;True|2021-07-30T14:35:29.5239463+08:00;True|2021-07-30T09:32:38.2676032+08:00;True|2021-07-30T09:14:42.6170851+08:00;True|2021-07-29T19:06:09.1449349+08:00;True|2021-06-11T08:16:29.9542894+08:00;True|2021-06-04T14:46:02.2707457+08:00;True|2021-06-02T15:08:52.8245632+08:00;True|2021-06-02T15:05:50.3614099+08:00;True|2021-06-02T14:59:32.3690948+08:00;True|2021-06-02T14:10:25.1182836+08:00;True|2021-06-02T14:09:54.9215833+08:00;True|2021-06-01T10:41:54.9488501+08:00;True|2021-06-01T10:38:56.0283198+08:00;True|2021-05-28T13:59:02.2308877+08:00;True|2021-05-28T11:56:26.6796406+08:00;True|2021-05-28T11:28:00.4087907+08:00;True|2021-05-27T16:18:09.5993838+08:00;True|2021-05-27T16:07:31.3484951+08:00;True|2021-05-27T11:30:37.9119310+08:00;True|2021-05-27T11:28:35.5374674+08:00;True|2021-05-27T08:00:09.1625592+08:00;True|2021-05-26T20:42:17.0852150+08:00;True|2021-05-26T20:36:49.7527415+08:00;True|2021-05-25T17:57:31.8791293+08:00;True|2021-05-25T13:49:29.6488978+08:00;True|2021-05-25T13:48:24.6686105+08:00;True|2021-05-25T13:25:41.2512493+08:00;True|2021-05-24T17:55:33.3800078+08:00;True|2021-05-20T14:35:30.6957985+08:00;True|2021-05-20T13:17:22.6192995+08:00;True|2021-05-20T10:51:38.1268169+08:00;True|2021-05-19T19:50:03.7000224+08:00;True|2021-05-19T19:44:27.2518811+08:00;True|2021-05-19T19:43:26.5916681+08:00;True|2021-05-19T19:36:29.3197365+08:00;True|2021-05-19T19:30:00.3802430+08:00;True|2021-05-19T17:55:23.7939835+08:00;True|2021-05-19T11:05:17.9043392+08:00;True|2021-05-19T10:19:38.4839988+08:00;True|2021-05-19T10:17:19.7430612+08:00;True|2021-05-19T10:13:23.0031721+08:00;True|2021-05-19T10:06:03.9881599+08:00;True|2021-05-18T14:39:03.8876574+08:00;True|2021-05-18T14:23:46.9818836+08:00;True|2021-05-18T14:19:56.2382079+08:00;True|2021-05-18T11:29:53.5497590+08:00;True|2021-05-18T11:16:18.0123853+08:00;True|2021-05-17T18:59:52.4159105+08:00;True|2021-05-17T18:53:37.9438984+08:00;True|2021-05-17T18:48:14.9625161+08:00;True|2021-05-17T17:46:03.7723404+08:00;True|2021-05-17T17:14:20.2312990+08:00;True|2021-05-17T16:44:34.5837616+08:00;True|2021-05-17T16:25:20.1087804+08:00;True|2021-05-17T11:35:27.9388562+08:00;
\ No newline at end of file
diff --git a/Waste.Web.Entry/appsettings.json b/Waste.Web.Entry/appsettings.json
index fb127f9..1f0c9ca 100644
--- a/Waste.Web.Entry/appsettings.json
+++ b/Waste.Web.Entry/appsettings.json
@@ -47,7 +47,8 @@
"ApiUrl": "https://api.data.suzhou.ljflytjl.cn",
"UserId": "55863a65-a28c-4e7f-8835-1fa779e1eb9f",
"ApiSecret": "EtifGTppTL0TTjie",
- "ApiSecretHash": "3f907fe05acb58c6"
+ "ApiSecretHash": "3f907fe05acb58c6",
+ "SocketUrl": "wss://api.device.suzhou.ljflytjl.cn/device_rpc"
},
"IsTask": "false", //定时任务是否开启
"SoftName": "巨鼎物联网数字平台", //软件名称
diff --git a/Waste.Web.Entry/libman.json b/Waste.Web.Entry/libman.json
new file mode 100644
index 0000000..872477a
--- /dev/null
+++ b/Waste.Web.Entry/libman.json
@@ -0,0 +1,10 @@
+{
+ "version": "1.0",
+ "defaultProvider": "unpkg",
+ "libraries": [
+ {
+ "library": "@microsoft/signalr@latest",
+ "destination": "wwwroot/lib/microsoft/signalr/"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Waste.Web.Entry/wwwroot/lib/microsoft/signalr/README.md b/Waste.Web.Entry/wwwroot/lib/microsoft/signalr/README.md
new file mode 100644
index 0000000..4339b73
--- /dev/null
+++ b/Waste.Web.Entry/wwwroot/lib/microsoft/signalr/README.md
@@ -0,0 +1,85 @@
+JavaScript and TypeScript clients for SignalR for ASP.NET Core and Azure SignalR Service
+
+## Installation
+
+```bash
+npm install @microsoft/signalr
+# or
+yarn add @microsoft/signalr
+```
+
+To try previews of the next version, use the `next` tag on NPM:
+
+```bash
+npm install @microsoft/signalr@next
+# or
+yarn add @microsoft/signalr@next
+```
+
+## Usage
+
+See the [SignalR Documentation](https://docs.microsoft.com/aspnet/core/signalr) at docs.microsoft.com for documentation on the latest release. [API Reference Documentation](https://docs.microsoft.com/javascript/api/%40aspnet/signalr/?view=signalr-js-latest) is also available on docs.microsoft.com.
+
+For documentation on using this client with Azure SignalR Service and Azure Functions, see the [SignalR Service serverless developer guide](https://docs.microsoft.com/azure/azure-signalr/signalr-concept-serverless-development-config).
+
+### Browser
+
+To use the client in a browser, copy `*.js` files from the `dist/browser` folder to your script folder include on your page using the `