wjc
2023-06-28 975b91521a04e159f45fb34fc7b55afbf455f7f5
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -5,11 +5,14 @@
import com.google.gson.Gson;
import com.hdl.photovoltaic.HDLApp;
import com.hdl.photovoltaic.bean.BaseEventBus;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.WifiUtils;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
@@ -52,9 +55,7 @@
            if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
                return;
            }
            String json = data == null ? "{}" : data.toString();
            json = json.equals("") ? "{}" : json;
            org.json.JSONObject jsonObject = new org.json.JSONObject(json);
            org.json.JSONObject jsonObject = getJSONObject(data);
            String type_value = "";
            if (jsonObject.has("type")) {
                type_value = jsonObject.getString("type");
@@ -65,7 +66,10 @@
                switch (type_value) {
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: {
                        //创建
                        HdlResidenceLogic.getInstance().getResidenceList("", "", null);
                        //eventbus通知
                        BaseEventBus baseEventBus = new BaseEventBus();
                        baseEventBus.setType(ConstantManage.EVENTBUS_POST_HOME_CREATED);
                        EventBus.getDefault().post(baseEventBus);
                    }
                    break;
@@ -127,7 +131,7 @@
    /**
     * 原生打开uni指定页面
     *
     * @param path       打开路径
     * @param path       打开全路径
     * @param jsonObject 附件数据(没有数据填null)
     */
    public void openUniMP(String path, JSONObject jsonObject) {
@@ -141,15 +145,16 @@
     * 原生【主动】向小程序发送通知事件
     * 注意:需要提前小程序在运行才可成功
     *
     * @param topic 主题
     * @param topic 主题大类
     * @param type  功能类
     * @param body  附件数据(没有数据填null)
     */
    public void sendUni(String topic, String body) {
    public void sendUni(String topic, String type, String body) {
        try {
            HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
            callBackBaseBean.setTopic(topic);
            callBackBaseBean.setType(type);
            callBackBaseBean.setData(body);
            HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_APP_ID, getJSONObject(callBackBaseBean));
            HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, topic, getJSONObject(callBackBaseBean));
        } catch (Exception e) {
            HdlLogLogic.print("uni===原生主动向小程序发送通知事件", e.getMessage());
        }
@@ -204,29 +209,13 @@
            uniCallBackBaseBean.setMes(msg);
            uniCallBackBaseBean.setData(obj);
            if (callback != null) {
                callback.invoke(uniCallBackBaseBean);
                callback.invoke(getJSONObject(uniCallBackBaseBean));
            }
        } catch (Exception e) {
            HdlLogLogic.print("uni===组装uni发送数据格式", e.getMessage());
        }
    }
    /**
     * 获取uni发送对象
     *
     * @param obj  附加数据
     * @param code 状态码
     * @param msg  结果描述的信息
     */
    private HDLUniMP.UniCallBackBaseBean getUniCallBackBaseBean(Object obj, String code, String msg) {
        HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
        uniCallBackBaseBean.setCode(code);
        uniCallBackBaseBean.setMes(msg);
        uniCallBackBaseBean.setData(obj);
        return uniCallBackBaseBean;
    }
    /**
@@ -236,6 +225,12 @@
     */
    private JSONObject getJSONObject(Object obj) {
        try {
            if (obj == null) {
                return new JSONObject();
            }
            if (TextUtils.isEmpty(obj.toString())) {
                return new JSONObject();
            }
            String json = new Gson().toJson(obj);
            return new JSONObject(json);
        } catch (Exception e) {