Skip to content

Commit

Permalink
[Fix]: Alarm API: FCM Token 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
sonshn committed Mar 2, 2024
1 parent 95869c8 commit e7ac592
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ public class AlarmController {
@PostMapping("/api/fcm")
public ResponseEntity<ErrorResponse> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class Message {
private Notification notification;
private String token;
private Data data;
private Apns apns;
}

/**
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public class FCMMessageTestDto {

private String title;
private String body;
// private String targetToken;
private String targetToken;

public FCMMessageTestDto(){

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit e7ac592

Please sign in to comment.