|
@@ -1,17 +1,23 @@
|
|
|
package org.springblade.school.controller;
|
|
package org.springblade.school.controller;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.cloud.commons.lang.StringUtils;
|
|
|
|
|
+import com.alibaba.nacos.client.naming.utils.SignUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springblade.school.excel.WxEeventType;
|
|
|
|
|
+import org.springblade.school.excel.WxMessageType;
|
|
|
|
|
+import org.springblade.school.excel.WxServiceMsgDto;
|
|
|
import org.springblade.school.util.WxUtil;
|
|
import org.springblade.school.util.WxUtil;
|
|
|
import org.springblade.system.user.entity.WxUnionIdOpenId;
|
|
import org.springblade.system.user.entity.WxUnionIdOpenId;
|
|
|
import org.springblade.system.user.feign.IWxUnionIdOpenIdClient;
|
|
import org.springblade.system.user.feign.IWxUnionIdOpenIdClient;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.school.util.WXPayXmlUtil;
|
|
import org.springblade.school.util.WXPayXmlUtil;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -32,7 +38,7 @@ public class WxUnionIdOpenIdController {
|
|
|
private static final String appSecret = "50e84930675a0c06057d45a6d64ec548";
|
|
private static final String appSecret = "50e84930675a0c06057d45a6d64ec548";
|
|
|
|
|
|
|
|
@PostMapping("/scanCodeCallback")
|
|
@PostMapping("/scanCodeCallback")
|
|
|
- public void scanCodeCallback(HttpServletRequest request, HttpServletResponse response){
|
|
|
|
|
|
|
+ public void scanCodeCallback(HttpServletRequest request, HttpServletResponse response) {
|
|
|
log.info("======关注回调======");
|
|
log.info("======关注回调======");
|
|
|
|
|
|
|
|
Map<String, String> dataMap = WXPayXmlUtil.analysis(request);
|
|
Map<String, String> dataMap = WXPayXmlUtil.analysis(request);
|
|
@@ -42,21 +48,21 @@ public class WxUnionIdOpenIdController {
|
|
|
|
|
|
|
|
if ("subscribe".equals(Event)) {//关注
|
|
if ("subscribe".equals(Event)) {//关注
|
|
|
//获得公众号token
|
|
//获得公众号token
|
|
|
- Map<String,String> tokenMap = WxUtil.getToken(appId, appSecret);
|
|
|
|
|
|
|
+ Map<String, String> tokenMap = WxUtil.getToken(appId, appSecret);
|
|
|
|
|
|
|
|
//根据公众号openid获得unionId
|
|
//根据公众号openid获得unionId
|
|
|
- Map<String, String > userMap = WxUtil.getUserInfo(tokenMap.get("accessToken"),openId);
|
|
|
|
|
|
|
+ Map<String, String> userMap = WxUtil.getUserInfo(tokenMap.get("accessToken"), openId);
|
|
|
String unionId = userMap.get("unionid");
|
|
String unionId = userMap.get("unionid");
|
|
|
|
|
|
|
|
- if (ObjectUtil.isNotEmpty(unionId)){
|
|
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(unionId)) {
|
|
|
//根据unionId查询数据库是否存在
|
|
//根据unionId查询数据库是否存在
|
|
|
WxUnionIdOpenId wxUnionIdOpenId = wxUnionIdOpenIdClient.getWxUnionId(unionId);
|
|
WxUnionIdOpenId wxUnionIdOpenId = wxUnionIdOpenIdClient.getWxUnionId(unionId);
|
|
|
- if (ObjectUtil.isEmpty(wxUnionIdOpenId)){//不存在 新增
|
|
|
|
|
|
|
+ if (ObjectUtil.isEmpty(wxUnionIdOpenId)) {//不存在 新增
|
|
|
WxUnionIdOpenId item = new WxUnionIdOpenId();
|
|
WxUnionIdOpenId item = new WxUnionIdOpenId();
|
|
|
item.setOpenId(openId);
|
|
item.setOpenId(openId);
|
|
|
item.setUnionId(unionId);
|
|
item.setUnionId(unionId);
|
|
|
wxUnionIdOpenIdClient.insertWxUO(item);
|
|
wxUnionIdOpenIdClient.insertWxUO(item);
|
|
|
- }else {//存在 则更新
|
|
|
|
|
|
|
+ } else {//存在 则更新
|
|
|
wxUnionIdOpenId.setOpenId(openId);
|
|
wxUnionIdOpenId.setOpenId(openId);
|
|
|
wxUnionIdOpenIdClient.updateWxUO(wxUnionIdOpenId);
|
|
wxUnionIdOpenIdClient.updateWxUO(wxUnionIdOpenId);
|
|
|
}
|
|
}
|
|
@@ -66,4 +72,38 @@ public class WxUnionIdOpenIdController {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @PostMapping(value = "/scanCodeCallbackQB")
|
|
|
|
|
+ public void checkWxToken(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ // 只处理订阅与取消订阅消息
|
|
|
|
|
+ log.info("======关注回调======");
|
|
|
|
|
+ Map<String, String> dataMap = WXPayXmlUtil.analysis(request);
|
|
|
|
|
+ log.info("返回数据======>>" + dataMap);
|
|
|
|
|
+ String openId = dataMap.get("FromUserName");//openId
|
|
|
|
|
+ String Event = dataMap.get("Event");//关注或取消关注
|
|
|
|
|
+
|
|
|
|
|
+ if ("subscribe".equals(Event)) {//关注
|
|
|
|
|
+ //获得公众号token
|
|
|
|
|
+ Map<String, String> tokenMap = WxUtil.getToken("wx0d55134f5ad8b0ec", "6764b4e6b6d0143d2309109110e91b28");
|
|
|
|
|
+
|
|
|
|
|
+ log.info("获得公众号token======>>" + tokenMap);
|
|
|
|
|
+ //根据公众号openid获得unionId
|
|
|
|
|
+ Map<String, String> userMap = WxUtil.getUserInfo(tokenMap.get("accessToken"), openId);
|
|
|
|
|
+ log.info("根据公众号openid获得unionId======>>" + userMap);
|
|
|
|
|
+ String unionId = userMap.get("unionid");
|
|
|
|
|
+
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(unionId)) {
|
|
|
|
|
+ //根据unionId查询数据库是否存在
|
|
|
|
|
+ WxUnionIdOpenId wxUnionIdOpenId = wxUnionIdOpenIdClient.getWxUnionId(unionId);
|
|
|
|
|
+ if (ObjectUtil.isEmpty(wxUnionIdOpenId)) {//不存在 新增
|
|
|
|
|
+ WxUnionIdOpenId item = new WxUnionIdOpenId();
|
|
|
|
|
+ item.setOpenId(openId);
|
|
|
|
|
+ item.setUnionId(unionId);
|
|
|
|
|
+ wxUnionIdOpenIdClient.insertWxUO(item);
|
|
|
|
|
+ } else {//存在 则更新
|
|
|
|
|
+ wxUnionIdOpenId.setOpenId(openId);
|
|
|
|
|
+ wxUnionIdOpenIdClient.updateWxUO(wxUnionIdOpenId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|