Althars123 vor 3 Jahren
Ursprung
Commit
67ad2b6a62

+ 27 - 14
twzd-admin/src/main/java/com/miaxis/app/controller/wx/WxgzhController.java

@@ -8,12 +8,12 @@ import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 /**
  * 微信公众号相关
@@ -42,14 +42,13 @@ public class WxgzhController {
 
 
     /**
-     * 处理服务器推送消息
+     * 获取微信验签
      * @param request
-     * @param response
      * @return
      */
-    @RequestMapping(value = "/notifyMsg",method = { RequestMethod.GET, RequestMethod.POST })
-    @ApiOperation("处理服务器推送消息")
-    public String checkSign(HttpServletRequest request, HttpServletResponse response) {
+    @GetMapping(value = "/notifyMsg")
+    @ApiOperation("获取微信验签")
+    public String checkSign(HttpServletRequest request) {
         log.info("-----------进入---------");
         try {
             String signature = request.getParameter("signature");
@@ -57,13 +56,8 @@ public class WxgzhController {
             String nonce = request.getParameter("nonce");
             String echostr = request.getParameter("echostr");
             log.info("本身" + signature);
-            if(request.getMethod().equals("GET")){
-                log.info("-----------微信验签---------");
-                return SignUtil.checkSignature(signature, timestamp, nonce) == true ? echostr : null;
-            }else{
-                log.info("-----------推送消息处理---------");
-                return wxGzhService.handlePublicMsg(request);
-            }
+            log.info("-----------微信验签---------");
+            return SignUtil.checkSignature(signature, timestamp, nonce) == true ? echostr : null;
         } catch (Exception e) {
             log.error("验证公众号token失败", e);
         }
@@ -71,4 +65,23 @@ public class WxgzhController {
     }
 
 
+    /**
+     * 处理服务器推送消息
+     * @param request
+     * @return
+     */
+    @PostMapping(value = "/notifyMsg")
+    @ApiOperation("处理服务器推送消息")
+    public String dealNotify(HttpServletRequest request) {
+        log.info("-----------进入---------");
+        try {
+            log.info("-----------推送消息处理---------");
+            return wxGzhService.handlePublicMsg(request);
+        } catch (Exception e) {
+            log.error("处理推送消息失败", e);
+        }
+        return null;
+    }
+
+
 }

+ 5 - 3
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxGzhServiceImpl.java

@@ -1,5 +1,6 @@
 package com.miaxis.wx.service.impl;
 
+import cn.hutool.json.XML;
 import com.alibaba.fastjson.JSONObject;
 import com.miaxis.common.constant.Constants;
 import com.miaxis.common.core.domain.entity.UserInfo;
@@ -13,6 +14,7 @@ import com.miaxis.wx.service.IWxMessageEvenService;
 import com.qcloud.cos.COSClient;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
@@ -87,11 +89,11 @@ public class WxGzhServiceImpl implements IWxGzhService {
     public String handlePublicMsg(HttpServletRequest request) {
         try {
             log.info("1....");
-//            cn.hutool.json.JSONObject decryptMap = XML.toJSONObject(IOUtils.toString(request.getInputStream()));
-//            cn.hutool.json.JSONObject jsonObjectData = decryptMap.getJSONObject("xml");
+            cn.hutool.json.JSONObject decryptMap = XML.toJSONObject(IOUtils.toString(request.getInputStream()));
+            cn.hutool.json.JSONObject jsonObjectData = decryptMap.getJSONObject("xml");
 
 
-            cn.hutool.json.JSONObject jsonObjectData = new cn.hutool.json.JSONObject("{\"CreateTime\":1639474955,\"EventKey\":\"https://jpcj-h5.zzxcx.net\",\"ToUserName\":\"gh_628da25a95e5\",\"MsgType\":\"event\",\"MenuId\":442656773,\"Event\":\"VIEW\",\"FromUserName\":\"ovKTX50v7OAEPI_ERofpUvrNQCJU\"}");
+            //cn.hutool.json.JSONObject jsonObjectData = new cn.hutool.json.JSONObject("{\"CreateTime\":1639474955,\"EventKey\":\"https://jpcj-h5.zzxcx.net\",\"ToUserName\":\"gh_628da25a95e5\",\"MsgType\":\"event\",\"MenuId\":442656773,\"Event\":\"VIEW\",\"FromUserName\":\"ovKTX50v7OAEPI_ERofpUvrNQCJU\"}");
             log.info("2-----jsonObjectData------"+jsonObjectData);