diff --git a/lib/MiPush_SDK_Server_Http2_1.0.14.jar b/lib/MiPush_SDK_Server_Http2_1.0.14.jar new file mode 100644 index 0000000..956b7aa Binary files /dev/null and b/lib/MiPush_SDK_Server_Http2_1.0.14.jar differ diff --git a/pom.xml b/pom.xml index 6322617..4a08061 100644 --- a/pom.xml +++ b/pom.xml @@ -239,6 +239,20 @@ 3.1.521 + + com.xiaomi.miliao + xmpush-server-api-http2 + 1.0.14 + system + ${project.basedir}/lib/MiPush_SDK_Server_Http2_1.0.14.jar + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + @@ -267,6 +281,9 @@ org.springframework.boot spring-boot-maven-plugin + + true + diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 0231da0..90ca35b 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -10,8 +10,8 @@ import com.xkrs.model.vo.AppTaskBodyVo; import com.xkrs.model.vo.GaoDeIgGeocodeVo; import com.xkrs.service.FirePointService; import com.xkrs.service.GlobalConfigService; +import com.xkrs.sms.PushHelper; import com.xkrs.sms.SMSHelper; -import com.xkrs.sms.WeChatMessageHelper; import com.xkrs.utils.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,7 +96,7 @@ public class FirePointServiceImpl implements FirePointService { private SMSHelper smsHelper; @Resource - private WeChatMessageHelper weChatMessageHelper; + private PushHelper pushHelper; /** * 添加火点信息 @@ -375,10 +375,12 @@ public class FirePointServiceImpl implements FirePointService { boolean vipSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L); List smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList, adminList, normalSmsEnable, vipSmsEnable); + //推送 try { - weChatMessageHelper.dispatchWeChatMessage(smsReceiverList, firePointEntity); + List userAccountList = pushHelper.obtainUserAccountList(smsReceiverList); + pushHelper.dispatchPushMessage(userAccountList, firePointEntity); } catch (Exception e) { - throw new RuntimeException(e); + e.printStackTrace(); } //对短信通知收件人进行分组 diff --git a/src/main/java/com/xkrs/sms/PushHelper.java b/src/main/java/com/xkrs/sms/PushHelper.java new file mode 100644 index 0000000..62b70a9 --- /dev/null +++ b/src/main/java/com/xkrs/sms/PushHelper.java @@ -0,0 +1,77 @@ +package com.xkrs.sms; + +import com.xiaomi.xmpush.server.Constants; +import com.xiaomi.xmpush.server.Message; +import com.xiaomi.xmpush.server.Sender; +import com.xkrs.model.entity.FirePointEntity; +import com.xkrs.model.entity.SysUserEntity; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class PushHelper { + + public PushHelper() { + } + + public List obtainUserAccountList(List sysUserList) { + List userAccountList = new ArrayList<>(); + if (sysUserList != null && sysUserList.size() > 0) { + for (SysUserEntity sysUserEntity : sysUserList) { + userAccountList.add(sysUserEntity.getPushUserAccount()); + } + } + return userAccountList; + } + + /** + * 发起推送 + * + * @param userAccountList userAccount 非空白,不能包含逗号, 长度小于128 + * @param firePointEntity + * @throws Exception + */ + public void dispatchPushMessage(List userAccountList, FirePointEntity firePointEntity) throws Exception { + Constants.useOfficial(); + Sender sender = new Sender("f6N7nchoqOWj3YyZiQPH2w=="); + String messagePayload = "This is a message"; + String title = "notification title"; + String description = "notification description"; + Message.Builder messageBuilder = new Message.Builder(); + // 设置要发送的消息内容payload, 不允许全是空白字符, 长度小于4KB, 一个中英文字符均计算为1 + messageBuilder.payload(messagePayload); + // 设置在通知栏展示的通知的标题, 不允许全是空白字符, 长度小于50, 一个中英文字符均计算为1(通知栏消息必填) + messageBuilder.title(title); + // 设置在通知栏展示的通知描述, 不允许全是空白字符, 长度小于128, 一个中英文字符均计算为1(通知栏消息必填) + messageBuilder.description(description); + // 设置通知类型, type类型支持以下值: + // 1:使用默认提示音提示 + // 2:使用默认震动提示 + // 4:使用默认led灯光提示 + // -1(系统默认值):以上三种效果都有 + // 0:以上三种效果都无,即静默推送。 + // 并且支持1,2,4的任意OR运算来实现声音、震动和闪光灯的任意组合。 + messageBuilder.notifyType(1);//使用默认提示音提示 + // 设置app的包名packageName, packageName必须和开发者网站上申请的结果一致 + messageBuilder.restrictedPackageName("com.xkrs.mssfms"); + // 设置app的多包名packageNames(多包名发送广播消息), packageNames必须和开发者网站上申请的结果一致, 可以为空, + // 为空则默认给所有渠道包名推送(不能同时调用restrictedPackageName方法和restrictedPackageNames方法) +// messageBuilder.restrictedPackageNames(null); + // 可选项, 消息的生命周期, 若用户离线, 设置消息在服务器保存的时间, 单位: ms(服务器默认最长10天) +// messageBuilder.timeToLive(10 * 24 * 60 * 60 * 1000); + // 可选项, 定时发送消息, timeToSend是以毫秒为单位的时间戳(仅支持七天内的定时消息) +// messageBuilder.timeToSend(0); + // 可选项, 默认情况下, 通知栏只显示一条推送消息, 如果通知栏要显示多条推送消息, 需要针对不同的消息设置不同的notify_id(相同notify_id的通知栏消息会覆盖之前的), + // 且要求notify_id为取值在0~2147483647的整数。 +// messageBuilder.notifyId(1); + // 可选项, 控制消息是否需要进行平滑推送(qps less 3000/second), 默认不支持 +// messageBuilder.enableFlowControl(false); + // 可选项, 对app提供一些扩展功能(除了这些扩展功能, 开发者还可以定义一些key和value来控制客户端的行为, + // 注:key和value的字符数不能超过1024, 至多可以设置10个key-value键值对) +// messageBuilder.extra("",""); + Message message = messageBuilder.build(); + sender.sendToUserAccount(message, userAccountList, 3);//根据accountList, 发送消息到指定设备上 + } +}