From 2574334327d47d5b0d62e1e9fe442a493bbcf2bd Mon Sep 17 00:00:00 2001 From: 562935844@qq.com Date: 星期二, 11 四月 2023 15:52:54 +0800 Subject: [PATCH] 新增接收主机退网delete/notify主题处理 --- HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java | 56 ++++++++++++++++---------------------------------------- 1 files changed, 16 insertions(+), 40 deletions(-) diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java index 29b1941..8184536 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java +++ b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java @@ -1,18 +1,13 @@ package com.hdl.sdk.connect.bean; + import android.text.TextUtils; -import android.util.Log; -import androidx.annotation.NonNull; -import com.hdl.sdk.common.config.AuthenticateConfig; -import com.hdl.sdk.connect.utils.AESUtils; +import com.hdl.sdk.common.utils.LogUtils; +import com.hdl.sdk.connect.config.HDLLinkConfig; +import com.hdl.sdk.common.utils.ByteUtils; import com.hdl.sdk.connect.utils.AesUtil; - -import java.io.UnsupportedEncodingException; - -import static com.hdl.sdk.common.config.TopicConstant.DEIVCE_AUTH_REQUEST; -import static com.hdl.sdk.common.config.TopicConstant.GATEWAY_SEARCH; /** * Created by Tong on 2021/9/29. @@ -47,7 +42,6 @@ this.data = data; if (!TextUtils.isEmpty(data)) { setLength(getBytesLength(data)); -// setLength(data.length()); } else { setLength(0); } @@ -62,7 +56,6 @@ this.length = length; } - @NonNull @Override public String toString() { return "Topic:" + @@ -74,32 +67,12 @@ getData(); } - private static byte[] stringToBytes(String str) { - try { - // 浣跨敤鎸囧畾鐨勫瓧绗﹂泦灏嗘瀛楃涓茬紪鐮佷负byte搴忓垪骞跺瓨鍒颁竴涓猙yte鏁扮粍涓� - return str.getBytes("utf-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return new byte[]{}; + + private int getBytesLength(String str) { + return ByteUtils.stringToBytes(str).length; } - private int getBytesLength(String str){ - return stringToBytes(str).length; - } - /** - * 鍚堝苟鏁扮粍 - * @param bt1 - * @param bt2 - * @return - */ - public static byte[] byteMerger(byte[] bt1, byte[] bt2){ - byte[] bt3 = new byte[bt1.length + bt2.length]; - System.arraycopy(bt1, 0, bt3, 0, bt1.length); - System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length); - return bt3; - } /** * 鑾峰彇鍙戦�佹暟鎹産yte * @@ -108,16 +81,19 @@ public byte[] getSendBytes() { try { //鍒ゆ柇鏄惁闇�瑕佸姞瀵� - if (AuthenticateConfig.getInstance().ifNeedEncrypt(topic)) { + if (HDLLinkConfig.getInstance().ifNeedEncrypt(topic)) { //闇�瑕佸姞瀵� - byte[] dataBytes = AesUtil.aesEncrypt(stringToBytes(data), AuthenticateConfig.getInstance().getLocalSecret()); + byte[] dataBytes = AesUtil.aesEncrypt(ByteUtils.stringToBytes(data), HDLLinkConfig.getInstance().getLocalSecret()); String headString = "Topic:" + getTopic() + "\r\n" + "Length:" + dataBytes.length + "\r\n" + "\r\n"; -// byte[] headBytes = headString.getBytes("utf-8"); - byte[] headBytes = headString.getBytes(); - byte[] sendBytes = byteMerger(headBytes, dataBytes); + byte[] headBytes = headString.getBytes("utf-8"); + byte[] sendBytes = ByteUtils.concatBytes(headBytes, dataBytes); + LogUtils.i("鍙戦�佹暟鎹細\r\n" + headString + "\r\n" + data); return sendBytes; + } else { - return this.toString().getBytes("utf-8"); + String sendString = this.toString(); + LogUtils.i("鍙戦�佹暟鎹細\r\n" + sendString); + return sendString.getBytes("utf-8"); } } catch (Exception e) { -- Gitblit v1.8.0