From e2c3cac7a8bfbc84e2948c1f8d18d58b81ab518c Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Thu, 5 Jan 2023 08:50:21 -0500 Subject: [PATCH] =?UTF-8?q?USVT-132=20=E6=A0=A1=E9=AA=8C=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=97=E5=88=B0=E7=9A=84=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/HomeController.java | 13 ++++++++---- .../visatrack/api/util/WeChatUtils.java | 21 +++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) 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 e45b2db..f7f0027 100644 --- a/src/main/java/com/northtecom/visatrack/api/controller/HomeController.java +++ b/src/main/java/com/northtecom/visatrack/api/controller/HomeController.java @@ -6,9 +6,7 @@ import io.swagger.v3.oas.annotations.Operation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; /** @@ -31,7 +29,7 @@ public class HomeController { return "Welcome To check.visafn.com - " + System.currentTimeMillis(); } - @GetMapping("/wechat/verification") + @GetMapping("/wechat") @Operation(summary = "Wechat Verification API", description = "Make sure the calling to this API come from WeChat") public String weChatVerification(WeChatVerificationRequest weChatVerificationRequest) { log.debug("Doing WeChat Verification"); @@ -45,4 +43,11 @@ public class HomeController { return StringUtils.EMPTY; } + @PostMapping("/wechat") + @Operation(summary = "Wechat Verification API", description = "Make sure the calling to this API come from WeChat") + public String weChatMessage(@RequestBody String weChatMessage) { + log.debug("Receive message from WeChat - [{}]", weChatMessage); + return "success"; + } + } diff --git a/src/main/java/com/northtecom/visatrack/api/util/WeChatUtils.java b/src/main/java/com/northtecom/visatrack/api/util/WeChatUtils.java index c8ce29a..ed67b6e 100644 --- a/src/main/java/com/northtecom/visatrack/api/util/WeChatUtils.java +++ b/src/main/java/com/northtecom/visatrack/api/util/WeChatUtils.java @@ -30,7 +30,13 @@ public class WeChatUtils { public static final String WECHAT_API_KEY = "appid"; public static final String WECHAT_API_USERNAME = "secret"; - public static final String WECHAT_VERIFICATION_TOKEN = "verification_token"; + public static final String WECHAT_OFFICIAL_ACCOUNT_APP_ID = "official_account_app_id"; + public static final String WECHAT_OFFICIAL_ACCOUNT_SECRET = "official_account_secret"; + + public static final String TEST_WECHAT_OFFICIAL_ACCOUNT_APP_ID = "test_official_account_app_id"; + public static final String TEST_WECHAT_OFFICIAL_ACCOUNT_SECRET = "test_official_account_secret"; + + public static final String WECHAT_OFFICIAL_ACCOUNT_VERIFICATION_TOKEN = "official_account_verification_token"; private Map wechatParameterConfMap = new HashMap(); @@ -39,13 +45,23 @@ public class WeChatUtils { wechatParameterConfMap.put(WECHAT_API_KEY, StringUtils.EMPTY); wechatParameterConfMap.put(WECHAT_API_USERNAME, StringUtils.EMPTY); + //Official Account + wechatParameterConfMap.put(WECHAT_OFFICIAL_ACCOUNT_APP_ID, StringUtils.EMPTY); + wechatParameterConfMap.put(WECHAT_OFFICIAL_ACCOUNT_SECRET, StringUtils.EMPTY); + + //Official Account - Test + wechatParameterConfMap.put(TEST_WECHAT_OFFICIAL_ACCOUNT_APP_ID, StringUtils.EMPTY); + wechatParameterConfMap.put(TEST_WECHAT_OFFICIAL_ACCOUNT_SECRET, StringUtils.EMPTY); + + wechatParameterConfMap.put(WECHAT_OFFICIAL_ACCOUNT_VERIFICATION_TOKEN, StringUtils.EMPTY); + wechatParameterConfMap = awsUtils.getWechatParameterConfValueFromAWS(wechatParameterConfMap); } public String getWechatVerificationSignature(String timestamp, String nonce) { StringBuffer strToSHA1 = new StringBuffer(); - strToSHA1.append(wechatParameterConfMap.get(WECHAT_VERIFICATION_TOKEN)); + strToSHA1.append(wechatParameterConfMap.get(WECHAT_OFFICIAL_ACCOUNT_VERIFICATION_TOKEN)); strToSHA1.append(timestamp); strToSHA1.append(nonce); @@ -66,3 +82,4 @@ public class WeChatUtils { return weChatUser; } } +