|
|
@@ -28,9 +28,9 @@ import com.wxxcx.ws.PushMsgWebSocket;
|
|
|
|
|
|
@Slf4j
|
|
|
public class MqttUtil {
|
|
|
- // private static String HOST = "tcp://119.45.12.173:1883";
|
|
|
+ private static String HOST = "tcp://119.45.12.173:1883";
|
|
|
// 测试websocket
|
|
|
- private static String HOST = "tcp://43.137.10.199:1883";
|
|
|
+// private static String HOST = "tcp://43.137.10.199:1883";
|
|
|
private static String clientId = UUID.randomUUID().toString();
|
|
|
private static String username = "lnradar";
|
|
|
private static String password = "lnradar";
|
|
|
@@ -61,6 +61,7 @@ public class MqttUtil {
|
|
|
sub("/das/realtime_pos");
|
|
|
sub("/das/dev_status");
|
|
|
sub("/das/exist");
|
|
|
+ sub("/das/alarm_event");
|
|
|
}
|
|
|
|
|
|
public static void init() throws MqttException {
|
|
|
@@ -266,14 +267,64 @@ public class MqttUtil {
|
|
|
}
|
|
|
System.out.println("mqttutil--当前useropenid=" + user.getOpenid() +", fwhopenId=" + fwhOpenId);
|
|
|
System.out.println("发送微信公众号信息:devName=" + dev_name.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
|
|
|
-// log.info("mqttutil--发送微信公众号信息:devName=" + dev.getDev_name() + ", phoneNo=" + phoneNo + "fwhOpenId=" + fwhOpenId);
|
|
|
- wxSendMessage.queryAccessToken(devId, dev_name.toString(), user.getPhone(), fwhOpenId);
|
|
|
+ wxSendMessage.queryAccessToken(devId, dev_name.toString(), user.getPhone(), fwhOpenId, "设备检测到跌倒,请前往小程序查看详细信息");
|
|
|
System.out.println("发送微信公众号消息发完了");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (topic.equals("/das/alarm_event")) {
|
|
|
+ JSONObject obj = JSONObject.parseObject(pl);
|
|
|
+ String dev_id = obj.getString("dev_id");
|
|
|
+
|
|
|
+ List<DevVO> devs = baseDAO.queryAllByCondition(DevVO.class, " and dev_id='" + dev_id + "' ", null);
|
|
|
+
|
|
|
+ List<String> openids = new ArrayList<String>();
|
|
|
+ StringBuffer dev_name = new StringBuffer("");
|
|
|
+ String devId = "";
|
|
|
+ // 设备拥有者openid
|
|
|
+ if (devs != null && devs.size() > 0) {
|
|
|
+ DevVO dev = devs.get(0);
|
|
|
+ openids.add(dev.getUser_openid());
|
|
|
+ dev_name.append(dev.getDev_name());
|
|
|
+ devId= dev.getDev_id();
|
|
|
+ }
|
|
|
+ // 被分享者openid
|
|
|
+// List<ShareVO> shares = baseDAO.queryAllByCondition(ShareVO.class, " and dev_id ='"+dev_id+"' ", null);
|
|
|
+// if(shares !=null && shares.size()>0) {
|
|
|
+// for(int i=0;i<shares.size();i++) {
|
|
|
+// ShareVO share =shares.get(i);
|
|
|
+// openids.add(share.getShared());
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ if (openids.size() > 0) {
|
|
|
+ // 拥有者和被分享者phone
|
|
|
+ StringBuffer sqlBuffer = new StringBuffer("and openid in(");
|
|
|
+ for (int i = 0; i < openids.size(); i++) {
|
|
|
+ sqlBuffer.append("'" + openids.get(i) + "',");
|
|
|
+ }
|
|
|
+ sqlBuffer.setLength(sqlBuffer.length() - 1);
|
|
|
+ sqlBuffer.append(")");
|
|
|
+ List<MiniUserVO> users = baseDAO.queryAllByCondition(MiniUserVO.class, sqlBuffer.toString(), null);
|
|
|
+ for (int i = 0; i < users.size(); i++) {
|
|
|
+ MiniUserVO user = users.get(i);
|
|
|
+
|
|
|
+ System.out.println("mqttUtil--消息发完了");
|
|
|
+ List<WxRelatiion> wxRelatiions = baseDAO.queryAllByConditionNocare(WxRelatiion.class, "and openid = '" + user.getOpenid() + "'", null);
|
|
|
+ String fwhOpenId = "";
|
|
|
+ if (wxRelatiions != null && !wxRelatiions.isEmpty()) {
|
|
|
+ fwhOpenId = wxRelatiions.get(0).getFwhopenid();
|
|
|
+ }
|
|
|
+ System.out.println("mqttutil--当前useropenid=" + user.getOpenid() +", fwhopenId=" + fwhOpenId);
|
|
|
+ System.out.println("发送微信公众号信息:devName=" + dev_name.toString() + ", phoneNo=" + user.getPhone() + "fwhOpenId=" + fwhOpenId);
|
|
|
+ wxSendMessage.queryAccessToken(devId, dev_name.toString(), user.getPhone(), fwhOpenId, "检测到异常滞留,请前往小程序查看详细信息");
|
|
|
+ System.out.println("发送微信公众号消息发完了");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
if (topic.equals("/das/dev_status")) {
|
|
|
JSONObject obj = JSONObject.parseObject(pl);
|
|
|
String dev_id = obj.getString("dev_id");
|