From 68d9078b49cfa8e83ed553835b05d4042c183969 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期四, 16 三月 2023 09:39:34 +0800 Subject: [PATCH] 云台不显示问题修复,LC问题 --- AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java | 42 +++++++++++++++++++++++++++++++++--------- 1 files changed, 33 insertions(+), 9 deletions(-) diff --git a/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java b/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java index 444c507..1af77fd 100644 --- a/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java +++ b/AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java @@ -1,5 +1,6 @@ package com.mm.android.deviceaddmodule.openapi; +import android.content.Intent; import android.text.TextUtils; import com.google.gson.Gson; @@ -7,12 +8,14 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; +import hdl.onpro.HdlData; import com.mm.android.deviceaddmodule.LCDeviceEngine; import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException; import com.mm.android.deviceaddmodule.mobilecommon.utils.LogUtil; import com.mm.android.deviceaddmodule.mobilecommon.utils.MD5Helper; import org.apache.http.conn.ConnectTimeoutException; +import org.greenrobot.eventbus.EventBus; import org.json.JSONObject; import java.io.IOException; @@ -35,7 +38,11 @@ Map<String, Object> map = paramsInit(paramsMap); JsonObject jsonResult = null; if (CONST.isHdlServer()) { - jsonResult = doPost(CONST.HOST + "/home-wisdom/imou/openapi/" + method, map, timeOut); + if (method.equals("bindDevice")) { + jsonResult = doPost(CONST.HOST + "/home-wisdom/app/device/independentRegister", map, timeOut); + } else { + jsonResult = doPost(CONST.HOST + "/home-wisdom/imou/openapi/" + method, map, timeOut); + } } else { jsonResult = doPost(CONST.HOST + "/openapi/" + method, map, timeOut); if (jsonResult == null) { @@ -49,29 +56,41 @@ } String code = jsonResult.get("code").getAsString(); if (!"0".equals(code)) { - String msg = jsonResult.get("msg").getAsString(); - throw new BusinessException(code + msg); + try { + String msg = jsonResult.get("msg").getAsString(); + EventBus.getDefault().post("InterfaceException"); + hdl.onpro.HdlData.getInstance().getiRegisterDeviceFeedback().feedback(method,jsonResult.toString()); + throw new BusinessException(code + msg); + }catch (Exception exception){ + String msg = jsonResult.get("message").getAsString(); + EventBus.getDefault().post("InterfaceException"); + hdl.onpro.HdlData.getInstance().getiRegisterDeviceFeedback().feedback(method,jsonResult.toString()); + throw new BusinessException(code + msg); + } } + + JsonObject jsonData = new JsonObject(); try { - JsonObject jsonData = jsonResult.getAsJsonObject("data"); + jsonData = jsonResult.getAsJsonObject("data"); if (jsonData == null) { jsonData = new JsonObject(); } - return jsonData; + } catch (Throwable e) { - BusinessException businessException = new BusinessException(e); - throw businessException; +// BusinessException businessException = new BusinessException(e); +// throw businessException; } + return jsonData; } private static JsonObject doPost(String url, Map<String, Object> map, int timeOut) throws BusinessException { Gson gson = new Gson(); - map.put("homeId", LCDeviceEngine.newInstance().getHomeId()); String json; JsonObject jsonObject; if(CONST.isHdlServer()) { + map.put("homeId", LCDeviceEngine.newInstance().getHomeId()); if (map.containsKey("params")) { Map<String, Object> tempMap = (Map<String, Object>) map.get("params"); map.remove("params"); @@ -98,7 +117,12 @@ try { LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json); String openApi = HttpClient.post(url, json, "application/json", "OpenApi",timeOut); - jsonObject = new JsonParser().parse(openApi).getAsJsonObject(); + LogUtil.debugLog(TAG, "杩斿洖缁撴灉: \r\n" + openApi); + try { + jsonObject = new JsonParser().parse(openApi).getAsJsonObject(); + }catch (Exception exception){ + jsonObject = new Gson().fromJson(openApi,JsonObject.class); + } } catch (IOException e) { BusinessException b = new BusinessException(e); if (e instanceof ConnectTimeoutException || e instanceof SocketTimeoutException -- Gitblit v1.8.0