Prechádzať zdrojové kódy

新增微信接口校验

hsj 1 mesiac pred
rodič
commit
20f2130d87

+ 11 - 1
src/main/java/top/husj/husj_wx/controller/WeChatController.java

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