-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/zipdabang/Server into fe…
…ature/140
- Loading branch information
Showing
18 changed files
with
244 additions
and
9 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
27 changes: 27 additions & 0 deletions
27
src/main/java/zipdabang/server/FeignClient/Config/FCMFeignConfiguration.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,27 @@ | ||
package zipdabang.server.FeignClient.Config; | ||
|
||
import feign.Logger; | ||
import feign.RequestInterceptor; | ||
import feign.codec.ErrorDecoder; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import zipdabang.server.FeignClient.exception.FeignClientExceptionErrorDecoder; | ||
|
||
@RequiredArgsConstructor | ||
public class FCMFeignConfiguration { | ||
|
||
@Bean | ||
public RequestInterceptor requestInterceptor(){ | ||
return template -> template.header("Content-Type", "application/json;charset=UTF-8"); | ||
} | ||
|
||
@Bean | ||
public ErrorDecoder errorDecoder() { | ||
return new FeignClientExceptionErrorDecoder(); | ||
} | ||
|
||
@Bean | ||
Logger.Level feignLoggerLevel() { | ||
return Logger.Level.FULL; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../FeignClient/KakaoFeignConfiguration.java → ...lient/Config/KakaoFeignConfiguration.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
2 changes: 1 addition & 1 deletion
2
.../FeignClient/NaverFeignConfiguration.java → ...lient/Config/NaverFeignConfiguration.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
20 changes: 20 additions & 0 deletions
20
src/main/java/zipdabang/server/FeignClient/FCMFeignClient.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,20 @@ | ||
package zipdabang.server.FeignClient; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import zipdabang.server.FeignClient.Config.FCMFeignConfiguration; | ||
import zipdabang.server.FeignClient.dto.fcm.FCMResponseDto; | ||
import zipdabang.server.firebase.fcm.dto.FcmAOSMessage; | ||
|
||
@FeignClient(name = "FCMFeign", url = "https://fcm.googleapis.com", configuration = FCMFeignConfiguration.class) | ||
@Component | ||
public interface FCMFeignClient { | ||
|
||
|
||
@PostMapping("/v1/projects/zipdabang-android/messages:send") | ||
FCMResponseDto getFCMResponse(@RequestHeader("Authorization") String token, @RequestBody String fcmAOSMessage); | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/main/java/zipdabang/server/FeignClient/NaverSmsFeignClient.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
14 changes: 14 additions & 0 deletions
14
src/main/java/zipdabang/server/FeignClient/dto/fcm/FCMResponseDto.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,14 @@ | ||
package zipdabang.server.FeignClient.dto.fcm; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class FCMResponseDto { | ||
String name; | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/zipdabang/server/firebase/fcm/dto/FcmAOSMessage.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,35 @@ | ||
package zipdabang.server.firebase.fcm.dto; | ||
|
||
import lombok.*; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class FcmAOSMessage { | ||
|
||
private boolean validateOnly; | ||
private Message message; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public static class Message{ | ||
private Data data; | ||
private String token; | ||
} | ||
|
||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public static class Data{ | ||
private String title; | ||
private String body; | ||
private String targetView; | ||
private String targetPK; | ||
private String targetNotification; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/zipdabang/server/firebase/fcm/service/FirebaseService.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,8 @@ | ||
package zipdabang.server.firebase.fcm.service; | ||
|
||
import java.io.IOException; | ||
|
||
public interface FirebaseService { | ||
|
||
void sendMessageTo(String targetToken, String title, String body, String targetView, String targetPK, String targetNotification) throws IOException; | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/zipdabang/server/firebase/fcm/service/FirebaseServiceImpl.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,74 @@ | ||
package zipdabang.server.firebase.fcm.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.gson.Gson; | ||
import lombok.RequiredArgsConstructor; | ||
import okhttp3.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.json.JsonParseException; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import zipdabang.server.FeignClient.FCMFeignClient; | ||
import zipdabang.server.FeignClient.dto.fcm.FCMResponseDto; | ||
import zipdabang.server.firebase.fcm.dto.FcmAOSMessage; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class FirebaseServiceImpl implements FirebaseService{ | ||
|
||
private String fcmUrl = "https://fcm.googleapis.com/v1/projects/zipdabang-android/messages:send"; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final FCMFeignClient fcmFeignClient; | ||
|
||
Logger logger = LoggerFactory.getLogger(FirebaseServiceImpl.class); | ||
|
||
@Override | ||
@Transactional | ||
public void sendMessageTo(String targetToken, String title, String body, String targetView, String targetPK, String targetNotification) throws IOException { | ||
String aosMessage = makeAOSMessage(targetToken, title, body, targetView, targetPK, targetNotification); | ||
|
||
FCMResponseDto fcmResponse = fcmFeignClient.getFCMResponse("Bearer " + getAccessToken(),aosMessage); | ||
logger.info("성공? : {}",fcmResponse); | ||
logger.info("보낸 메세지 : {}",aosMessage); | ||
} | ||
|
||
private String makeAOSMessage(String targeToken, String title, String body, String targetView, String targetPK,String targetNotification) throws JsonParseException, JsonProcessingException { | ||
FcmAOSMessage fcmMessage = FcmAOSMessage.builder() | ||
.message( | ||
FcmAOSMessage.Message.builder() | ||
.token(targeToken). | ||
data(FcmAOSMessage.Data.builder() | ||
.title(title) | ||
.body(body) | ||
.targetView(targetView) | ||
.targetNotification(targetNotification) | ||
.targetPK(targetPK).build() | ||
). | ||
build() | ||
) | ||
.validateOnly(false).build(); | ||
return objectMapper.writeValueAsString(fcmMessage); | ||
} | ||
|
||
private String getAccessToken() throws IOException{ | ||
String fireBaseConfigPath = "firebase/zipdabang-firebase-key.json"; | ||
|
||
GoogleCredentials googleCredentials = GoogleCredentials | ||
.fromStream(new ClassPathResource(fireBaseConfigPath).getInputStream()) | ||
.createScoped(List.of("https://www.googleapis.com/auth/cloud-platform")); | ||
googleCredentials.refreshIfExpired(); | ||
return googleCredentials.getAccessToken().getTokenValue(); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/zipdabang/server/web/dto/requestDto/RootRequestDto.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,11 @@ | ||
package zipdabang.server.web.dto.requestDto; | ||
|
||
import lombok.Getter; | ||
|
||
public class RootRequestDto { | ||
|
||
@Getter | ||
public static class FCMTestDto{ | ||
String fcmToken; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"type": "service_account", | ||
"project_id": "zipdabang-android", | ||
"private_key_id": "d12c0f24a9637589b2d4ea148ca257b47c4178c4", | ||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC2Iu1utX6w9ZZZ\nFSpv0HytxvPz37G1UW6HixLy/NRPUJj8LJNQIjK3lnXuL9doiDGWdjuQChuvEcLg\nt8FCF1F1Jq52RwwwdtHRBT8NqbThcLFqXduWQhxhEZ3Dutccf1JhoxWKd/Rw3lTd\nNO2UROrRZfcWHore8nOIFqIHcSY81BiZKWJbq8030tJIvsE1IRXfxKmkqdJw0xnm\n7GCX0qHKqAzcNS6ahRedhtcE0bTislm7qoV6eLTelpCWf7UG0+5Ba98UDMUD/WHe\n/0w51fTeSqTi1CyrwKCFIBlOVjcbeu/GxKqsmCWTOfI5XnmPIwBFhbXDBTKNNsQv\niGPV/CuzAgMBAAECggEAChaZLB6la8vOjhScCyFzJnT0ojdrsm1WP++2FvtmDxaZ\nwq39YtziDkUpNw4zUjjo9jqKRgopSmMjdir3a1+7RU/lLev1guGx8W/m9CzINgx1\n5zxXo1T6GW5OXL8Gly9+MqZD1S2bvnyyGqaJ2kKO9xY8v17ltj+bopgOVXcw9QF6\neCgvMw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==\n-----END PRIVATE KEY-----\n", | ||
"client_email": "firebase-adminsdk-ipk1z@zipdabang-android.iam.gserviceaccount.com", | ||
"client_id": "102672117766991763499", | ||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-ipk1z%40zipdabang-android.iam.gserviceaccount.com", | ||
"universe_domain": "googleapis.com" | ||
} |