562935844@qq.com
2023-08-31 b77dc026ffd21dba8652d28409c51e27d3e5a76c
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java
@@ -15,6 +15,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,8 +28,9 @@
import com.hdl.sdk.socket.codec.ByteToMessageDecoder;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import android.util.Base64;
import kotlin.ParameterName;
@@ -181,7 +183,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 +215,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 +242,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) {