|
@@ -1,5 +1,6 @@
|
|
|
package org.springblade.weChat.officialAccount;
|
|
package org.springblade.weChat.officialAccount;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -8,13 +9,14 @@ import org.springblade.weChat.Util.WXPayXmlUtil;
|
|
|
import org.springblade.weChat.Util.WxUtil;
|
|
import org.springblade.weChat.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.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import org.springblade.weChat.template.entity.WechatMessageTemplate;
|
|
|
|
|
+import org.springblade.weChat.template.service.IWechatMessageTemplateService;
|
|
|
|
|
+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.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
import java.util.TreeMap;
|
|
|
|
|
|
|
@@ -25,17 +27,18 @@ import java.util.TreeMap;
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@RestController
|
|
@RestController
|
|
|
-@RequestMapping("/wechatTest")
|
|
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
|
public class WxUnionIdOpenIdController {
|
|
public class WxUnionIdOpenIdController {
|
|
|
|
|
|
|
|
private final IWxUnionIdOpenIdClient wxUnionIdOpenIdClient;
|
|
private final IWxUnionIdOpenIdClient wxUnionIdOpenIdClient;
|
|
|
|
|
|
|
|
|
|
+ private final IWechatMessageTemplateService wechatMessageTemplateService;
|
|
|
|
|
+
|
|
|
//公众号的appId以及secret
|
|
//公众号的appId以及secret
|
|
|
private static final String appId = "wxf077390a6ec17f23";
|
|
private static final String appId = "wxf077390a6ec17f23";
|
|
|
private static final String appSecret = "50e84930675a0c06057d45a6d64ec548";
|
|
private static final String appSecret = "50e84930675a0c06057d45a6d64ec548";
|
|
|
|
|
|
|
|
- @PostMapping("/scanCodeCallback")
|
|
|
|
|
|
|
+ @RequestMapping(value = "/wechatTest/scanCodeCallback", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
public void scanCodeCallback(HttpServletRequest request, HttpServletResponse response) {
|
|
public void scanCodeCallback(HttpServletRequest request, HttpServletResponse response) {
|
|
|
log.info("======关注回调======");
|
|
log.info("======关注回调======");
|
|
|
|
|
|
|
@@ -70,7 +73,7 @@ public class WxUnionIdOpenIdController {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @PostMapping("/scanCodeCallbackQB")
|
|
|
|
|
|
|
+ @RequestMapping(value = "/wechatTest/scanCodeCallbackQB", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
public String checkWxTokenQB(HttpServletRequest request, HttpServletResponse response) {
|
|
public String checkWxTokenQB(HttpServletRequest request, HttpServletResponse response) {
|
|
|
try {
|
|
try {
|
|
|
//通知传输的编码为GBK
|
|
//通知传输的编码为GBK
|
|
@@ -90,28 +93,28 @@ public class WxUnionIdOpenIdController {
|
|
|
log.info("返回数据======>>" + map);
|
|
log.info("返回数据======>>" + map);
|
|
|
String openId = map.get("openid");
|
|
String openId = map.get("openid");
|
|
|
|
|
|
|
|
- //获得公众号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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //获得公众号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);
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
if (ObjectUtils.isNotNull(request.getParameter("echostr"))) {
|
|
if (ObjectUtils.isNotNull(request.getParameter("echostr"))) {
|
|
|
return request.getParameter("echostr");
|
|
return request.getParameter("echostr");
|
|
|
} else {
|
|
} else {
|
|
@@ -119,7 +122,7 @@ public class WxUnionIdOpenIdController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @PostMapping("/scanCodeCallbackLT")
|
|
|
|
|
|
|
+ @RequestMapping(value = "/wechatTest/scanCodeCallbackLT", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
public String checkWxTokenLT(HttpServletRequest request, HttpServletResponse response) {
|
|
public String checkWxTokenLT(HttpServletRequest request, HttpServletResponse response) {
|
|
|
try {
|
|
try {
|
|
|
//通知传输的编码为GBK
|
|
//通知传输的编码为GBK
|
|
@@ -139,28 +142,86 @@ public class WxUnionIdOpenIdController {
|
|
|
log.info("返回数据======>>" + map);
|
|
log.info("返回数据======>>" + map);
|
|
|
String openId = map.get("openid");
|
|
String openId = map.get("openid");
|
|
|
|
|
|
|
|
- //获得公众号token
|
|
|
|
|
- Map<String, String> tokenMap = WxUtil.getToken("wxd2b063ae955ea05f", "38d6e2dadc583c289b8eb81eb9281510");
|
|
|
|
|
|
|
+ //获得公众号token
|
|
|
|
|
+ Map<String, String> tokenMap = WxUtil.getToken("wxd2b063ae955ea05f", "38d6e2dadc583c289b8eb81eb9281510");
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtils.isNotNull(request.getParameter("echostr"))) {
|
|
|
|
|
+ return request.getParameter("echostr");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- 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");
|
|
|
|
|
|
|
+ //福达任务通知
|
|
|
|
|
+ @RequestMapping(value = "/wechatTest/scanCodeCallbackPublic", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
|
|
+ public String checkWxTokenFD(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //通知传输的编码为GBK
|
|
|
|
|
+ request.setCharacterEncoding("UTF-8");
|
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("数据======>>" + request.getParameter("tenantId"));
|
|
|
|
|
+ // 只处理订阅与取消订阅消息
|
|
|
|
|
+ log.info("======关注回调======");
|
|
|
|
|
+ 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 (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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<WechatMessageTemplate> list = wechatMessageTemplateService.list(new LambdaQueryWrapper<WechatMessageTemplate>()
|
|
|
|
|
+ .eq(WechatMessageTemplate::getTenantId, request.getParameter("tenantId"))
|
|
|
|
|
+ .eq(WechatMessageTemplate::getIsDeleted, 0));
|
|
|
|
|
+ if (list.size() == 0) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获得公众号token
|
|
|
|
|
+ Map<String, String> tokenMap = WxUtil.getToken(list.get(0).getOfficialAccount(), list.get(0).getOfficialAccountSecret());
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
if (ObjectUtils.isNotNull(request.getParameter("echostr"))) {
|
|
if (ObjectUtils.isNotNull(request.getParameter("echostr"))) {
|
|
|
return request.getParameter("echostr");
|
|
return request.getParameter("echostr");
|
|
|
} else {
|
|
} else {
|