562935844@qq.com
2022-09-23 830e47a67026205b75f69e061d81783aa606a237
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java
@@ -1,16 +1,13 @@
package com.hdl.sdk.connect.bean;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.hdl.sdk.common.config.AuthenticateConfig;
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.AESUtils;
import com.hdl.sdk.connect.utils.AesUtil;
import java.io.UnsupportedEncodingException;
//import com.hdl.sdk.connect.utils.AesUtil;
/**
 * Created by Tong on 2021/9/29.
@@ -59,7 +56,6 @@
        this.length = length;
    }
    @NonNull
    @Override
    public String toString() {
        return "Topic:" +
@@ -72,8 +68,7 @@
    }
    private int getBytesLength(String str){
    private int getBytesLength(String str) {
        return ByteUtils.stringToBytes(str).length;
    }
@@ -86,17 +81,19 @@
    public byte[] getSendBytes() {
        try {
            //判断是否需要加密
            if (AuthenticateConfig.getInstance().ifNeedEncrypt(topic)) {
            if (HDLLinkConfig.getInstance().ifNeedEncrypt(topic)) {
                //需要加密
                byte[] dataBytes = AesUtil.aesEncrypt(ByteUtils.stringToBytes(data), AuthenticateConfig.getInstance().getLocalSecret());
//                byte[] dataBytes = AESUtils.encryptAES(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[] 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) {