-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from EveryUniv/dev
fix: FCM 기능 수정 (단, 아직 완벽하진 않아서 향후 사용시 수정 필요)
- Loading branch information
Showing
9 changed files
with
367 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,6 @@ api.pdf | |
/pinpoint-agent/ | ||
/logs/.DS_Store | ||
.DS_Store | ||
|
||
### Firebase ### | ||
**/src/main/resources/**/**.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 26 additions & 16 deletions
42
src/main/java/com/dku/council/infra/fcm/config/FCMConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
package com.dku.council.infra.fcm.config; | ||
|
||
import com.dku.council.infra.fcm.model.dto.request.FCMPushRequestDto; | ||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import com.google.firebase.messaging.ApnsConfig; | ||
import com.google.firebase.messaging.Aps; | ||
import com.google.firebase.messaging.ApsAlert; | ||
import com.google.firebase.messaging.FirebaseMessaging; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
// TODO 향후 사용시 활성화 | ||
//@Configuration | ||
@Configuration | ||
@Slf4j | ||
public class FCMConfig { | ||
|
||
@Bean | ||
public FirebaseMessaging firebaseMessaging() { | ||
try (InputStream keyStream = FCMConfig.class.getResourceAsStream("/serviceAccountKey.json")) { | ||
if (keyStream == null) { | ||
throw new IOException("Not found serviceAccountKey.json file"); | ||
} | ||
if (!FirebaseApp.getApps().isEmpty()) { | ||
return FirebaseMessaging.getInstance(); | ||
} | ||
@Value("${fcm.key.path}") | ||
private String SERVICE_ACCOUNT_JSON; | ||
|
||
@PostConstruct | ||
public void init() { | ||
try { | ||
ClassPathResource resource = new ClassPathResource(SERVICE_ACCOUNT_JSON); | ||
InputStream inputStream = resource.getInputStream(); | ||
|
||
FirebaseOptions options = FirebaseOptions.builder() | ||
.setCredentials(GoogleCredentials.fromStream(keyStream)) | ||
.setCredentials(GoogleCredentials.fromStream(inputStream)) | ||
.setProjectId("next-dku-push-server") | ||
.build(); | ||
FirebaseApp app = FirebaseApp.initializeApp(options); | ||
return FirebaseMessaging.getInstance(app); | ||
|
||
FirebaseApp.initializeApp(options); | ||
log.info("파이어베이스 서버와의 연결에 성공했습니다."); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
log.error("파이어베이스 서버와의 연결에 실패했습니다.", e); | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/dku/council/infra/fcm/model/dto/FCMMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.dku.council.infra.fcm.model.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class FCMMessage { | ||
|
||
private boolean validateOnly; | ||
private Message message; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@Getter | ||
public static class Message { | ||
private Notification notification; | ||
private String token; | ||
private String topic; | ||
} | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@Getter | ||
public static class Notification { | ||
private String title; | ||
private String body; | ||
private String image; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/dku/council/infra/fcm/model/dto/request/FCMPushRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.dku.council.infra.fcm.model.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.*; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Getter | ||
@Slf4j | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class FCMPushRequestDto { | ||
|
||
private String targetToken; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private String title; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private String body; | ||
} |
Oops, something went wrong.