添加接口:服务器绑定用户的推送信息
This commit is contained in:
parent
cedfc78357
commit
6341aeecd5
BIN
lib/MiPush_SDK_Server_Http2_1.0.14.jar
Normal file
BIN
lib/MiPush_SDK_Server_Http2_1.0.14.jar
Normal file
Binary file not shown.
17
pom.xml
17
pom.xml
@ -239,6 +239,20 @@
|
|||||||
<version>3.1.521</version>
|
<version>3.1.521</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xiaomi.miliao</groupId>
|
||||||
|
<artifactId>xmpush-server-api-http2</artifactId>
|
||||||
|
<version>1.0.14</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${project.basedir}/lib/MiPush_SDK_Server_Http2_1.0.14.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -267,6 +281,9 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<includeSystemScope>true</includeSystemScope>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
@ -10,8 +10,8 @@ import com.xkrs.model.vo.AppTaskBodyVo;
|
|||||||
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
||||||
import com.xkrs.service.FirePointService;
|
import com.xkrs.service.FirePointService;
|
||||||
import com.xkrs.service.GlobalConfigService;
|
import com.xkrs.service.GlobalConfigService;
|
||||||
|
import com.xkrs.sms.PushHelper;
|
||||||
import com.xkrs.sms.SMSHelper;
|
import com.xkrs.sms.SMSHelper;
|
||||||
import com.xkrs.sms.WeChatMessageHelper;
|
|
||||||
import com.xkrs.utils.*;
|
import com.xkrs.utils.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -96,7 +96,7 @@ public class FirePointServiceImpl implements FirePointService {
|
|||||||
private SMSHelper smsHelper;
|
private SMSHelper smsHelper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private WeChatMessageHelper weChatMessageHelper;
|
private PushHelper pushHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加火点信息
|
* 添加火点信息
|
||||||
@ -375,10 +375,12 @@ public class FirePointServiceImpl implements FirePointService {
|
|||||||
boolean vipSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L);
|
boolean vipSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L);
|
||||||
List<SysUserEntity> smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList, adminList, normalSmsEnable, vipSmsEnable);
|
List<SysUserEntity> smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList, adminList, normalSmsEnable, vipSmsEnable);
|
||||||
|
|
||||||
|
//推送
|
||||||
try {
|
try {
|
||||||
weChatMessageHelper.dispatchWeChatMessage(smsReceiverList, firePointEntity);
|
List<String> userAccountList = pushHelper.obtainUserAccountList(smsReceiverList);
|
||||||
|
pushHelper.dispatchPushMessage(userAccountList, firePointEntity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//对短信通知收件人进行分组
|
//对短信通知收件人进行分组
|
||||||
|
77
src/main/java/com/xkrs/sms/PushHelper.java
Normal file
77
src/main/java/com/xkrs/sms/PushHelper.java
Normal file
@ -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<String> obtainUserAccountList(List<SysUserEntity> sysUserList) {
|
||||||
|
List<String> 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<String> 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, 发送消息到指定设备上
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user