完善逻辑
parent
97da9f0abb
commit
2828c209a1
|
|
@ -88,7 +88,14 @@ public class DeviceStatusHandler {
|
|||
*/
|
||||
public void handle(String topic, String payload) {
|
||||
|
||||
if (!isJsonObjectLike(payload)) return;
|
||||
// log.info("【设备处理】JSON解析:{}",payloadObj);
|
||||
// 解析设备ID:主题格式为dtu/{deviceId}/up,分割后第2个元素是设备ID
|
||||
String deviceId = extractDeviceId(topic);
|
||||
if (deviceId == null) return;
|
||||
String[] segments = topic.split("/");
|
||||
String action = segments[2];
|
||||
if ("down".equals(action) || !isJsonObjectLike(payload)) return;
|
||||
|
||||
// 第一步:解析JSON,非有效JSON直接return
|
||||
JSONObject payloadObj;
|
||||
try {
|
||||
|
|
@ -102,13 +109,6 @@ public class DeviceStatusHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
// log.info("【设备处理】JSON解析:{}",payloadObj);
|
||||
// 解析设备ID:主题格式为dtu/{deviceId}/up,分割后第2个元素是设备ID
|
||||
String deviceId = extractDeviceId(topic);
|
||||
if (deviceId == null) return;
|
||||
|
||||
String[] segments = topic.split("/");
|
||||
String action = segments[2];
|
||||
// 转发消息
|
||||
forwardPayload(deviceId, payload,payloadObj,action);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue