Explorar el Código

新增微信接口校验

hsj hace 1 mes
padre
commit
3885a9aae8

+ 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 {