|
|
@@ -1,12 +1,16 @@
|
|
|
package com.nb.app.assistant.utils;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.nb.app.assistant.api.bean.DeviceAlarmBean;
|
|
|
import com.turo.pushy.apns.*;
|
|
|
import com.turo.pushy.apns.auth.ApnsSigningKey;
|
|
|
import com.turo.pushy.apns.util.SimpleApnsPushNotification;
|
|
|
import com.turo.pushy.apns.util.concurrent.PushNotificationFuture;
|
|
|
import io.netty.channel.EventLoopGroup;
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.io.File;
|
|
|
@@ -20,7 +24,7 @@ import static com.turo.pushy.apns.PushType.ALERT;
|
|
|
@Slf4j
|
|
|
public class ApnsUtils {
|
|
|
private static ApnsClient apnsClient = null;
|
|
|
- public static void sendMsg(String deviceToken,String msgContent) throws Exception {
|
|
|
+ public static void sendMsg(String deviceToken, DeviceAlarmBean source) throws Exception {
|
|
|
//IOS等终端设备注册后返回的DeviceToken
|
|
|
/**
|
|
|
* Use the voip push type for notifications that provide information about an incoming Voice-over-IP (VoIP)
|
|
|
@@ -34,17 +38,9 @@ public class ApnsUtils {
|
|
|
//此处可以参考https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns?language=objc
|
|
|
|
|
|
String topic = "tuoren.PumpIOS";
|
|
|
- String payload = "{ \n" +
|
|
|
- " \"aps\":{ \n" +
|
|
|
- " \"alert\":{ \n" +
|
|
|
- " \"title\":\"驼人镇痛泵报警\",\n" +
|
|
|
- " \"subtitle\":\"75415123E11248\",\n" +
|
|
|
- " \"body\":\"故障报警\"\n" +
|
|
|
- " },\n" +
|
|
|
- " \"badge\":1, \n" +
|
|
|
- " \"sound\":\"default\", \n" +
|
|
|
- " }\n" +
|
|
|
- "}\n" ;
|
|
|
+
|
|
|
+ ApsEntity aps = ApsEntity.createDefault(ApsEntity.AlertEntity.of("驼人镇痛泵报警", String.format("设备号:%s,住院号:%s", source.getDeviceId(), source.getPatientCode()), source.getAlarmState().getText()));
|
|
|
+ String payload = JSONUtil.toJsonStr(aps);
|
|
|
//有效时间
|
|
|
Date invalidationTime= new Date(System.currentTimeMillis() + 60 * 60 * 1000L );
|
|
|
//发送策略 apns-priority 10为立即 5为省电
|
|
|
@@ -92,4 +88,27 @@ public class ApnsUtils {
|
|
|
}
|
|
|
return apnsClient;
|
|
|
}
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public static class ApsEntity {
|
|
|
+
|
|
|
+ private AlertEntity alert;
|
|
|
+ private Integer badge;
|
|
|
+ private String sound;
|
|
|
+
|
|
|
+ public static ApsEntity createDefault(AlertEntity alert){
|
|
|
+ ApsEntity apsEntity = new ApsEntity();
|
|
|
+ apsEntity.setBadge(1);
|
|
|
+ apsEntity.setSound("default");
|
|
|
+ apsEntity.setAlert(alert);
|
|
|
+ return apsEntity;
|
|
|
+ }
|
|
|
+ @Data
|
|
|
+ @AllArgsConstructor(staticName = "of")
|
|
|
+ public static class AlertEntity {
|
|
|
+ private String title;
|
|
|
+ private String subtitle;
|
|
|
+ private String body;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|