diff --git a/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java b/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java index 5ac1cea..018484b 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/controller/AlarmController.java @@ -22,13 +22,14 @@ public class AlarmController { @PostMapping("/api/fcm") public ResponseEntity pushMessage(@RequestBody FCMMessageTestDto fcmTestDto) throws IOException { - // log.info(fcmTestDto.getTargetToken() + " " +fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); - log.info(fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); + log.info(fcmTestDto.getTargetToken() + " " +fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); + // log.info(fcmTestDto.getTitle() + " " + fcmTestDto.getBody()); fcmService.sendMessageTo( - //fcmTestDto.getTargetToken(), + fcmTestDto.getTargetToken(), fcmTestDto.getTitle(), - fcmTestDto.getBody()); + fcmTestDto.getBody() + ); return ResponseEntity.ok().build(); } diff --git a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java index e067540..2715810 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageDto.java @@ -28,6 +28,7 @@ public static class Message { private Notification notification; private String token; private Data data; + private Apns apns; } /** @@ -55,4 +56,28 @@ public static class Data { private String description; } + /** + * iOS 알림 추가 설정: 소리 등등 + */ + @Builder + @AllArgsConstructor + @Getter + public static class Aps { + private String sound; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Payload { + private Aps aps; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Apns { + private Payload payload; + } + } diff --git a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java index 5167111..676eaa1 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/dto/FCMMessageTestDto.java @@ -11,9 +11,6 @@ public class FCMMessageTestDto { private String title; private String body; - // private String targetToken; + private String targetToken; - public FCMMessageTestDto(){ - - } } diff --git a/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java b/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java index 47aeeef..5c5901b 100644 --- a/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java +++ b/src/main/java/com/umc/commonplant/domain/alarm/service/FCMService.java @@ -55,19 +55,23 @@ private String getAccessToken() throws IOException { * @return * @throws JsonProcessingException */ - // private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { - private String makeMessage(String title, String body) throws JsonProcessingException { + private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { + // private String makeMessage(String title, String body) throws JsonProcessingException { FCMMessageDto fcmMessage = FCMMessageDto.builder() .message(FCMMessageDto.Message.builder() - //.token(targetToken) + .token(targetToken) .notification(FCMMessageDto.Notification.builder() .title(title) .body(body) .image(null) .build() ) - .build() - ) + .apns(FCMMessageDto.Apns.builder() + .payload(FCMMessageDto.Payload.builder() + .aps(FCMMessageDto.Aps.builder().sound("default").build()) + .build()) + .build()) + .build()) .validate_only(false) .build(); @@ -81,10 +85,10 @@ private String makeMessage(String title, String body) throws JsonProcessingExcep * @param body * @throws IOException */ - // public void sendMessageTo(String targetToken, String title, String body) throws IOException { - public void sendMessageTo(String title, String body) throws IOException { - // String message = makeMessage(targetToken, title, body); - String message = makeMessage(title, body); + public void sendMessageTo(String targetToken, String title, String body) throws IOException { + // public void sendMessageTo(String title, String body) throws IOException { + String message = makeMessage(targetToken, title, body); + // String message = makeMessage(title, body); OkHttpClient client = new OkHttpClient();