From ffe1bc81d619aa9a8d6bc0d4231e78e96d086904 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Wed, 4 Jan 2023 18:12:36 -0500 Subject: [PATCH] =?UTF-8?q?USVT-132=20=E9=85=8D=E7=BD=AE=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=96=B0=E7=9A=84=20API=20Endpoint=20=E8=AE=A9=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E8=83=BD=E5=A4=9F=E5=AF=B9=E5=B9=B3=E5=8F=B0=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/web/AutoApiResponseBodyAdvice.java | 4 +- .../api/controller/HomeController.java | 26 ++++++++---- .../controller/{ => auth}/AuthController.java | 4 +- .../api/controller/auth/WeChatController.java | 6 ++- .../auth/WeChatVerificationRequest.java | 42 +++++++++++++++++++ 5 files changed, 70 insertions(+), 12 deletions(-) rename src/main/java/com/northtecom/visatrack/api/controller/{ => auth}/AuthController.java (98%) create mode 100644 src/main/java/com/northtecom/visatrack/api/model/request/auth/WeChatVerificationRequest.java diff --git a/src/main/java/com/northtecom/visatrack/api/base/web/AutoApiResponseBodyAdvice.java b/src/main/java/com/northtecom/visatrack/api/base/web/AutoApiResponseBodyAdvice.java index 67413f2..1b5c721 100644 --- a/src/main/java/com/northtecom/visatrack/api/base/web/AutoApiResponseBodyAdvice.java +++ b/src/main/java/com/northtecom/visatrack/api/base/web/AutoApiResponseBodyAdvice.java @@ -15,7 +15,9 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; * @author Xie Yang * @date 2022/10/02 */ -@RestControllerAdvice(basePackages = {"com.northtecom.visatrack.api.controller.api", "com.northtecom.visatrack.api.controller"}) +@RestControllerAdvice(basePackages = {"com.northtecom.visatrack.api.controller.api", + "com.northtecom.visatrack.api.controller.auth", + "com.northtecom.visatrack.api.controller.vo"}) public class AutoApiResponseBodyAdvice implements ResponseBodyAdvice { @Autowired diff --git a/src/main/java/com/northtecom/visatrack/api/controller/HomeController.java b/src/main/java/com/northtecom/visatrack/api/controller/HomeController.java index 494ae12..73d12c5 100644 --- a/src/main/java/com/northtecom/visatrack/api/controller/HomeController.java +++ b/src/main/java/com/northtecom/visatrack/api/controller/HomeController.java @@ -1,16 +1,16 @@ package com.northtecom.visatrack.api.controller; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.northtecom.visatrack.api.model.request.auth.WeChatVerificationRequest; +import io.swagger.v3.oas.annotations.Operation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; + /** - * Created with IntelliJ IDEA. - * - * @Author: XieYang - * @Date: 2022/10/08/13:30 - * @Description: + * HomeController Endpoint to check service running and wechat verification response */ @Slf4j @RestController @@ -19,7 +19,19 @@ public class HomeController { @GetMapping("/index") public String index() { - log.info("call index"); - return "Hello World 121221!"+System.currentTimeMillis(); + log.debug("Index Api Called"); + return "Welcome To check.visafn.com - " + System.currentTimeMillis(); } + + @GetMapping("/wechat/verification") + @Operation(summary = "Wechat Verification API", description = "Make sure the calling to this API come from WeChat") + public String weChatVerification(WeChatVerificationRequest weChatVerificationRequest) throws JsonProcessingException { + log.debug("Doing WeChat Verification"); + log.debug("signature - [{}]", weChatVerificationRequest.getSignature()); + log.debug("timestamp - [{}]", weChatVerificationRequest.getTimestamp()); + log.debug("nonce - [{}]", weChatVerificationRequest.getNonce()); + + return weChatVerificationRequest.getEchostr(); + } + } diff --git a/src/main/java/com/northtecom/visatrack/api/controller/AuthController.java b/src/main/java/com/northtecom/visatrack/api/controller/auth/AuthController.java similarity index 98% rename from src/main/java/com/northtecom/visatrack/api/controller/AuthController.java rename to src/main/java/com/northtecom/visatrack/api/controller/auth/AuthController.java index 4c3a300..ab46306 100644 --- a/src/main/java/com/northtecom/visatrack/api/controller/AuthController.java +++ b/src/main/java/com/northtecom/visatrack/api/controller/auth/AuthController.java @@ -1,4 +1,4 @@ -package com.northtecom.visatrack.api.controller; +package com.northtecom.visatrack.api.controller.auth; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -16,7 +16,6 @@ import com.northtecom.visatrack.api.util.WeChatUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +30,6 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -import java.io.IOException; import java.util.Date; import java.util.Optional; diff --git a/src/main/java/com/northtecom/visatrack/api/controller/auth/WeChatController.java b/src/main/java/com/northtecom/visatrack/api/controller/auth/WeChatController.java index 948b9a2..e9aa750 100644 --- a/src/main/java/com/northtecom/visatrack/api/controller/auth/WeChatController.java +++ b/src/main/java/com/northtecom/visatrack/api/controller/auth/WeChatController.java @@ -2,11 +2,13 @@ package com.northtecom.visatrack.api.controller.auth; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.northtecom.visatrack.api.controller.vo.BlogSearchVo; import com.northtecom.visatrack.api.controller.vo.UserLoginResponse; import com.northtecom.visatrack.api.controller.vo.VisaTrackUserDetail; import com.northtecom.visatrack.api.data.entity.User; import com.northtecom.visatrack.api.model.entity.wechat.WeChatUser; import com.northtecom.visatrack.api.model.request.auth.WeChatTokenizeRequest; +import com.northtecom.visatrack.api.model.request.auth.WeChatVerificationRequest; import com.northtecom.visatrack.api.service.impl.UserService; import com.northtecom.visatrack.api.service.impl.WeChatService; import io.swagger.v3.oas.annotations.Operation; @@ -64,10 +66,12 @@ public class WeChatController { } + + @GetMapping("/qrconnect") @ResponseBody @Operation(summary = "用户注册接口", description = "用户注册接口,用户注册以后会给用户发送一封邮件,邮件中包含了激活链接,用户点击激活链接以后,用户的账号才会被激活") - public String getWeChatLoginQR() throws JsonProcessingException { + public String getWeChatLoginQR(BlogSearchVo blogSearchVo) throws JsonProcessingException { log.debug("Get WeChat Login QR link"); StringBuffer qrconnect = new StringBuffer(); qrconnect.append("https://open.weixin.qq.com/connect/qrconnect?"); diff --git a/src/main/java/com/northtecom/visatrack/api/model/request/auth/WeChatVerificationRequest.java b/src/main/java/com/northtecom/visatrack/api/model/request/auth/WeChatVerificationRequest.java new file mode 100644 index 0000000..74394c9 --- /dev/null +++ b/src/main/java/com/northtecom/visatrack/api/model/request/auth/WeChatVerificationRequest.java @@ -0,0 +1,42 @@ +package com.northtecom.visatrack.api.model.request.auth; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.northtecom.visatrack.api.controller.vo.BlogSearchVo; +import com.northtecom.visatrack.api.controller.vo.UserLoginResponse; +import com.northtecom.visatrack.api.controller.vo.VisaTrackUserDetail; +import com.northtecom.visatrack.api.data.entity.User; +import com.northtecom.visatrack.api.model.entity.wechat.WeChatUser; +import com.northtecom.visatrack.api.service.impl.UserService; +import com.northtecom.visatrack.api.service.impl.WeChatService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.io.IOException; +import java.util.Date; +import java.util.UUID; + +/** + * + */ +@Getter +@Setter +public class WeChatVerificationRequest { + + private String signature; + private Long timestamp; + private String nonce; + private String echostr; +}