|
@@ -1,17 +1,23 @@
|
|
|
package top.husj.husj_wx.controller;
|
|
package top.husj.husj_wx.controller;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import top.husj.husj_wx.entity.model.WeChatMsg;
|
|
import top.husj.husj_wx.entity.model.WeChatMsg;
|
|
|
import top.husj.husj_wx.exception.AesException;
|
|
import top.husj.husj_wx.exception.AesException;
|
|
|
|
|
+import top.husj.husj_wx.properties.WeChatProperties;
|
|
|
import top.husj.husj_wx.utils.SHA1;
|
|
import top.husj.husj_wx.utils.SHA1;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/wechat")
|
|
@RequestMapping("/wechat")
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class WeChatController {
|
|
public class WeChatController {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WeChatProperties weChatProperties;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// 1. 微信后台验证 URL 时使用 (GET)
|
|
// 1. 微信后台验证 URL 时使用 (GET)
|
|
|
@GetMapping("/callback")
|
|
@GetMapping("/callback")
|
|
|
public String checkSignature(
|
|
public String checkSignature(
|
|
@@ -21,7 +27,7 @@ public class WeChatController {
|
|
|
@RequestParam("echostr") String echostr) throws AesException {
|
|
@RequestParam("echostr") String echostr) throws AesException {
|
|
|
|
|
|
|
|
log.info("收到微信服务器验证请求 - signature: {}, timestamp: {}, nonce: {}",
|
|
log.info("收到微信服务器验证请求 - signature: {}, timestamp: {}, nonce: {}",
|
|
|
- signature, timestamp, nonce);
|
|
|
|
|
|
|
+ weChatProperties.getToken(), timestamp, nonce);
|
|
|
|
|
|
|
|
// 校验签名
|
|
// 校验签名
|
|
|
String sha1 = SHA1.getSHA1("", timestamp, nonce);
|
|
String sha1 = SHA1.getSHA1("", timestamp, nonce);
|
|
@@ -51,4 +57,8 @@ public class WeChatController {
|
|
|
msg.getFromUserName(), msg.getToUserName(), System.currentTimeMillis() / 1000, msg.getContent()
|
|
msg.getFromUserName(), msg.getToUserName(), System.currentTimeMillis() / 1000, msg.getContent()
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static void main(String[] args) throws AesException {
|
|
|
|
|
+ System.out.println(SHA1.getSHA1("12345", "1770626722", "324960664"));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|