From 61bce4c26a3defe256d4c503e9d1605049678a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=B4=AA=E9=BE=99?= <599179587@qq.com> Date: Fri, 28 Jul 2017 13:38:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E7=95=99=E8=A8=80?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ifish/enums/PushTypeEnum.java | 3 +- .../java/com/ifish/helper/LiveRoomHelper.java | 97 ++++++++++++++++++- 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ifish/enums/PushTypeEnum.java b/src/main/java/com/ifish/enums/PushTypeEnum.java index 5e209a9..4a3bd77 100644 --- a/src/main/java/com/ifish/enums/PushTypeEnum.java +++ b/src/main/java/com/ifish/enums/PushTypeEnum.java @@ -19,7 +19,8 @@ public enum PushTypeEnum { offline_push("offline_push", "离线通知"), send_report("send_report", "看护报告"), shops_push("shops_push", "看护通知"), - all_push("all_push", "所有用户推送"); + all_push("all_push", "所有用户推送"), + pinglun_push("pinglun_push","直播间评论"); private PushTypeEnum(String key, String value) { this.key = key; diff --git a/src/main/java/com/ifish/helper/LiveRoomHelper.java b/src/main/java/com/ifish/helper/LiveRoomHelper.java index 7fed8b7..9c16571 100644 --- a/src/main/java/com/ifish/helper/LiveRoomHelper.java +++ b/src/main/java/com/ifish/helper/LiveRoomHelper.java @@ -5,6 +5,7 @@ */ package com.ifish.helper; +import com.ifish.API.JiGuangPush; import com.ifish.Interceptor.IfishException; import com.ifish.bean.LiveRoomPageInfo; import com.ifish.bean.PageResult; @@ -12,7 +13,9 @@ import com.ifish.bean.Tbl_Device_User; import com.ifish.bean.Tbl_Live_Message; import com.ifish.bean.Tbl_Live_Room; import com.ifish.bean.Tbl_Live_Watch; +import com.ifish.bean.Tbl_Push_List; import com.ifish.bean.Tbl_User; +import com.ifish.enums.PushTypeEnum; import com.ifish.enums.ResultEnum; import com.ifish.mapper.Tbl_Live_Room_Mapper; import com.ifish.util.IfishUtil; @@ -51,6 +54,12 @@ public class LiveRoomHelper implements LiveRoomHelperI { @Autowired private RedisKeyHelperI redisKeyHelperI; + @Autowired + private JiGuangPush jiGuangPush; + + @Autowired + private PushMessageHelperI pushMessageHelperI; + /** * 新增直播间 * @@ -246,8 +255,7 @@ public class LiveRoomHelper implements LiveRoomHelperI { try { Integer roomId = liveMessage.getRoomId(); Integer userId = liveMessage.getUserId(); - String messageContent = new String(liveMessage.getMessageContent().getBytes("ISO-8859-1"), "UTF-8"); - liveMessage.setMessageContent(messageContent); + String messageContent = liveMessage.getMessageContent(); if (roomId != null && userId != null && StringUtils.isNotBlank(messageContent)) { Tbl_Live_Room live_Room = getTbl_Live_RoomByRoomId(roomId); Tbl_User user = userHelperI.getUserById(userId); @@ -266,14 +274,40 @@ public class LiveRoomHelper implements LiveRoomHelperI { if (asUser != null) { liveMessage.setAsUserName(asUser.getNickName()); if (!asUserId.equals(userId)) { + String timestamp = IfishUtil.format(new Date()); //发送云信消息给所@的用户 //neteaseIM.sendMsg(userId.toString(), asUserId.toString(), "来自爱鱼看看的回复:" + messageContent, ""); + //基本参数 + Map baseMap = new HashMap(); + baseMap.put("title", PushTypeEnum.pinglun_push.getValue()); + baseMap.put("content", "来自爱鱼看看的回复:" + messageContent); + baseMap.put("user_id", asUserId.toString()); + baseMap.put("loginType", asUser.getLoginType()); + //推送参数 + Map pushMap = new HashMap(); + pushMap.put("timestamp", timestamp); + pushMap.put("msg_type", PushTypeEnum.pinglun_push.getKey()); + //推送消息 + jPushNotifcation(baseMap, pushMap); } } else { Integer roomUserId = live_Room.getUserId(); if (!roomUserId.equals(userId)) { //发送云信消息给房主 //neteaseIM.sendMsg(userId.toString(), roomUserId.toString(), "来自爱鱼看看的留言:" + messageContent, ""); + String timestamp = IfishUtil.format(new Date()); + //基本参数 + Map baseMap = new HashMap(); + baseMap.put("title", PushTypeEnum.pinglun_push.getValue()); + baseMap.put("content", "来自爱鱼看看的回复:" + messageContent); + baseMap.put("user_id", user.getUserId().toString()); + baseMap.put("loginType", user.getLoginType()); + //推送参数 + Map pushMap = new HashMap(); + pushMap.put("timestamp", timestamp); + pushMap.put("msg_type", PushTypeEnum.pinglun_push.getKey()); + //推送消息 + jPushNotifcation(baseMap, pushMap); } } } @@ -513,4 +547,63 @@ public class LiveRoomHelper implements LiveRoomHelperI { } return IfishUtil.toJson(ResultEnum.fail101.getKey(), ""); } + + /** + * 极光推送 + * + * @param userId + */ + public boolean jPushNotifcation(Map baseMap, Map pushMap) { + try { + //登录类型 + String loginType = baseMap.get("loginType"); + if (loginType != null) { + //推送消息类型 + String msgType = pushMap.get("msg_type"); + String userId = baseMap.get("user_id"); + String title = baseMap.get("title"); + String content = baseMap.get("content"); + boolean result = false; + if (loginType.equals("ios")) { + result = jiGuangPush.pushMessageByIOS(title, content, userId, pushMap); + } else if (loginType.equals("android")) { + result = jiGuangPush.pushMessageByAndroid(title, content, userId, pushMap); + } + //推送记录 + Tbl_Push_List pushList = new Tbl_Push_List(); + if (msgType.equals(PushTypeEnum.remove_device.getKey())) { + pushList.setUserId(Integer.valueOf(userId)); + pushList.setDeviceId(Integer.valueOf(pushMap.get("device_id"))); + pushList.setPhoneType(loginType); + pushList.setShowName(pushMap.get("showName")); + pushList.setPushType(msgType); + pushList.setPushTitle(title); + pushList.setPushContext(content); + pushList.setJpushStatus(result ? "1" : "0"); + pushList.setCreateTime(new Date()); + pushMessageHelperI.save(pushList); + return true; + } //发送看护报告推送 + else if (msgType.equals(PushTypeEnum.send_report.getKey())) { + String reportId = baseMap.get("reportId"); + if (reportId != null) { + pushList.setReportId(Integer.valueOf(reportId)); + } + pushList.setUserId(Integer.valueOf(userId)); + pushList.setPhoneType(loginType); + pushList.setPushType(msgType); + pushList.setPushTitle(title); + pushList.setPushContext(content); + pushList.setPushLink(pushMap.get("push_link")); + pushList.setJpushStatus(result ? "1" : "0"); + pushList.setCreateTime(new Date()); + pushMessageHelperI.save(pushList); + return true; + } + } + } catch (Exception e) { + throw new RuntimeException(); + } + return false; + } }