From 75eb8b1e3748f724651948249384b0cd58a5618e Mon Sep 17 00:00:00 2001 From: junhaa <2171326@hansung.ac.kr> Date: Wed, 8 May 2024 01:56:29 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20FEAT.=20webhook=20=EB=B3=B5?= =?UTF-8?q?=ED=98=B8=ED=99=94=20=EA=B8=B0=EB=8A=A5,=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../faceSwap/service/FaceSwapApiServiceImpl.java | 8 ++++++++ .../tbd/domain/faceSwap/util/CryptoUtils.java | 10 ++++++---- .../web/controller/FaceSwapRestController.java | 8 ++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/fairytale/tbd/domain/faceSwap/service/FaceSwapApiServiceImpl.java b/src/main/java/fairytale/tbd/domain/faceSwap/service/FaceSwapApiServiceImpl.java index b40eb78..0dc03b4 100644 --- a/src/main/java/fairytale/tbd/domain/faceSwap/service/FaceSwapApiServiceImpl.java +++ b/src/main/java/fairytale/tbd/domain/faceSwap/service/FaceSwapApiServiceImpl.java @@ -1,6 +1,8 @@ package fairytale.tbd.domain.faceSwap.service; +import fairytale.tbd.domain.faceSwap.util.CryptoUtils; import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapRequestDto; +import fairytale.tbd.domain.faceSwap.web.dto.WebhookRequestDTO; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; @@ -37,6 +39,8 @@ public class FaceSwapApiServiceImpl implements FaceSwapApiService{ private final ObjectMapper objectMapper; + private final CryptoUtils cryptoUtils; + @Override @Transactional public Map getFaceSwapImg(FaceSwapRequestDto.FaceSwapRequest faceSwapRequest) throws IOException{ @@ -135,5 +139,9 @@ public String getToken() { throw new RuntimeException(e); } } + + public String getSwapImageURL(WebhookRequestDTO.RequestDTO webhookRequestDTO){ + return cryptoUtils.getURL(webhookRequestDTO); + } } diff --git a/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java b/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java index 2aa20c8..0163bb7 100644 --- a/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java +++ b/src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java @@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import fairytale.tbd.domain.faceSwap.web.dto.WebhookRequestDTO; + @Component public class CryptoUtils { @@ -84,10 +86,10 @@ public static String generateAesEncrypt(String data, String clientId, String cli } // Example usage - public String getURL(String timestamp, String nonce, String msgEncrypt, String signature){ - String newSignature = generateMsgSignature(clientId, timestamp, nonce, msgEncrypt); - if (signature.equals(newSignature)) { - String result = generateAesDecrypt(msgEncrypt, clientId, clientSecret); + public String getURL(WebhookRequestDTO.RequestDTO webhookRequestDTO){ + String newSignature = generateMsgSignature(clientId, webhookRequestDTO.getTimestamp(), webhookRequestDTO.getNonce(), webhookRequestDTO.getDataEncrypt()); + if (webhookRequestDTO.getSignature().equals(newSignature)) { + String result = generateAesDecrypt(webhookRequestDTO.getDataEncrypt(), clientId, clientSecret); return result; } return null; diff --git a/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java b/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java index 98c0b5c..5321864 100644 --- a/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java +++ b/src/main/java/fairytale/tbd/domain/faceSwap/web/controller/FaceSwapRestController.java @@ -32,7 +32,7 @@ public class FaceSwapRestController { private final PhotoUploadServiceImpl photoUploadService; private final FaceDetectApiServiceImpl faceDetectApiService; private final FaceSwapApiServiceImpl faceSwapApiService; - private final CryptoUtils cryptoUtils; + @PostMapping("/uploadImg") public ApiResponse uploadImg(@LoginUser User user, @ModelAttribute MultipartFile file) throws IOException{ @@ -80,7 +80,11 @@ public ApiResponse> test(@RequestBody FaceSwapRequestDto.Fac } @PostMapping("/webhook") - public void webhook(@RequestBody WebhookRequestDTO.RequestDTO request){ + public ApiResponse webhook(@RequestBody WebhookRequestDTO.RequestDTO request){ LOGGER.info("request = {}", request); + + String swapResult = faceSwapApiService.getSwapImageURL(request); + LOGGER.info("swapResult = {}", swapResult); + return ApiResponse.onSuccess("thank you"); } }