Răsfoiți Sursa

微信公众号服务器验证

skyline 1 an în urmă
părinte
comite
40fc78bcc7

+ 30 - 25
miniapp/src/main/java/com/kym/miniapp/controller/WeixinMPController.java

@@ -2,15 +2,20 @@ package com.kym.miniapp.controller;
 
 
 import com.kym.common.annotation.ApiLog;
+import com.kym.common.annotation.SysLog;
+import com.kym.common.utils.wx.WxPbUtil;
 import com.kym.service.wechat.WeixinMPService;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import java.io.PrintWriter;
+
 
 @Controller
 @RequestMapping("wx")
@@ -29,7 +34,7 @@ public class WeixinMPController {
      * @param request
      */
 
-    @PostMapping(value = "check", produces = MediaType.TEXT_XML_VALUE)
+    @PostMapping(value = "notify", produces = MediaType.TEXT_XML_VALUE)
     @ApiLog(value = "微信公众号服务器推送消息", ignoreParams = true)
     public void handleMessage(HttpServletRequest request, HttpServletResponse response) {
         weixinMPService.handleWxMPNotify(request, response);
@@ -48,30 +53,30 @@ public class WeixinMPController {
     /**
      * 微信服务器token验证
      */
-//    @GetMapping(value = "check")
-//    @SysLog("微信服务器token验证")
-//    public void checkSign(HttpServletResponse response, String signature, String timestamp, String nonce, String echostr) {
-//        String responseVal = echostr;
-//        try {
-//
-//            boolean resp = WxPbUtil.checkSign(signature, timestamp, nonce);
-//            if (!resp) {
-//                responseVal = "failure";
-//                logger.error("wxpb check sign ERR!!!!");
-//            }
-//        } catch (Exception e) {
-//            responseVal = "failure";
-//        } finally {
-//            try {
-//                PrintWriter writer = response.getWriter();
-//                writer.print(responseVal);
-//                writer.flush();
-//                writer.close();
-//            } catch (Exception e) {
-//                logger.error(e.getMessage(), e);
-//            }
-//        }
-//    }
+    @GetMapping(value = "check")
+    @SysLog("微信服务器token验证")
+    public void checkSign(HttpServletResponse response, String signature, String timestamp, String nonce, String echostr) {
+        String responseVal = echostr;
+        try {
+
+            boolean resp = WxPbUtil.checkSign(signature, timestamp, nonce);
+            if (!resp) {
+                responseVal = "failure";
+                log.error("wxpb check sign ERR!!!!");
+            }
+        } catch (Exception e) {
+            responseVal = "failure";
+        } finally {
+            try {
+                PrintWriter writer = response.getWriter();
+                writer.print(responseVal);
+                writer.flush();
+                writer.close();
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+            }
+        }
+    }
 
 //    @GetMapping(value = "/test")
 //    public void test() throws WxErrorException {