From 0fd690cf61ce8b954cd742fb790cd8c3cce18d6d Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期二, 03 一月 2023 17:31:02 +0800 Subject: [PATCH] 备份 --- AndroidOpenDemo/DeviceAddModule/src/main/java/com/mm/android/deviceaddmodule/openapi/HttpSend.java | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 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 12a46fc..59df71c 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 @@ -35,7 +35,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,19 +53,27 @@ } 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(); + throw new BusinessException(code + msg); + }catch (Exception exception){ + String msg = jsonResult.get("message").getAsString(); + 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; } @@ -99,7 +111,11 @@ LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json); String openApi = HttpClient.post(url, json, "application/json", "OpenApi",timeOut); LogUtil.debugLog(TAG, "杩斿洖缁撴灉: \r\n" + openApi); - jsonObject = new JsonParser().parse(openApi).getAsJsonObject(); + 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