From 30e96788f05f5ce28b58d991051c79e9c952c824 Mon Sep 17 00:00:00 2001 From: 562935844@qq.com Date: 星期三, 28 十二月 2022 14:51:34 +0800 Subject: [PATCH] 修改入网认证流程 --- HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java | 32 ++++++++++++++++++-------------- 1 files changed, 18 insertions(+), 14 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 0d20188..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 @@ -2,18 +2,13 @@ import android.os.Build; -import android.util.Log; -import androidx.annotation.RequiresApi; - -import com.google.gson.internal.bind.DateTypeAdapter; -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; @@ -110,15 +105,15 @@ } list.clear(); - for(int i=0;i<tempList.size();i++){ + for (int i = 0; i < tempList.size(); i++) { list.add(tempList.get(i)); } } } - @RequiresApi(api = Build.VERSION_CODES.O) + @Override - protected synchronized 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)); //濡傛灉澶氭潯鍛戒护鎵撳寘鍦ㄤ竴鏉℃暟鎹腑锛岄兘闇�瑕佸鐞嗗畬 @@ -156,6 +151,7 @@ bytes.add(recevieBytes[i]); } LinkResponse response = new LinkResponse(); + response.setSource_ipAddress(ipaddress); response.setTopic(topic); if (HDLLinkConfig.getInstance().ifNeedEncrypt(response.getTopic())) { //闇�瑕佽В瀵� @@ -164,19 +160,27 @@ body = bodyBytes; } else { try { - LogUtils.e("瑙e瘑澶辫触锛屾暟鎹唴瀹规槸锛歕r\n" + Base64.getEncoder().encodeToString(body)); + //涔嬪墠鐨勭増鏈繖鍧楁槸鏄庢枃鐨� + 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) { } } } String bodyString = new String(body, "utf-8"); + response.setData(bodyString); + LogUtils.i("鎺ユ敹鍒版暟鎹�:" + response.getTopic() + "\r\n" + response.getData()); //闈炴甯告暟鎹紝杩斿洖 - if (!(bodyString.startsWith("{") || bodyString.startsWith("["))) { + if (!((bodyString.startsWith("{") && bodyString.endsWith("}")) + || (bodyString.startsWith("[") && bodyString.endsWith("]")))) { continue; } - response.setData(bodyString); - LogUtils.i( "LinkMessageDecoder->decoder:" + response.getTopic() + "\r\n" + response.getData()); //瑙f瀽瀹屾垚,topic鍙戦�佷竴娆� EventDispatcher.getInstance().post(response.getTopic(), response); } -- Gitblit v1.8.0