From 755e2893c12b79649ee12dec2b7d832d58b9265b Mon Sep 17 00:00:00 2001 From: 562935844@qq.com Date: 星期三, 18 十月 2023 16:19:26 +0800 Subject: [PATCH] 上报oid列表新增parentoid --- HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/AllTopicManagerUtils.java | 196 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 196 insertions(+), 0 deletions(-) diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/AllTopicManagerUtils.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/AllTopicManagerUtils.java new file mode 100644 index 0000000..1908d0a --- /dev/null +++ b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/AllTopicManagerUtils.java @@ -0,0 +1,196 @@ +package com.hdl.sdk.common.utils; + +import android.text.TextUtils; +import android.util.Base64; +import android.util.Log; + +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.common.config.TopicConstant; +import com.hdl.sdk.common.exception.HDLLinkException; +import com.hdl.sdk.common.utils.gson.GsonConvert; +import com.hdl.sdk.connect.HDLLink; +import com.hdl.sdk.connect.bean.LinkResponse; +import com.hdl.sdk.connect.bean.request.GatewayRemoteEditRequest; +import com.hdl.sdk.connect.bean.response.DeviceDeleteResponse; +import com.hdl.sdk.connect.bean.response.DeviceInfoResponse; +import com.hdl.sdk.connect.callback.HDLLinkCallBack; +import com.hdl.sdk.connect.config.HDLLinkConfig; +import com.hdl.sdk.connect.socket.HDLAuthSocket; +import com.hdl.sdk.connect.socket.HDLSocket; +import com.hdl.sdk.connect.utils.AesUtil; + +/** + * Created by hxb on 2023/9/14. + */ +public class AllTopicManagerUtils { + + /** + * 鍏ㄥ眬涓婚澶勭悊鏂规硶锛屽彲浠ュ鐞嗘墍鏈夋帴鏀跺埌鐨勬暟鎹� + * + * @param linkResponse + */ + public static void manager(LinkResponse linkResponse) { + try { + if (linkResponse == null) { + return; + } + String topic = linkResponse.getTopic(); + if (TextUtils.isEmpty(topic)) { + return; + } + String[] topics = topic.split("/"); + //闈炲綋鍓嶄綇瀹呯綉鍏崇殑鏁版嵁杩斿洖 + if (topics.length < 3) { + return; + } + + String mac_Oid_GatewayId = topics[2]; + + if (!isLocalDevice(mac_Oid_GatewayId)) { + LogUtils.i("涓嶆槸褰撳墠璁惧鐨勭綉鍏矷d锛孖d鏄�" + mac_Oid_GatewayId); + //闈炲綋鍓嶈澶囩殑鏁版嵁 + return; + } + + if (isSameTopic(TopicConstant.GATEWAY_EDIT_REMOTE, topic)) { + gatewayRemoteEditRequest(mac_Oid_GatewayId, linkResponse.getData()); + } else if (isSameTopic(TopicConstant.GATEWAY_SEARCH, topic)) { + HDLAuthSocket.getInstance().UploadGatewayInfo(null); + } else if (isSameTopic(TopicConstant.LINK_BROADCAST, topic)) { + managerLinkBroadcast(linkResponse.getData()); + } else if (isSameTopic(TopicConstant.DELETE_NOTIFY, topic)) { + managerDeleteNofity(linkResponse.getData()); + } + + } catch (Exception e) { + LogUtils.e("鍏ㄥ眬澶勭悊妯″潡寮傚父锛�" + e.getMessage()); + } + } + + /** + * 鏄惁褰撳墠鐨勮澶� + * + * @param mac_Oid_GatewayId + * @return + */ + private static boolean isLocalDevice(String mac_Oid_GatewayId) { + if (TextUtils.isEmpty(mac_Oid_GatewayId)) { + return false; + } + String mac = HDLLinkConfig.getInstance().getDeviceInfoBean().getDeviceMAC(); + String oid = HDLLinkConfig.getInstance().getDeviceInfoBean().getOID(); + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + String all = "all"; + + return mac_Oid_GatewayId.equals(mac) || mac_Oid_GatewayId.equals(oid) || mac_Oid_GatewayId.equals(gatewayId) || mac_Oid_GatewayId.toLowerCase().equals(all); + } + + /** + * 鏄惁鐩稿悓涓婚 + * + * @param targetTopic 鐩爣鐨勪富棰� + * @param sourceTopic 鎺ユ敹鐨勪富棰� + * @return + */ + private static boolean isSameTopic(String targetTopic, String sourceTopic) { + if (TextUtils.isEmpty(targetTopic) || TextUtils.isEmpty(sourceTopic)) { + return false; + } + String[] targetTopics = targetTopic.split("/"); + String[] sourceTopics = sourceTopic.split("/"); + + if (targetTopics.length != sourceTopics.length) { + return false; + } + for (int i = 0; i < targetTopics.length; i++) { + if (i == 2) { + //杩欎釜浣嶇疆涓嶅尮閰嶏紝鏄綉鍏砳d + continue; + } + if (!targetTopics[i].equals(sourceTopics[i])) { + return false; + } + } + return true; + } + + /** + * 缃戝叧淇℃伅閰嶇疆 + * + * @param body + */ + private static void gatewayRemoteEditRequest(String mac_Oid_GatewayId, String body) { + if (TextUtils.isEmpty(body)) { + return; + } + GatewayRemoteEditRequest gatewayRemoteEditRequest = GsonConvert.getGson().fromJson(body, new TypeToken<GatewayRemoteEditRequest>() { + }.getType()); + + if (gatewayRemoteEditRequest == null || gatewayRemoteEditRequest.getObjects() == null) { + return; + } + + String homeId = gatewayRemoteEditRequest.getObjects().getHomeId(); + HDLLinkConfig.getInstance().setHomeId(homeId); + + HDLSocket.getInstance().gatewayRemoteEditReply(mac_Oid_GatewayId, gatewayRemoteEditRequest.getId(), null); + } + + /** + * 鏇存柊瀵嗛挜 + * + * @param body + */ + private static void managerLinkBroadcast(String body) { + try { + DeviceInfoResponse deviceInfoResponse = GsonConvert.getGson().fromJson(body, new TypeToken<DeviceInfoResponse>() { + }.getType()); + + if (deviceInfoResponse == null || deviceInfoResponse.getObjects() == null) { + return; + } + if (!TextUtils.isEmpty(deviceInfoResponse.getObjects().getLocalSecret())) { + byte[] baseBytes = Base64.decode(deviceInfoResponse.getObjects().getLocalSecret(), Base64.NO_WRAP); + String mackey = ""; + if (!TextUtils.isEmpty(SPUtils.getString("auth_mackey_key", ""))) { + mackey = SPUtils.getString("auth_mackey_key", ""); + byte[] bodyBytes = AesUtil.aesDecrypt(baseBytes, mackey.substring(mackey.length() - 16)); + String localSecret = new String(bodyBytes, "utf-8"); + Log.d("panlili", "鏇存柊瀵嗛挜----->localSecret= " + localSecret); + HDLLinkConfig.getInstance().setLocalSecret(localSecret); + } + } + } catch (Exception e) { + LogUtils.i("LinkMessageDecoder.java:getLocalSecret----->e= " + e.getMessage()); + } + } + + /** + * 閫�缃� + * + * @param body + */ + private static void managerDeleteNofity(String body) { + try { + DeviceDeleteResponse deviceDeleteResponse = GsonConvert.getGson().fromJson(body, new TypeToken<DeviceDeleteResponse>() { + }.getType()); + + if (deviceDeleteResponse == null || deviceDeleteResponse.getObjects() == null) { + return; + } + HDLSocket.getInstance().deleteNetwork(deviceDeleteResponse.getObjects().get(0).getOID(), new HDLLinkCallBack() { + @Override + public void onSuccess(String msg) { + + } + + @Override + public void onError(HDLLinkException e) { + + } + }); + } catch (Exception e) { + LogUtils.i("LinkMessageDecoder.java:deleteNetwork----->e= " + e.getMessage()); + } + } +} \ No newline at end of file -- Gitblit v1.8.0