|
@@ -2,11 +2,11 @@ package com.miaxis.system.controller.test;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
|
+import cn.hutool.json.XML;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.miaxis.common.annotation.Log;
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
-import com.miaxis.common.enums.BusinessTypeEnum;
|
|
|
+import com.miaxis.common.utils.wx.SignUtil;
|
|
|
import com.miaxis.feign.dto.WxTicket;
|
|
|
import com.miaxis.feign.service.IWxMpService;
|
|
|
import com.miaxis.feign.service.IWxSendService;
|
|
@@ -14,14 +14,18 @@ import com.miaxis.wx.service.IWxGzhService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
/**
|
|
|
* @author wwl
|
|
|
* @version 1.0
|
|
@@ -30,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor
|
|
|
@RequestMapping(Constants.OPEN_PREFIX + "/wxTest")
|
|
|
-@Api(tags={"测试"})
|
|
|
+@Api(tags={"wx测试"})
|
|
|
public class TestController {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(TestController.class);
|
|
@@ -44,6 +48,8 @@ public class TestController {
|
|
|
@Autowired
|
|
|
IWxMpService wxMpService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ HttpServletRequest request;
|
|
|
|
|
|
/**
|
|
|
* 生成带参数的二维码
|
|
@@ -75,16 +81,88 @@ public class TestController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 测试
|
|
|
+ * 处理服务器推送消息
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
*/
|
|
|
- @Log(title = "测试", businessType = BusinessTypeEnum.UPDATE)
|
|
|
- @GetMapping("/test")
|
|
|
- @ApiOperation("测试")
|
|
|
- public void test(Object object){
|
|
|
- System.out.println("----test-----"+ object);
|
|
|
- log.info("测试:"+object);
|
|
|
+ @GetMapping(value = "/notifyMsg")
|
|
|
+ @ApiOperation("处理服务器推送消息")
|
|
|
+ public String checkSign(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ String signature = request.getParameter("signature");
|
|
|
+ String timestamp = request.getParameter("timestamp");
|
|
|
+ String nonce = request.getParameter("nonce");
|
|
|
+ String echostr = request.getParameter("echostr");
|
|
|
+ log.info("本身" + signature);
|
|
|
+ if (SignUtil.checkSignature(signature, timestamp, nonce)) {
|
|
|
+
|
|
|
+ //消息处理
|
|
|
+ WexHandeler();
|
|
|
+
|
|
|
+ return echostr;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("验证公众号token失败", e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //微信功能处理
|
|
|
+ public String WexHandeler() throws Exception {
|
|
|
+ try {
|
|
|
+ cn.hutool.json.JSONObject info = XML.toJSONObject(IOUtils.toString(request.getInputStream()));
|
|
|
+ log.info("info:" + info);
|
|
|
+ if (info.get("xml") != null) {
|
|
|
+ JSONObject event = (JSONObject) info.get("xml");
|
|
|
+ if (event.get("MsgType") != null) {
|
|
|
+ String Event = (String) event.get("Event");//事件类型 关注事件还是取消关注等
|
|
|
+ //如果是事件
|
|
|
+ if (!StringUtils.isEmpty(Event)) try {
|
|
|
+ if ("subscribe".equals(Event)) { //带参数二维码的关注事件
|
|
|
+ //关注方法
|
|
|
+ String toUserName = (String) event.get("ToUserName");//开发者微信号
|
|
|
+ String fromUserName = (String) event.get("FromUserName");//发送方帐号(一个OpenID)
|
|
|
+ String eventKey = (String) event.get("EventKey");//事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id
|
|
|
+ String ticket = (String) event.get("Ticket");//二维码的ticket,可用来换取二维码图片
|
|
|
+ log.info(">>>>>>>>>>>>>>>>>>接受的数据为:");
|
|
|
+ log.info("toUserName:" + toUserName);
|
|
|
+ log.info("fromUserName:" + fromUserName);
|
|
|
+ log.info("scene_id:" + eventKey);
|
|
|
+ log.info("ticket:" + ticket);
|
|
|
+ //解析完执行操作
|
|
|
+
|
|
|
+ } else if ("SCAN".equals(Event)) {//扫描带参数二维码事件 用户已关注时的事件推送
|
|
|
+ String toUserName = (String) event.get("ToUserName");//开发者微信号
|
|
|
+ String fromUserName = (String) event.get("FromUserName");//发送方帐号(一个OpenID)
|
|
|
+ String eventKey = (String) event.get("EventKey");//事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id
|
|
|
+ String ticket = (String) event.get("Ticket");//二维码的ticket,可用来换取二维码图片
|
|
|
+ log.info(">>>>>>>>>>>>>>>>>>接受的数据为:");
|
|
|
+ log.info("toUserName:" + toUserName);
|
|
|
+ log.info("fromUserName:" + fromUserName);
|
|
|
+ log.info("scene_id:" + eventKey);
|
|
|
+ log.info("ticket:" + ticket);
|
|
|
+ //解析完执行操作
|
|
|
+
|
|
|
+ } else if ("unsubscribe".equals(Event)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return e.getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return request.getParameter("echostr");
|
|
|
+ }
|
|
|
+ return request.getParameter("echostr");
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|