| | |
| | | |
| | | import android.text.TextUtils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.google.gson.Gson; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.uni.UniToAndroidBean; |
| | | 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 com.hdl.sdk.link.core.connect.HDLModBusConnect; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | |
| | | if (!HDLUniMP.UNI_APP_ID.equals(appId)) { |
| | | return; |
| | | } |
| | | org.json.JSONObject jsonObject = getJSONObject(data); |
| | | String type_value = ""; |
| | | if (jsonObject.has("type")) { |
| | | type_value = jsonObject.getString("type"); |
| | | } |
| | | UniToAndroidBean uniToAndroidBean = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(data), UniToAndroidBean.class); |
| | | |
| | | if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) { |
| | | //住宅模块 |
| | | switch (type_value) { |
| | | switch (uniToAndroidBean.getType()) { |
| | | case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: { |
| | | //创建 |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | |
| | | } |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(event)) { |
| | | //设备模块 |
| | | switch (type_value) { |
| | | switch (uniToAndroidBean.getType()) { |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: { |
| | | //添加 |
| | | } |
| | | 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.setTopic(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL); |
| | | callBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_LIST); |
| | | callBackBaseBean.setData(gatewayBeanList); |
| | | sendUni(callBackBaseBean); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | //发送失败 |
| | | } |
| | | }); |
| | | } |
| | | break; |
| | | |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND:{ |
| | | //发送modbus协议 |
| | | HDLModBusConnect.getInstance().Send(uniToAndroidBean.getGatewayOid(),null,); |
| | | } |
| | | } |
| | | |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(event)) { |
| | | WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance()); |
| | | //wifi模块 |
| | | switch (type_value) { |
| | | switch (uniToAndroidBean.getType()) { |
| | | case HDLUniMP.UNI_EVENT_REPLY_WIFI_LIST: { |
| | | //获取wifi列表 |
| | | if (callback != null) { |
| | |
| | | /** |
| | | * 原生【主动】向小程序发送通知事件 |
| | | * 注意:需要提前小程序在运行才可成功 |
| | | * |
| | | * @param topic 主题 |
| | | * @param body 附件数据(没有数据填null) |
| | | */ |
| | | public void sendUni(String topic, String body) { |
| | | public void sendUni(HDLUniMP.UniCallBackBaseBean callBackBaseBean) { |
| | | try { |
| | | HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); |
| | | callBackBaseBean.setTopic(topic); |
| | | callBackBaseBean.setData(body); |
| | | HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_APP_ID, getJSONObject(callBackBaseBean)); |
| | | } catch (Exception e) { |
| | | HdlLogLogic.print("uni===原生主动向小程序发送通知事件", e.getMessage()); |
| | |
| | | return new JSONObject(); |
| | | } |
| | | String json = new Gson().toJson(obj); |
| | | |
| | | return new JSONObject(json); |
| | | } catch (Exception e) { |
| | | return new JSONObject(); |