Feat: FCM Service 기능 구현
This commit is contained in:
parent
3c4ff8204e
commit
77c81303a8
@ -40,12 +40,10 @@ public class FCMConfig {
|
|||||||
FirebaseApp firebaseApp = FirebaseApp.getApps().isEmpty() ?
|
FirebaseApp firebaseApp = FirebaseApp.getApps().isEmpty() ?
|
||||||
FirebaseApp.initializeApp(options) :
|
FirebaseApp.initializeApp(options) :
|
||||||
FirebaseApp.getInstance();
|
FirebaseApp.getInstance();
|
||||||
log.debug("firebase 불러오기 성공");
|
|
||||||
// 설정된 FirebaseApp 연결된 FirebaseMessaging 인스턴스를 반환
|
// 설정된 FirebaseApp 연결된 FirebaseMessaging 인스턴스를 반환
|
||||||
return FirebaseMessaging.getInstance(firebaseApp);
|
return FirebaseMessaging.getInstance(firebaseApp);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CustomException(ErrorCode.SERVER_ERROR, "Firebase Key 불러오기 실패 ");
|
throw new CustomException(ErrorCode.SERVER_ERROR, "Firebase Key 불러오기 실패 ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.worlabel.global.service;
|
||||||
|
|
||||||
|
import com.google.firebase.messaging.FirebaseMessaging;
|
||||||
|
import com.google.firebase.messaging.Message;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class FCMService {
|
||||||
|
|
||||||
|
private final FirebaseMessaging firebaseMessaging;
|
||||||
|
|
||||||
|
private void sendNotification(String targetToken, String title, String body){
|
||||||
|
Message message = Message.builder()
|
||||||
|
.setToken(targetToken)
|
||||||
|
.putData("title",title)
|
||||||
|
.putData("body",body)
|
||||||
|
.build();
|
||||||
|
try {
|
||||||
|
log.debug("FCM 알림 전송 {}", message);
|
||||||
|
firebaseMessaging.sendAsync(message);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("FCM 전송 오류 ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user