wjc
2025-05-07 b9cc7390e8e8ce64c41c26fb369c98ce669d660c
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;
@@ -67,6 +68,7 @@
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.NetworkUtils;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.hdl.photovoltaic.utils.WifiUtils;
import com.hdl.sdk.link.common.exception.HDLLinkException;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
@@ -148,7 +150,7 @@
            String type = getKeyValue("type", data);//小类
            String logTag = getKeyValue("logTag", data);//标记uni指令
            String mode_type = "大类-" + topic + "---" + "小类-" + type;//用来打印的
            HdlLogLogic.print(logTag + ":" + "uni---发送---" + mode_type + "\r\n" + data, true);
            HdlLogLogic.print(logTag + ":" + "uni---发送---" + mode_type + "---" + data, true);
            if (HDLUniMP.UNI_EVENT_REPLY_USER_MODEL.equals(topic)) {
                //用户模块
                switch (type) {
@@ -168,7 +170,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())) {
@@ -178,7 +180,7 @@
                        jsonObject.addProperty("appKey", AppConfigManage.getAppKey());
                        jsonObject.addProperty("appSecret", AppConfigManage.getAppSecret());
                        uniSuccessCallback(mode_type, jsonObject, callback);
                        HdlLogLogic.print("获取用户本地缓存信息---->>>" + jsonObject.toString());
                        HdlLogLogic.print("获取用户本地缓存信息----" + jsonObject.toString());
                    }
                    break;
                }
@@ -387,6 +389,14 @@
                WifiUtils wifiUtils = WifiUtils.getInstance();
                //wifi模块
                switch (type) {
                    //获取位置权限
                    case HDLUniMP.UNI_EVENT_REPLY_AUTHORIZATION_GET: {
                        boolean isLocalAuthor = PermissionUtils.checkPermission(HDLApp.getInstance(), Manifest.permission.ACCESS_FINE_LOCATION);
                        if (callback != null) {
                            uniSuccessCallback(mode_type, isLocalAuthor, callback);
                        }
                    }
                    break;
                    //获取手机wifi列表
                    case HDLUniMP.UNI_EVENT_REPLY_PHONE_WIFI_LIST: {
                        if (callback != null) {
@@ -437,10 +447,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;
@@ -648,6 +655,7 @@
            } else if (HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL.equals(topic)) {
                //其它模块
                switch (type) {
                    //获取温度单位
                    case HDLUniMP.UNI_EVENT_REPLY_OTHER_UNIT: {
                        uniSuccessCallback(mode_type, UserConfigManage.getInstance().getTemperature_unit(), callback);
@@ -686,6 +694,7 @@
                    break;
                    //uni通知原生退出登录
                    case HDLUniMP.UNI_EVENT_REPLY_OTHER_LOGOUT: {
                        HdlLogLogic.print("uni通知原生退出登录---", true);
                        HDLLinkPMUser.getInstance().logout(0);
                    }
                    break;
@@ -724,19 +733,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 +791,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) {
@@ -889,7 +916,7 @@
                if (callback != null) {
                    uniSuccessCallback(type, null, callback);
                }
                List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId);
                List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null);
                for (int i = 0; i < list.size(); i++) {
                    GatewayBean gatewayBean = list.get(i);
                    HdlDeviceLogic.getInstance().initializeInverter(gatewayBean.getDevice_mac(), null);
@@ -1294,11 +1321,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
@@ -1991,7 +2027,7 @@
                            UserConfigManage.getInstance().setBingEmail(cUserInfo.getMemberEmail());
                            UserConfigManage.getInstance().setUserImageUrl(cUserInfo.getMemberHeadIcon());
                            UserConfigManage.getInstance().Save();
                            HdlLogLogic.print("头像路径---->>>" + cUserInfo.getMemberHeadIcon());
                            HdlLogLogic.print("头像路径----" + cUserInfo.getMemberHeadIcon());
                        }
                        @Override
@@ -2373,6 +2409,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 +2869,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 +2915,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);