wjc
2023-06-28 99bc815e07e39354f51421b77f4012ffd35594d8
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -11,10 +11,15 @@
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.WifiUtils;
import com.hdl.sdk.link.common.exception.HDLLinkException;
import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
import com.hdl.sdk.link.core.callback.GatewayCallBack;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
import java.util.List;
import io.dcloud.feature.unimp.DCUniMPJSCallback;
@@ -57,8 +62,12 @@
            }
            org.json.JSONObject jsonObject = getJSONObject(data);
            String type_value = "";
            String oid = "";
            if (jsonObject.has("type")) {
                type_value = jsonObject.getString("type");
            }
            if (jsonObject.has("oid")) {
                oid = jsonObject.getString("oid");
            }
            if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) {
@@ -90,10 +99,28 @@
                    }
                    break;
                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: {
                        //获取设备列表
                        //网关搜索
                        HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
                            @Override
                            public void onSuccess(List<GatewayBean> gatewayBeanList) {
                                HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
                                callBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_LIST);
                                callBackBaseBean.setData(gatewayBeanList);
                                sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, callBackBaseBean);
                            }
                            @Override
                            public void onError(HDLLinkException e) {
                                //发送失败
                            }
                        });
                    }
                    break;
                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: {
                        //发送modbus协议
                    }
                }
            } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(event)) {
@@ -145,15 +172,11 @@
     * 原生【主动】向小程序发送通知事件
     * 注意:需要提前小程序在运行才可成功
     *
     * @param topic 主题大类
     * @param type  功能类
     * @param body  附件数据(没有数据填null)
     * @param topic            主题大类
     * @param callBackBaseBean _
     */
    public void sendUni(String topic, String type, String body) {
    public void sendUni(String topic, HDLUniMP.UniCallBackBaseBean callBackBaseBean) {
        try {
            HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
            callBackBaseBean.setType(type);
            callBackBaseBean.setData(body);
            HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, topic, getJSONObject(callBackBaseBean));
        } catch (Exception e) {
            HdlLogLogic.print("uni===原生主动向小程序发送通知事件", e.getMessage());
@@ -232,6 +255,7 @@
                return new JSONObject();
            }
            String json = new Gson().toJson(obj);
            return new JSONObject(json);
        } catch (Exception e) {
            return new JSONObject();