浏览代码

新增微信接口校验

hsj 1 月之前
父节点
当前提交
3885a9aae8
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      src/main/java/top/husj/husj_wx/controller/WeChatController.java

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

@@ -26,13 +26,13 @@ public class WeChatController {
             @RequestParam("nonce") String nonce,
             @RequestParam("echostr") String echostr) throws AesException {
 
-        log.info("收到微信服务器验证请求 - signature: {}, timestamp: {}, nonce: {}",
-                signature, timestamp, nonce);
+        log.info("收到微信服务器验证请求 - signature: {}, timestamp: {}, nonce: {}, echostr: {}",
+                signature, timestamp, nonce, echostr);
 
         // 校验签名
-        String sha1 = SHA1.getSHA1(weChatProperties.getToken(), timestamp, nonce);
+        String sha1 = SHA1.getSHA1(weChatProperties.getToken(), timestamp, nonce).trim();
         log.info("本地生成微信服务器签名:{}", sha1);
-        if (sha1.equals(echostr)) {
+        if (sha1.equals(echostr.trim())) {
             log.info("微信服务器验证成功");
             return echostr;
         } else {