From 8adb5e06a5fcfad9a634944c0d65fc70c5c2527f Mon Sep 17 00:00:00 2001 From: Tong <1025782220@qq.com> Date: 星期二, 19 四月 2022 10:12:57 +0800 Subject: [PATCH] 去掉依赖库 --- HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java | 46 ++++++++++++++++++++++++++++++---------------- 1 files changed, 30 insertions(+), 16 deletions(-) diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java index dc3afa8..20df34d 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java +++ b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java @@ -1,18 +1,18 @@ package com.hdl.sdk.connect.protocol; -import android.util.Log; +import android.os.Build; -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.connect.config.HDLLinkConfig; import com.hdl.sdk.common.event.EventDispatcher; import com.hdl.sdk.common.utils.ByteUtils; +import com.hdl.sdk.common.utils.LogUtils; import com.hdl.sdk.connect.bean.LinkResponse; +import com.hdl.sdk.connect.config.HDLLinkConfig; import com.hdl.sdk.connect.utils.AesUtil; -import com.hdl.sdk.connect.utils.ProtocolParse; import com.hdl.sdk.socket.codec.ByteToMessageDecoder; import java.util.ArrayList; +import java.util.Base64; import java.util.List; /** @@ -101,18 +101,19 @@ if (0 < index && isMatch) { List<Byte> tempList = new ArrayList<Byte>(); for (int i = index; i < list.size(); i++) { - tempList.add(list.get(index)); + tempList.add(list.get(i)); } list.clear(); - for(int i=0;i<tempList.size();i++){ + for (int i = 0; i < tempList.size(); i++) { list.add(tempList.get(i)); } } } + @Override - protected LinkResponse decoder(Object msg) throws Exception { + protected synchronized LinkResponse decoder(Object msg, String ipaddress) throws Exception { if (msg instanceof byte[]) { bytes.addAll(ByteUtils.toByteList((byte[]) msg)); //濡傛灉澶氭潯鍛戒护鎵撳寘鍦ㄤ竴鏉℃暟鎹腑锛岄兘闇�瑕佸鐞嗗畬 @@ -150,23 +151,36 @@ bytes.add(recevieBytes[i]); } LinkResponse response = new LinkResponse(); + response.setSource_ipAddress(ipaddress); response.setTopic(topic); if (HDLLinkConfig.getInstance().ifNeedEncrypt(response.getTopic())) { //闇�瑕佽В瀵� byte[] bodyBytes = AesUtil.aesDecrypt(body, HDLLinkConfig.getInstance().getLocalSecret()); -// byte[] bodyBytes = AESUtils.decryptAES(body,AuthenticateConfig.getInstance().getLocalSecret()); if (bodyBytes != null) { - response.setData(new String(bodyBytes, "utf-8")); -// LogUtils.i("TAG", "瑙e瘑 涓婚锛�"+response.getTopic()+ " body: "+response.getData()); + body = bodyBytes; } else { - //瑙e瘑澶辫触锛岃繑鍥炲師鏁版嵁 - response.setData(new String(body, "utf-8")); + try { + //涔嬪墠鐨勭増鏈繖鍧楁槸鏄庢枃鐨� + if (!topic.contains("heartbeat_reply")) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + LogUtils.e("瑙e瘑澶辫触锛屾暟鎹唴瀹规槸锛歕r\n" + Base64.getEncoder().encodeToString(body)); + else { + LogUtils.e("瑙e瘑澶辫触锛屾暟鎹唴瀹规槸锛歕r\n" + new String(body, "utf-8")); + } + } + } catch (Exception e) { + } } - - } else { - response.setData(new String(body, "utf-8")); } - Log.i("TAG", "LinkMessageDecoder->decoder:" + response.getTopic() + "\r\n" + response.getData()); + + String bodyString = new String(body, "utf-8"); + response.setData(bodyString); + LogUtils.i("鎺ユ敹鍒版暟鎹�:" + response.getTopic() + "\r\n" + response.getData()); + //闈炴甯告暟鎹紝杩斿洖 + if (!((bodyString.startsWith("{") && bodyString.endsWith("}")) + || (bodyString.startsWith("[") && bodyString.endsWith("]")))) { + continue; + } //瑙f瀽瀹屾垚,topic鍙戦�佷竴娆� EventDispatcher.getInstance().post(response.getTopic(), response); } -- Gitblit v1.8.0