wjc
2025-04-15 cdf49871675e42a5576f725a93eec7ca15294c6f
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -9,6 +9,7 @@
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.net.wifi.ScanResult;
import android.os.IBinder;
import android.os.SystemClock;
import android.provider.Settings;
@@ -168,7 +169,7 @@
                        jsonObject.addProperty("user_name", UserConfigManage.getInstance().getUserName());
                        jsonObject.addProperty("user_image_url", UserConfigManage.getInstance().getUserImageUrl());
                        jsonObject.addProperty("user_account", UserConfigManage.getInstance().getAccount());
                        jsonObject.addProperty("appLanguage", UserConfigManage.getInstance().getCurrentAppLanguage());
                        jsonObject.addProperty("token", HDLLinkPMUser.getInstance().getAccessToken());
                        jsonObject.addProperty("refreshToken", HDLLinkPMUser.getInstance().getRefreshToken());
                        if (TextUtils.isEmpty(AppConfigManage.getUserRegionUrl())) {
@@ -437,10 +438,7 @@
                    break;
                    //逆变器以太网获取
                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ETHERNET_GET: {
                        if (callback != null) {
                            uniSuccessCallback(type, "", callback);
                        }
                        //uniGetAndSetNetwork(mode_type, data, TopicApi.DELETING_GATEWAY_ETHERNET_GET, callback);
                        uniGetAndSetNetwork(mode_type, data, TopicApi.DELETING_GATEWAY_ETHERNET_GET, callback);
                    }
                    break;
@@ -686,6 +684,7 @@
                    break;
                    //uni通知原生退出登录
                    case HDLUniMP.UNI_EVENT_REPLY_OTHER_LOGOUT: {
                        HdlLogLogic.print("uni通知原生退出登录--->", true);
                        HDLLinkPMUser.getInstance().logout(0);
                    }
                    break;
@@ -724,19 +723,21 @@
                    break;
                    //本地json资源文件获取
                    case HDLUniMP.UNI_EVENT_REPLY_OTHER_GET_LOCAL_JSON: {
                        String url = getKeyValue("url", getKeyValue("data", data));
                        String deviceModel = getKeyValue("deviceModel", getKeyValue("data", data));
//                      String url = getKeyValue("url", getKeyValue("data", data));
                        String fileName = getKeyValue("fileName", getKeyValue("data", data));//唯一标识
                        String deviceType = getKeyValue("deviceType", getKeyValue("data", data));//设备类型
                        String deviceModel = getKeyValue("deviceModel", getKeyValue("data", data));//设备模型
                        String language = getKeyValue("language", getKeyValue("data", data));
                        String json = HdlESLocalJsonLogic.getInstance().readHdlESLocalJson(url, deviceModel);
                        String json = HdlESLocalJsonLogic.getInstance().readHdlESLocalJson(fileName + ".json", deviceModel);
                        if (TextUtils.isEmpty(json)) {
                            //本地没有缓存
                            HdlESLocalJsonLogic.getInstance().getHdlESLocalJson(url, deviceModel, new CloudCallBeak<String>() {
                            HdlESLocalJsonLogic.getInstance().getHdlESLocalJson(fileName, deviceType, deviceModel, false, new CloudCallBeak<String>() {
                                @Override
                                public void onSuccess(String obj) {
//                                    if (callback != null) {
//                                        uniSuccessCallback(type, obj, callback);
//                                    }
                                    String s = HdlESLocalJsonLogic.getInstance().readHdlESLocalJson(url, deviceModel);
                                    String s = HdlESLocalJsonLogic.getInstance().readHdlESLocalJson(fileName, deviceModel);
                                    //本地缓存数据
                                    if (callback != null) {
                                        try {
@@ -780,31 +781,47 @@
                        }
                    }
                    break;
                    //uni获取图片
                    case HDLUniMP.UNI_EVENT_REPLY_OTHER_GET_SELECTED_IMAGE: {
                    }
                    break;
                }
            } else if (HDLUniMP.UNI_EVENT_REPLY_COMMON_MODEL.equals(topic)) {
            } else if (HDLUniMP.UNI_EVENT_REPLY_UNI_SEND_TO_CLOUD.equals(topic)) {
                //网络请求模块
                if (type.equals(HDLUniMP.UNI_EVENT_REPLY_UNI_SEND_TO_CLOUD)) {
                    String url = getKeyValue("url", getKeyValue("data", data));
                    JsonObject jObject = new JsonObject();
                    String body = getKeyValue("body", getKeyValue("data", data));
                    if (!TextUtils.isEmpty(body)) {
                        try {
                            jObject = new Gson().fromJson(body, JsonObject.class);
                        } catch (Exception ignored) {
                JsonObject jObject = new JsonObject();
                String body = getKeyValue("data", data);
                if (!TextUtils.isEmpty(body)) {
                    try {
                        jObject = new Gson().fromJson(body, JsonObject.class);
                    } catch (Exception ignored) {
                    }
                }
                HttpClient.getInstance().requestHttp(type, jObject.toString(), new CloudCallBeak<String>() {
                    @Override
                    public void onSuccess(String jsonStr) {
                        //本地缓存数据
                        if (callback != null) {
                            try {
                                if (jsonStr.startsWith("{")) {
                                    uniSuccessCallback(mode_type, new Gson().fromJson(jsonStr, JsonObject.class), callback);
                                } else if (jsonStr.startsWith("[")) {
                                    uniSuccessCallback(mode_type, new Gson().fromJson(jsonStr, JsonArray.class), callback);
                                } else {
                                    uniSuccessCallback(mode_type, jsonStr, callback);
                                }
                            } catch (Exception e) {
                                uniSuccessCallback(mode_type, jsonStr, callback);
                            }
                        }
                    }
                    HttpClient.getInstance().requestHttp(url, jObject.toString(), new CloudCallBeak<String>() {
                        @Override
                        public void onSuccess(String jsonStr) {
                            uniSuccessCallback(mode_type, jsonStr, callback);
                        }
                        @Override
                        public void onFailure(HDLException e) {
                            uniExceptionCallback(mode_type, e, callback);
                        }
                    });
                }
                    @Override
                    public void onFailure(HDLException e) {
                        uniExceptionCallback(mode_type, e, callback);
                    }
                });
            }
        } catch (Exception e) {
@@ -1294,11 +1311,20 @@
        //解密负载数据(写密钥给网关一定是明文,因为那时网关还没有密钥)
        TcpClient.getInstance().sendDataToLinkGateway(mac, false, TopicApi, jsonArray, "", new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
            public void onSuccess(String s) {
                if (callback != null) {
                    uniSuccessCallback(type, msg, callback);
                    try {
                        if (s.startsWith("{")) {
                            uniSuccessCallback(type, new Gson().fromJson(s, JsonObject.class), callback);
                        } else if (s.startsWith("[")) {
                            uniSuccessCallback(type, new Gson().fromJson(s, JsonArray.class), callback);
                        } else {
                            uniSuccessCallback(type, s, callback);
                        }
                    } catch (Exception e) {
                        uniSuccessCallback(type, s, callback);
                    }
                }
            }
            @Override
@@ -2373,6 +2399,7 @@
     */
    private void uniGetCurrentHomeLocalAndCloudGatewayList(String type, Object data, DCUniMPJSCallback callback) {
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
//        UserConfigManage.getInstance().setHomeId(homeId);
        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(homeId, new CloudCallBeak<List<GatewayBean>>() {
            @Override
            public void onSuccess(List<GatewayBean> list) {
@@ -2832,17 +2859,18 @@
            if (data == null) {
                data = new JSONObject();
            }
            if (isTokenAndRefreshToken) {
                //小程序那里有自己的请求方法,但需要原生提供这些数据
                data.put("token", HDLLinkPMUser.getInstance().getAccessToken());
                data.put("refreshToken", HDLLinkPMUser.getInstance().getRefreshToken());
                if (TextUtils.isEmpty(AppConfigManage.getUserRegionUrl())) {
                    AppConfigManage.setUserRegionUrl(HDLLinkPMUser.getInstance().getUserRegionUrl());
                }
                data.put("serverAddress", AppConfigManage.getUserRegionUrl());
                data.put("appKey", AppConfigManage.getAppKey());
                data.put("appSecret", AppConfigManage.getAppSecret());
            }
//            if (isTokenAndRefreshToken) {
//                //小程序那里有自己的请求方法,但需要原生提供这些数据
//                data.put("token", HDLLinkPMUser.getInstance().getAccessToken());
//                data.put("refreshToken", HDLLinkPMUser.getInstance().getRefreshToken());
//                if (TextUtils.isEmpty(AppConfigManage.getUserRegionUrl())) {
//                    AppConfigManage.setUserRegionUrl(HDLLinkPMUser.getInstance().getUserRegionUrl());
//                }
//                data.put("serverAddress", AppConfigManage.getUserRegionUrl());
//                data.put("appKey", AppConfigManage.getAppKey());
//                data.put("appSecret", AppConfigManage.getAppSecret());
//            }
            data.put("appLanguage", UserConfigManage.getInstance().getCurrentAppLanguage());
            uniCallBackBaseBean.setData(data);
            return getJSONObject(uniCallBackBaseBean);
        } catch (Exception e) {
@@ -2877,8 +2905,7 @@
            uniCallBackBaseBean.setData(obj);
            if (callback != null) {
                callback.invoke(getJSONObject(uniCallBackBaseBean));
//                callback.invoke(uniCallBackBaseBean);
                HdlLogLogic.print("回复---uni---" + type + "---" + new Gson().toJson(uniCallBackBaseBean), true);
                HdlLogLogic.print("回复---uni---" + type + "---" + getJSONObject(uniCallBackBaseBean).toString(), true);
            }
        } catch (Exception e) {
            HdlLogLogic.print("回复---uni---" + type + "---" + e.getMessage(), true);