websocket测试

This commit is contained in:
Hinse 2021-08-06 18:23:12 +08:00
parent a23d44d5b0
commit 0d60acf8dd
6 changed files with 123 additions and 3 deletions

View File

@ -126,20 +126,21 @@ namespace Waste.Application
public async Task<ResultInfo> PostGarbagesAsync(GarbageC2SDto garbageC2SDto)
{
var url = $"{ApiUrl}/api/garbages";
garbageC2SDto.ScanningTime = GetTimestamp();
string[] paramlist = new string[] {
garbageC2SDto.Weight.ToString(),garbageC2SDto.Trash,garbageC2SDto.Type.ToString(),garbageC2SDto.ScanningTime.ToString(),garbageC2SDto.DStatus.ToString()
};
int timestamp = GetTimestamp();
int nonce = GetNonce();
string sign = GetUserApiSign("8137VxS0S01eooVc", paramlist);
string sign = GetUserApiSign("lsBThmYBYUMrmwkl", paramlist);
var c2s_dto = new SuZhouPostApiBaseDto<GarbageC2SDto>
{
Data = garbageC2SDto,
SecretHash = "1eca5f6af7d84fb3",
SecretHash = "bfbaf98fb5b343b2",
Nonce = nonce,
Signature = sign,
TimeStamp = timestamp,
DeviceId = "08d92039-6b06-4650-8691-f71d4aa52f0a"
DeviceId = "08d9588d-4796-48f9-8c5b-f28f271b51d0"
};
var request = new HttpRequestMessage(HttpMethod.Post, url);
var bytes = MessagePackSerializer.Serialize(c2s_dto);

View File

@ -0,0 +1,34 @@
附件三:关于读卡器、垃圾桶芯片编码标准、设备编号标准
1、由于垃圾桶在收运过程中存在流转现象为规避读卡器不兼容的情况建议读卡器的频率重点选择ISM915MHZ频段并对垃圾桶芯片采用统一格式编码要求如下
1垃圾种类数据定义
其它垃圾3016进制1个字节
厨余垃圾31
可回收垃圾32
有害垃圾33
2垃圾桶数据定义
小桶3016进制1个字节
大桶31
编号XX XX XX XX XX16进制5个字节最大为FFFFFFFFFF=1099511627775即1万多亿
一张卡片的卡片有效信息为:垃圾种类+桶种类+编号。如厨余垃圾小桶100号数据格式为31 30 00 00 00 00 64
卡片数据完整为:
垃圾桶编号
垃圾桶编号
厂家预留
厂家预留
桶大小
桶大小
垃圾种类
垃圾种类
00 00 00 00 00 31 30 00 00 00 00 64
厂家预留(红字),其中后二位由平台服务商提供,前二位厂商使用需与平台服务商沟通,确认之后使用,避免重复。
2、为直观区分各厂家设备对全市设备实行统一编码编码规则如下
格式十进制总长度9位其中前两位为字母并以H开头由平台服务商提供厂家的字母编号其余7位由设备厂商自行编码厂商完成设备编码后返回平台服务商进行备案。
HA 0000 170
设备编号
设备编号
厂家编码
厂家编码

Binary file not shown.

1
Waste.Doc/说明.txt Normal file
View File

@ -0,0 +1 @@
https://www.yuque.com/books/share/66e81f53-2084-4fc6-8ddc-740fc63dac91/yqpkhw#cf3e2664

View File

@ -0,0 +1,102 @@
@page
@model Waste.Web.Entry.Pages.Socket.TestModel
@{
}
<div class="layui-card">
<div class="layui-form layui-card-header layuiadmin-card-header-auto">
<div class="layui-form-item">
<div class="layui-inline">
<div class="layui-input-inline">
<input type="text" class="layui-input" name="Url" id="Url" value="wss://bright.ljflytjl.cn:9101/device_rpc" placeholder="请输入socket地址" />
</div>
</div>
<div class="layui-inline">
<button class="btn btn-primary btn-lg js-start" type="button">连接</button>
</div>
</div>
</div>
<div class="layui-card-body">
<div class="layui-form">
<div class="layui-form-item">
<div class="layui-inline">
<div class="layui-input-inline">
<input type="text" class="layui-input" id="Content" placeholder="请输入发送内容" />
</div>
</div>
<div class="layui-inline">
<button class="btn btn-primary btn-lg js-send" type="button">发送</button>
</div>
</div>
</div>
<div class="layui-form">
<div id="div_receive"></div>
</div>
</div>
</div>
@section Scripts{
<script type="text/javascript">
$(".js-start").on("click", function () {
initWebSocket();
});
$(".js-send").on("click", function () {
var val = $("#Content").val();
sendData("", val, "");
});
var webSocket;
//d:内容
function sendData(d) {
initWebSocket();
if (webSocket.OPEN && webSocket.readyState == 1) {
let time = new Date().getTime(); //1603009495724,精确到毫秒
var s = {
"type": 1,
"headers": {
"device": "08d92497-09cb-4d1d-8c47-44443caa6896",
"secret": "oWxxKZwwHvVxQhdE",
"time": time,
"os": 12,
"script": 2,
"baseProgrameLang": 109,
"dev": true
},
"invocationId": "Nil",
"target": "sayHello",
"arguments": [
"Hello Test Message"
]
};
var aa = JSON.stringify(s);
webSocket.send(aa);
}
if (webSocket.readyState == 2 || webSocket.readyState == 3) {
$("#div_receive").append("WebSocket closed");
}
}
function initWebSocket() {
var url = $("#Url").val();
if (!webSocket) {
webSocket = new WebSocket(url);
//Open connection handler.
webSocket.onopen = function () {
$("#div_receive").append("WebSocket opened" + "<br>");
};
//Message data handler.
webSocket.onmessage = function (e) {
$("#div_receive").append(e.data + "<br>");
};
//Close event handler.
webSocket.onclose = function () {
$("#div_receive").append("WebSocket closed." + "<br>");
};
//Error event handler.
webSocket.onerror = function (e) {
$("#div_receive").append(e.message + "<br>");
}
}
}
</script>
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Waste.Web.Entry.Pages.Socket
{
public class TestModel : PageModel
{
public void OnGet()
{
}
}
}