562935844@qq.com
2023-09-12 adba037d593cae303557bb686025b8ccc3bdf418
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java
@@ -5,7 +5,6 @@
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.RequiresApi;
import com.google.gson.reflect.TypeToken;
import com.hdl.sdk.common.config.TopicConstant;
@@ -15,6 +14,7 @@
import com.hdl.sdk.common.utils.LogUtils;
import com.hdl.sdk.common.utils.SPUtils;
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.AuthenticateRequest;
import com.hdl.sdk.connect.bean.response.DeviceDeleteResponse;
@@ -27,10 +27,10 @@
import com.hdl.sdk.socket.codec.ByteToMessageDecoder;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import kotlin.ParameterName;
import android.util.Base64;
/**
 * Created by Tong on 2021/9/22.
@@ -129,7 +129,7 @@
    }
    @RequiresApi(api = Build.VERSION_CODES.O)
//    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected synchronized LinkResponse decoder(Object msg, String ipaddress) throws Exception {
        if (msg instanceof byte[]) {
@@ -181,7 +181,7 @@
                            //之前的版本这块是明文的
                            if (!topic.contains("heartbeat_reply")) {
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
                                    LogUtils.e("解密失败,数据内容是:\r\n" + Base64.getEncoder().encodeToString(body));
                                    LogUtils.e("解密失败,数据内容是:\r\n" + Base64.encodeToString(body, Base64.NO_WRAP));
                                else {
                                    LogUtils.e("解密失败,数据内容是:\r\n" + new String(body, "utf-8"));
                                }
@@ -213,18 +213,19 @@
                            LogUtils.i("UploadGatewayInfo onError");
                        }
                    });
                } else if (response.getTopic().equals(updateLocalSecret)) {
                } else if (response.getTopic().equals(updateLocalSecret) || response.getTopic().equals(TopicConstant.LINK_BROADCAST)) {
                    try {
                        DeviceInfoResponse deviceInfoResponse = GsonConvert.getGson().fromJson(response.getData(), new TypeToken<DeviceInfoResponse>() {
                        }.getType());
                        if (!TextUtils.isEmpty(deviceInfoResponse.getObjects().getLocalSecret())) {
                            byte[] baseBytes = Base64.getDecoder().decode(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);
                            }
                        }
@@ -239,11 +240,17 @@
                            @Override
                            public void onSuccess(String msg) {
                                LogUtils.i("deleteNetwork onSucceed");
                                if (HDLLink.getInstance().listener != null) {
                                    HDLLink.getInstance().listener.onSuccess(msg);
                                }
                            }
                            @Override
                            public void onError(HDLLinkException e) {
                                LogUtils.i("deleteNetwork onError");
                                if (HDLLink.getInstance().listener != null) {
                                    HDLLink.getInstance().listener.onFailure();
                                }
                            }
                        });
                    } catch (Exception e) {