|
|
@@ -1,24 +1,25 @@
|
|
|
package org.springblade.school.controller;
|
|
|
|
|
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
|
|
-import com.alibaba.nacos.client.naming.utils.SignUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.school.excel.WxEeventType;
|
|
|
import org.springblade.school.excel.WxMessageType;
|
|
|
import org.springblade.school.excel.WxServiceMsgDto;
|
|
|
+import org.springblade.school.util.WXPayXmlUtil;
|
|
|
import org.springblade.school.util.WxUtil;
|
|
|
import org.springblade.system.user.entity.WxUnionIdOpenId;
|
|
|
import org.springblade.system.user.feign.IWxUnionIdOpenIdClient;
|
|
|
-import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
-import org.springblade.school.util.WXPayXmlUtil;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
|
|
|
/**
|
|
|
* 与微信公众号产生交换的控制器
|
|
|
@@ -72,16 +73,26 @@ public class WxUnionIdOpenIdController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @PostMapping(value = "/scanCodeCallbackQB")
|
|
|
- public void checkWxTokenQB(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ @PostMapping("/scanCodeCallbackQB")
|
|
|
+ public String checkWxTokenQB(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ //通知传输的编码为GBK
|
|
|
+ request.setCharacterEncoding("UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
// 只处理订阅与取消订阅消息
|
|
|
log.info("======关注回调======");
|
|
|
- Map<String, String> dataMap = WXPayXmlUtil.analysis(request);
|
|
|
- log.info("返回数据======>>" + dataMap);
|
|
|
- String openId = dataMap.get("FromUserName");//openId
|
|
|
- String Event = dataMap.get("Event");//关注或取消关注
|
|
|
+ TreeMap<String, String> map = new TreeMap<String, String>();
|
|
|
+ Map reqMap = request.getParameterMap();
|
|
|
+ for (Object key : reqMap.keySet()) {
|
|
|
+ String value = ((String[]) reqMap.get(key))[0];
|
|
|
+ System.out.println(key + ";" + value);
|
|
|
+ map.put(key.toString(), value);
|
|
|
+ }
|
|
|
+ log.info("返回数据======>>" + map);
|
|
|
+ String openId = map.get("openid");
|
|
|
|
|
|
- if ("subscribe".equals(Event)) {//关注
|
|
|
//获得公众号token
|
|
|
Map<String, String> tokenMap = WxUtil.getToken("wx0d55134f5ad8b0ec", "6764b4e6b6d0143d2309109110e91b28");
|
|
|
|
|
|
@@ -104,19 +115,33 @@ public class WxUnionIdOpenIdController {
|
|
|
wxUnionIdOpenIdClient.updateWxUO(wxUnionIdOpenId);
|
|
|
}
|
|
|
}
|
|
|
+ if (ObjectUtils.isNotNull(request.getParameter("echostr"))) {
|
|
|
+ return request.getParameter("echostr");
|
|
|
+ } else {
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @PostMapping(value = "/scanCodeCallbackLT")
|
|
|
- public void checkWxTokenLT(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ @PostMapping("/scanCodeCallbackLT")
|
|
|
+ public String checkWxTokenLT(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ //通知传输的编码为GBK
|
|
|
+ request.setCharacterEncoding("UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
// 只处理订阅与取消订阅消息
|
|
|
log.info("======关注回调======");
|
|
|
- Map<String, String> dataMap = WXPayXmlUtil.analysis(request);
|
|
|
- log.info("返回数据======>>" + dataMap);
|
|
|
- String openId = dataMap.get("FromUserName");//openId
|
|
|
- String Event = dataMap.get("Event");//关注或取消关注
|
|
|
+ TreeMap<String, String> map = new TreeMap<String, String>();
|
|
|
+ Map reqMap = request.getParameterMap();
|
|
|
+ for (Object key : reqMap.keySet()) {
|
|
|
+ String value = ((String[]) reqMap.get(key))[0];
|
|
|
+ System.out.println(key + ";" + value);
|
|
|
+ map.put(key.toString(), value);
|
|
|
+ }
|
|
|
+ log.info("返回数据======>>" + map);
|
|
|
+ String openId = map.get("openid");
|
|
|
|
|
|
- if ("subscribe".equals(Event)) {//关注
|
|
|
//获得公众号token
|
|
|
Map<String, String> tokenMap = WxUtil.getToken("wxd2b063ae955ea05f", "38d6e2dadc583c289b8eb81eb9281510");
|
|
|
|
|
|
@@ -129,7 +154,7 @@ public class WxUnionIdOpenIdController {
|
|
|
if (ObjectUtil.isNotEmpty(unionId)) {
|
|
|
//根据unionId查询数据库是否存在
|
|
|
WxUnionIdOpenId wxUnionIdOpenId = wxUnionIdOpenIdClient.getWxUnionId(unionId);
|
|
|
- if (ObjectUtil.isEmpty(wxUnionIdOpenId)) {//不存在 新增
|
|
|
+ if (ObjectUtil.isEmpty(wxUnionIdOpenId)) {
|
|
|
WxUnionIdOpenId item = new WxUnionIdOpenId();
|
|
|
item.setOpenId(openId);
|
|
|
item.setUnionId(unionId);
|
|
|
@@ -139,6 +164,10 @@ public class WxUnionIdOpenIdController {
|
|
|
wxUnionIdOpenIdClient.updateWxUO(wxUnionIdOpenId);
|
|
|
}
|
|
|
}
|
|
|
+ if (ObjectUtils.isNotNull(request.getParameter("echostr"))) {
|
|
|
+ return request.getParameter("echostr");
|
|
|
+ } else {
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|
|
|
}
|