USVT-132 校验微信接受到的消息
This commit is contained in:
parent
54558463bf
commit
e2c3cac7a8
|
@ -6,9 +6,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +29,7 @@ public class HomeController {
|
||||||
return "Welcome To check.visafn.com - " + System.currentTimeMillis();
|
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")
|
@Operation(summary = "Wechat Verification API", description = "Make sure the calling to this API come from WeChat")
|
||||||
public String weChatVerification(WeChatVerificationRequest weChatVerificationRequest) {
|
public String weChatVerification(WeChatVerificationRequest weChatVerificationRequest) {
|
||||||
log.debug("Doing WeChat Verification");
|
log.debug("Doing WeChat Verification");
|
||||||
|
@ -45,4 +43,11 @@ public class HomeController {
|
||||||
return StringUtils.EMPTY;
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,13 @@ public class WeChatUtils {
|
||||||
public static final String WECHAT_API_KEY = "appid";
|
public static final String WECHAT_API_KEY = "appid";
|
||||||
public static final String WECHAT_API_USERNAME = "secret";
|
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<String, String> wechatParameterConfMap = new HashMap<String, String>();
|
private Map<String, String> wechatParameterConfMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
@ -39,13 +45,23 @@ public class WeChatUtils {
|
||||||
wechatParameterConfMap.put(WECHAT_API_KEY, StringUtils.EMPTY);
|
wechatParameterConfMap.put(WECHAT_API_KEY, StringUtils.EMPTY);
|
||||||
wechatParameterConfMap.put(WECHAT_API_USERNAME, 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);
|
wechatParameterConfMap = awsUtils.getWechatParameterConfValueFromAWS(wechatParameterConfMap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWechatVerificationSignature(String timestamp, String nonce) {
|
public String getWechatVerificationSignature(String timestamp, String nonce) {
|
||||||
StringBuffer strToSHA1 = new StringBuffer();
|
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(timestamp);
|
||||||
strToSHA1.append(nonce);
|
strToSHA1.append(nonce);
|
||||||
|
|
||||||
|
@ -66,3 +82,4 @@ public class WeChatUtils {
|
||||||
return weChatUser;
|
return weChatUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue