From d1c2c241bf5041d6a5fb8ae58eb9d275086e6ee3 Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Mon, 1 Jul 2024 00:59:32 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]fcm=EC=A0=95=EC=B1=85=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EA=B2=8C=20=ED=95=84=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/comment/service/CommentCommendService.java | 4 ++-- .../api/content/service/ContentCommandService.java | 2 +- .../common/crontab/PopularContentScheduler.java | 2 +- .../DontBeServer/external/fcm/dto/FcmMessageDto.java | 3 ++- .../external/fcm/service/FcmService.java | 12 +++++++----- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/comment/service/CommentCommendService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/comment/service/CommentCommendService.java index 124a189..58b2cf1 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/comment/service/CommentCommendService.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/comment/service/CommentCommendService.java @@ -122,7 +122,7 @@ public void postCommentVer2(Long memberId, Long contentId, MultipartFile comment .description("답글 푸시 알림") .relateContentId(String.valueOf(contentId)) .build()) - .badge(String.valueOf(contentWritingMember.getFcmBadge())) + .badge(contentWritingMember.getFcmBadge()) .build()) .build(); @@ -197,7 +197,7 @@ public void likeComment(Long memberId, Long commentId, CommentLikedRequestDto co .description("답글 좋아요 푸시 알림") .relateContentId(String.valueOf(contentId)) .build()) - .badge(String.valueOf(targetMember.getFcmBadge())) + .badge(targetMember.getFcmBadge()) .build()) .build(); diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/content/service/ContentCommandService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/content/service/ContentCommandService.java index 3f33e84..8450ee4 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/content/service/ContentCommandService.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/api/content/service/ContentCommandService.java @@ -131,7 +131,7 @@ public void likeContent(Long memberId, Long contentId, ContentLikedRequestDto co .description("게시글 좋아요 푸시 알림") .relateContentId(String.valueOf(contentId)) .build()) - .badge(String.valueOf(targetMember.getFcmBadge())) + .badge(targetMember.getFcmBadge()) .build()) .build(); diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/common/crontab/PopularContentScheduler.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/common/crontab/PopularContentScheduler.java index 00aa36d..6f2c4aa 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/common/crontab/PopularContentScheduler.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/common/crontab/PopularContentScheduler.java @@ -83,7 +83,7 @@ public void popularContentNotification() { .description("인기글 관련 푸시 알림") .relateContentId(String.valueOf(topContent.getId())) .build()) - .badge(String.valueOf(topContentWriter.getFcmBadge())) + .badge(topContentWriter.getFcmBadge()) .build()) .build(); diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/dto/FcmMessageDto.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/dto/FcmMessageDto.java index d84c856..67a0806 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/dto/FcmMessageDto.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/dto/FcmMessageDto.java @@ -20,7 +20,7 @@ public static class Message { private NotificationDetails notificationDetails; private String token; private Data data; - private String badge; + private int badge; } @Builder @@ -29,6 +29,7 @@ public static class Message { public static class NotificationDetails { private String title; private String body; + private Integer badge; } @Builder diff --git a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/service/FcmService.java b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/service/FcmService.java index ce9387a..a23e02e 100644 --- a/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/service/FcmService.java +++ b/DontBeServer/src/main/java/com/dontbe/www/DontBeServer/external/fcm/service/FcmService.java @@ -6,9 +6,7 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; -import com.google.firebase.messaging.FirebaseMessaging; -import com.google.firebase.messaging.FirebaseMessagingException; -import com.google.firebase.messaging.Message; +import com.google.firebase.messaging.*; import lombok.RequiredArgsConstructor; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -48,10 +46,14 @@ public void sendMessage(FcmMessageDto fcmMessageDto) { .setBody(fcmMessageDto.getMessage().getNotificationDetails().getBody()) .build() ) + .setApnsConfig(ApnsConfig.builder() + .setAps(Aps.builder() + .setBadge(fcmMessageDto.getMessage().getBadge()) + .build()) + .build()) .putAllData(objectMapper.convertValue(fcmMessageDto.getMessage().getData(), Map.class)) - .putData("badge", fcmMessageDto.getMessage().getBadge()) .build(); - System.out.println(fcmMessageDto.getMessage().getBadge()); + System.out.println(fcmMessageDto.getMessage().getNotificationDetails().getBadge()); try { FirebaseMessaging.getInstance().send(message); } catch (FirebaseMessagingException e) {