hxb
2022-02-17 af2cbc2a24b3724e7fc3e6b42e134b21a3144c75
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java
@@ -1,6 +1,7 @@
package com.hdl.sdk.connect.protocol;
import android.annotation.TargetApi;
import android.os.Build;
import android.util.Log;
@@ -116,7 +117,7 @@
        }
    }
    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected synchronized LinkResponse decoder(Object msg) throws Exception {
        if (msg instanceof byte[]) {
@@ -164,19 +165,24 @@
                        body = bodyBytes;
                    } else {
                        try {
                            LogUtils.e("解密失败,数据内容是:\r\n" + Base64.getEncoder().encodeToString(body));
                            LogUtils.e("解密失败,数据内容是:\r\n");
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
                                LogUtils.e(Base64.getEncoder().encodeToString(body));
                            else {
                                LogUtils.e(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("["))) {
                    continue;
                }
                response.setData(bodyString);
                LogUtils.i( "LinkMessageDecoder->decoder:" + response.getTopic() + "\r\n" + response.getData());
                //解析完成,topic发送一次
                EventDispatcher.getInstance().post(response.getTopic(), response);
            }