|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|