|
|
|
@ -0,0 +1,164 @@
|
|
|
|
|
using Infrastructure.CloudSdk.mqttmessagecenter;
|
|
|
|
|
using OpenAuth.App.ServiceApp;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
{
|
|
|
|
|
public class ThingRequestHandler : IMqttMessageHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<ThingRequestHandler> _logger;
|
|
|
|
|
private readonly MqttClientManager _mqttClientManager;
|
|
|
|
|
AirportMaintenanceApp _app;
|
|
|
|
|
|
|
|
|
|
public ThingRequestHandler(ILogger<ThingRequestHandler> logger, MqttClientManager mqttClientManager, AirportMaintenanceApp app)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_mqttClientManager = mqttClientManager;
|
|
|
|
|
_app = app;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanHandle(string topic)
|
|
|
|
|
{
|
|
|
|
|
return topic.Contains("/requests");
|
|
|
|
|
}
|
|
|
|
|
string bid, tid, previousgateway;
|
|
|
|
|
int timestamp;
|
|
|
|
|
public async Task HandleAsync(string topic, string payload)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"[Request] Topic={topic}, Payload={payload}");
|
|
|
|
|
if (payload.Contains("config"))
|
|
|
|
|
{
|
|
|
|
|
var root = JsonNode.Parse(payload)?.AsObject();
|
|
|
|
|
if (root == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string gateway = root["gateway"]?.ToString() ?? "";
|
|
|
|
|
if (previousgateway == gateway)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bid = root["bid"]?.ToString() ?? "";
|
|
|
|
|
tid = root["tid"]?.ToString() ?? "";
|
|
|
|
|
timestamp = int.Parse(root["timestamp"]?.ToString() ?? "0");
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = bid,
|
|
|
|
|
method = "config",
|
|
|
|
|
tid = tid,
|
|
|
|
|
timestamp = timestamp,
|
|
|
|
|
gateway = gateway,
|
|
|
|
|
data = new
|
|
|
|
|
{
|
|
|
|
|
app_id = "164821",
|
|
|
|
|
app_key = "a5f80db847b285fd5fe51db7aa9f606",
|
|
|
|
|
app_license = "QXJX7VKLC03wYHujKbchjqIBiSgpjv46hLGY4B9Ez46RllbKZN9H+rVawveJWbbX/l4r6zPM5aZ/EzmCESUg046rSRziVhDOJ0tPw1cWqKAq6TuqaLK5bH88UFyB3ahv66YF3D/NmAgOfj5VRtT55cc67u/OIsF54lxhs/raAv0=",
|
|
|
|
|
ntp_server_host = "ntp.aliyun.com",
|
|
|
|
|
//ntp_server_host = "175.27.168.120",
|
|
|
|
|
//ntp_server_port = 6012
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{gateway}/requests_reply", payloadreq);
|
|
|
|
|
await _app.UpdateCodeStatus(gateway);
|
|
|
|
|
}
|
|
|
|
|
if (payload.Contains("airport_bind_status"))
|
|
|
|
|
{
|
|
|
|
|
//解析返回的设备sn 先不解析,先测试绑定
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = Guid.NewGuid().ToString(),
|
|
|
|
|
data = new
|
|
|
|
|
{
|
|
|
|
|
output = new
|
|
|
|
|
{
|
|
|
|
|
bind_status = new[]
|
|
|
|
|
{
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
device_callsign = "山东慧创",
|
|
|
|
|
is_device_bind_organization = true,
|
|
|
|
|
organization_id = "379",
|
|
|
|
|
organization_name = "山东慧创",
|
|
|
|
|
sn = "8UUXN5400A079H"
|
|
|
|
|
},
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
device_callsign = "山东慧创",
|
|
|
|
|
is_device_bind_organization = true,
|
|
|
|
|
organization_id = "379",
|
|
|
|
|
organization_name = "山东慧创",
|
|
|
|
|
sn = "1581F8HGX254V00A0BUY"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
result = 0
|
|
|
|
|
},
|
|
|
|
|
tid = Guid.NewGuid().ToString(),
|
|
|
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
|
method = "airport_bind_status"
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
string getway = topic.Split('/')[2];
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests_reply", payloadreq);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (payload.Contains("airport_organization_get"))
|
|
|
|
|
{
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = Guid.NewGuid().ToString(),
|
|
|
|
|
data = new
|
|
|
|
|
{
|
|
|
|
|
output = new
|
|
|
|
|
{
|
|
|
|
|
organization_name = "山东慧创"
|
|
|
|
|
},
|
|
|
|
|
result = 0
|
|
|
|
|
},
|
|
|
|
|
tid = Guid.NewGuid().ToString(),
|
|
|
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
|
method = "airport_organization_get"
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
string getway = topic.Split('/')[2];
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests_reply", payloadreq);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (payload.Contains("airport_organization_bind"))
|
|
|
|
|
{
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = Guid.NewGuid().ToString(),
|
|
|
|
|
data = new
|
|
|
|
|
{
|
|
|
|
|
output = new
|
|
|
|
|
{
|
|
|
|
|
err_infos = new[]
|
|
|
|
|
{
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
err_code = 210231,
|
|
|
|
|
sn = "8UUXN5400A079H"
|
|
|
|
|
},
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
err_code = 210231,
|
|
|
|
|
sn = "1581F8HGX254V00A0BUY"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
result = 0
|
|
|
|
|
},
|
|
|
|
|
tid = Guid.NewGuid().ToString(),
|
|
|
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
|
method = "airport_organization_bind"
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
string getway = topic.Split('/')[2];
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests_reply", payloadreq);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|