-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
2 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
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
62 changes: 62 additions & 0 deletions
62
...g-infrastructure/src/main/kotlin/team/comit/simtong/thirdparty/notification/FcmAdapter.kt
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,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) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ng-infrastructure/src/main/kotlin/team/comit/simtong/thirdparty/notification/FcmConfig.kt
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,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() | ||
} | ||
} | ||
} |
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