JLChen
2021-12-13 e7b8a808c2274e9c4329092bb752c7ea5cb035fc
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java
@@ -178,30 +178,39 @@
        String requestStr = gs.toJson(request);
        LinkRequest message = new LinkRequest(topic, requestStr);
        HdlSocketHelper.sendUdp(getUdpBoot(), ip, UDP_PORT, message,new HdlSocketHelper.HdlSocketListener() {
        HdlSocketHelper.sendUdp(getUdpBoot(), ip, UDP_PORT, message, new HdlSocketHelper.HdlSocketListener() {
            @Override
            public void onSucceed(Object msg) {
                if (callBack == null) return;
                try {
                    AuthenticateResponse bean = getAuthenticateResponseBean(msg);
                    if (bean != null) {
                        String localSecret = "";
                        String gatewayId = "";
                        String ipAddress = "";
                        if (bean.getAuth() != null) {
                            localSecret = bean.getAuth().getLocalSecret();
                        }
                        if (bean.getObjects() != null) {
                            gatewayId = bean.getObjects().getGatewayID();
                            ipAddress = bean.getObjects().getIPAddress();
                        }
                        //判断网关是否已经注册到云端
                        if (TextUtils.isEmpty(localSecret) || TextUtils.isEmpty(gatewayId)) {
                            //认证失败,网关未注册到云端
                            callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED));
                        } else {
                            HDLLinkConfig.getInstance().saveConfig(localSecret, gatewayId, ipAddress);
                            callBack.onSuccess("认证成功");
                        if (bean.getCode().equals("200")) {
                            String localSecret = "";
                            String gatewayId = "";
                            String ipAddress = "";
                            if (bean.getAuth() != null) {
                                localSecret = bean.getAuth().getLocalSecret();
                            }
                            if (bean.getObjects() != null) {
                                gatewayId = bean.getObjects().getGatewayID();
                                ipAddress = bean.getObjects().getIPAddress();
                            }
                            //判断网关是否已经注册到云端
                            if (TextUtils.isEmpty(localSecret) || TextUtils.isEmpty(gatewayId)) {
                                //认证失败,网关未注册到云端
                                callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED));
                            } else {
                                HDLLinkConfig.getInstance().saveConfig(localSecret, gatewayId, ipAddress);
                                callBack.onSuccess("认证成功");
                            }
                        } else if (bean.getCode().equals("14013")){
                            //认证失败,该MAC对应的设备密钥不存在
                            callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_MAC_KEY_ERROR_));
                        } else{
                            //认证失败,错误码:
                            LogUtils.e("认证失败,错误码:" + bean.getCode());
                            callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_ERROR));
                        }
                    } else {
                        callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_ERROR));