Skip to content

Commit

Permalink
merge: (#178) FCM 전송 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut authored Dec 28, 2022
2 parents cd9dd43 + 298c9bb commit d1976c0
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 2 deletions.
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ object Dependencies {
// poi
const val POI = "org.apache.poi:poi:${DependencyVersions.POI_VERSION}"
const val POI_OOXML = "org.apache.poi:poi-ooxml:${DependencyVersions.POI_VERSION}"

// firebase
const val FIREBASE_ADMIN = "com.google.firebase:firebase-admin:${DependencyVersions.FIREBASE_ADMIN_VERSION}"
}
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/DependencyVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ object DependencyVersions {
const val BYTE_BUDDY = "1.12.18"
const val COMMONS_IO = "2.11.0"
const val POI_VERSION = "5.2.3"
const val FIREBASE_ADMIN_VERSION = "9.1.0"
}
3 changes: 3 additions & 0 deletions simtong-infrastructure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ dependencies {
implementation(Dependencies.POI)
implementation(Dependencies.POI_OOXML)

// firebase
implementation(Dependencies.FIREBASE_ADMIN)

// configuration
annotationProcessor(Dependencies.CONFIGURATION_PROCESSOR)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package team.comit.simtong.thirdparty.notification

import com.google.firebase.messaging.ApnsConfig
import com.google.firebase.messaging.Aps
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.Message
import com.google.firebase.messaging.MulticastMessage
import com.google.firebase.messaging.Notification
import org.springframework.stereotype.Component
import java.util.UUID

/**
*
* FCM 메시지를 전송하는 FcmAdapter
*
* @author kimbeomjin
* @date 2022/12/27
* @version 1.1.0
**/
@Component
class FcmAdapter {

fun sendMessage(tokens: List<String>, title: String, content: String, identify: UUID) {
val multicastMessage = MulticastMessage.builder()
.addAllTokens(tokens)
.putData("identify", identify.toString())
.setNotification(
Notification.builder()
.setTitle(title)
.setBody(content)
.build()
)
.setApnsConfig(
ApnsConfig.builder()
.setAps(Aps.builder().setSound("default").build())
.build()
)
.build()

FirebaseMessaging.getInstance().sendMulticastAsync(multicastMessage)
}

fun sendMessage(token: String, title: String, content: String, identify: UUID) {
val message = Message.builder()
.setToken(token)
.putData("identify", identify.toString())
.setNotification(
Notification.builder()
.setTitle(title)
.setBody(content)
.build()
)
.setApnsConfig(
ApnsConfig.builder()
.setAps(Aps.builder().setSound("default").build())
.build()
)
.build()

FirebaseMessaging.getInstance().sendAsync(message)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package team.comit.simtong.thirdparty.notification

import com.google.auth.oauth2.GoogleCredentials
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import java.io.ByteArrayInputStream
import java.io.IOException
import java.nio.charset.StandardCharsets
import javax.annotation.PostConstruct

/**
*
* FCM 관련 설정을 하는 FcmConfig
*
* @author kimbeomjin
* @date 2022/12/27
* @version 1.1.0
**/
@Configuration
class FcmConfig(
@Value("\${fcm.value}")
private val fcmValue: String
) {

@PostConstruct
private fun initialize() {
try {
if (FirebaseApp.getApps().isEmpty()) {
val options: FirebaseOptions = FirebaseOptions.builder()
.setCredentials(
GoogleCredentials.fromStream(
ByteArrayInputStream(
fcmValue.toByteArray(StandardCharsets.UTF_8)
)
)
)
.build()
FirebaseApp.initializeApp(options)
}
} catch (e: IOException) {
e.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ domain:
head: ${HEAD_SPOT:본점}
holiday:
week-holiday-limit: ${WEEK_HOLIDAY_LIMIT:2}
annual-leave-limit: ${ANNUAL_LEAVE_LIMIT:15}
annual-leave-limit: ${ANNUAL_LEAVE_LIMIT:15}

fcm:
value: ${FCM_VALUE}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ domain:
head: ${HEAD_SPOT}
holiday:
week-holiday-limit: ${WEEK_HOLIDAY_LIMIT}
annual-leave-limit: ${ANNUAL_LEAVE_LIMIT}
annual-leave-limit: ${ANNUAL_LEAVE_LIMIT}

fcm:
value: ${FCM_VALUE}

0 comments on commit d1976c0

Please sign in to comment.