|
@@ -2,7 +2,10 @@ package com.care.client.controller;
|
|
|
|
|
|
import cn.hutool.core.util.XmlUtil;
|
|
import cn.hutool.core.util.XmlUtil;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
import com.care.client.dto.TemplateDataDTO;
|
|
import com.care.client.dto.TemplateDataDTO;
|
|
|
|
+import com.care.client.service.PinanbaoContactService;
|
|
|
|
+import com.care.client.vo.HouseContactVO;
|
|
import com.care.client.vo.WxAccessTokenVO;
|
|
import com.care.client.vo.WxAccessTokenVO;
|
|
import com.care.common.cache.RedisKeyConstant;
|
|
import com.care.common.cache.RedisKeyConstant;
|
|
import com.care.common.cache.RedisUtil;
|
|
import com.care.common.cache.RedisUtil;
|
|
@@ -10,6 +13,7 @@ import com.care.common.entity.CareDevice;
|
|
import com.care.common.entity.CareHouseContact;
|
|
import com.care.common.entity.CareHouseContact;
|
|
import com.care.common.service.CareDeviceService;
|
|
import com.care.common.service.CareDeviceService;
|
|
import com.care.common.service.CareHouseContactService;
|
|
import com.care.common.service.CareHouseContactService;
|
|
|
|
+import com.care.common.service.WxQrCodeService;
|
|
import com.care.common.service.WxTemplateService;
|
|
import com.care.common.service.WxTemplateService;
|
|
import com.care.common.util.CheckoutUtil;
|
|
import com.care.common.util.CheckoutUtil;
|
|
import com.care.common.util.MessageUtil;
|
|
import com.care.common.util.MessageUtil;
|
|
@@ -17,6 +21,7 @@ import com.care.common.util.WxTemplateUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
@@ -50,7 +55,7 @@ public class WxMsgController {
|
|
private WxTemplateService wxService;
|
|
private WxTemplateService wxService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- private CareHouseContactService careHouseContactService;
|
|
|
|
|
|
+ private PinanbaoContactService pinanbaoContactService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private WxTemplateService wxTemplateService;
|
|
private WxTemplateService wxTemplateService;
|
|
@@ -61,6 +66,9 @@ public class WxMsgController {
|
|
@Resource
|
|
@Resource
|
|
private CareDeviceService careDeviceService;
|
|
private CareDeviceService careDeviceService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private WxQrCodeService wxQrCodeService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 微信消息接收和token验证
|
|
* 微信消息接收和token验证
|
|
* @param request
|
|
* @param request
|
|
@@ -105,7 +113,8 @@ public class WxMsgController {
|
|
resp.setCharacterEncoding("UTF-8");
|
|
resp.setCharacterEncoding("UTF-8");
|
|
String message = "success";
|
|
String message = "success";
|
|
try {
|
|
try {
|
|
- WxAccessTokenVO wxAccessTokenVO = wxService.processAccessToken();
|
|
|
|
|
|
+// WxAccessTokenVO wxAccessTokenVO = wxService.processAccessToken();
|
|
|
|
+ WxAccessTokenVO wxAccessTokenVO = wxQrCodeService.processOfficialToken();
|
|
if (wxAccessTokenVO == null) {
|
|
if (wxAccessTokenVO == null) {
|
|
return "failure";
|
|
return "failure";
|
|
}
|
|
}
|
|
@@ -122,8 +131,8 @@ public class WxMsgController {
|
|
// String nickName = getUserNickName(fromUserName);
|
|
// String nickName = getUserNickName(fromUserName);
|
|
if(MessageUtil.MSGTYPE_EVENT.equals(msgType)){//如果为事件类型
|
|
if(MessageUtil.MSGTYPE_EVENT.equals(msgType)){//如果为事件类型
|
|
if(MessageUtil.SUBSCIBE_EVENT.equals(eventType)){//处理订阅事件
|
|
if(MessageUtil.SUBSCIBE_EVENT.equals(eventType)){//处理订阅事件
|
|
-// JSONObject parseUnionObject = WxTemplateUtil.parseWxOpenIdBySubscribe(wxAccessTokenVO.getAccessToken(), fromUserName);
|
|
|
|
-// System.out.println("parseUnionObject:"+parseUnionObject.toString());
|
|
|
|
|
|
+ JSONObject parseUnionObject = WxTemplateUtil.parseWxOpenIdBySubscribe(wxAccessTokenVO.getAccessToken(), fromUserName);
|
|
|
|
+ System.out.println("parseUnionObject:" + parseUnionObject.toString());
|
|
// parseUnionObject.set("unionid", "oyVYT6Ox9b88n_33lgKWRj5uFbUY");
|
|
// parseUnionObject.set("unionid", "oyVYT6Ox9b88n_33lgKWRj5uFbUY");
|
|
|
|
|
|
String eventKey = ObjectUtils.toString(map.get("EventKey"));
|
|
String eventKey = ObjectUtils.toString(map.get("EventKey"));
|
|
@@ -146,22 +155,7 @@ public class WxMsgController {
|
|
return "failure";
|
|
return "failure";
|
|
}
|
|
}
|
|
|
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
- // 正式环境
|
|
|
|
- String templateId = "1M1kDRDW-kMSoOzmv9cP-SImD1kXWtezwyWe8euUJIc";
|
|
|
|
- // 测试环境
|
|
|
|
-// String templateId = "gvJ1g3JOThT5IuQc1In6D2cwKwmKz9MBIkGdkXtXOTI";
|
|
|
|
-
|
|
|
|
- Map<String, TemplateDataDTO> data = new HashMap<>();
|
|
|
|
- data.put("first", new TemplateDataDTO("您已关联该监护人", "#459ae9"));
|
|
|
|
- data.put("keyword1", new TemplateDataDTO(careDevice.getDevName(), "#459ae9"));
|
|
|
|
- data.put("keyword2", new TemplateDataDTO(simpleDateFormat.format(new Date()), "#459ae9"));
|
|
|
|
- data.put("remark", new TemplateDataDTO("请补全您的联系信息, 便于能及时收到事件通知", "#459ae9"));
|
|
|
|
-
|
|
|
|
- String openId = fromUserName;
|
|
|
|
- boolean flag = wxTemplateService.sendTemplateMsgOriginal(openId, templateId, "wxda02870032b8f928", "/pages/supplement/index?memberId=" + arrs[1], data);
|
|
|
|
- log.info("发送消息模板: openId: " + openId + ", templateId: " + templateId + " 状态: " + flag);
|
|
|
|
-// if (parseUnionObject != null && parseUnionObject.containsKey("unionid")) {
|
|
|
|
|
|
+ if (parseUnionObject != null) {
|
|
// CareOfficialMemberInfo careOfficialMemberInfo = new CareOfficialMemberInfo();
|
|
// CareOfficialMemberInfo careOfficialMemberInfo = new CareOfficialMemberInfo();
|
|
// careOfficialMemberInfo.setNickname(parseUnionObject.getStr("nickname"));
|
|
// careOfficialMemberInfo.setNickname(parseUnionObject.getStr("nickname"));
|
|
// careOfficialMemberInfo.setOpenId(fromUserName);
|
|
// careOfficialMemberInfo.setOpenId(fromUserName);
|
|
@@ -175,16 +169,40 @@ public class WxMsgController {
|
|
// } else {
|
|
// } else {
|
|
// return "failure";
|
|
// return "failure";
|
|
// }
|
|
// }
|
|
-// CareHouseContact careHouseContact = new CareHouseContact();
|
|
|
|
-// careHouseContact.setContactName(parseUnionObject.getStr("nickname"));
|
|
|
|
-// careHouseContact.setCreateTime(new Date());
|
|
|
|
-// String gender = "";
|
|
|
|
-// if ("1".equalsIgnoreCase(parseUnionObject.getStr("sex"))) {
|
|
|
|
-// gender = "M";
|
|
|
|
-// } else if ("2".equalsIgnoreCase(parseUnionObject.getStr("sex"))) {
|
|
|
|
-// gender = "W";
|
|
|
|
-// }
|
|
|
|
-// careHouseContact.setGender(gender);
|
|
|
|
|
|
+ HouseContactVO houseContactVO = new HouseContactVO();
|
|
|
|
+ houseContactVO.setContactName(parseUnionObject.getStr("nickname"));
|
|
|
|
+ houseContactVO.setCreateTime(new Date());
|
|
|
|
+ String gender = "";
|
|
|
|
+ if ("0".equalsIgnoreCase(parseUnionObject.getStr("sex"))) {
|
|
|
|
+ gender = "M";
|
|
|
|
+ } else if ("1".equalsIgnoreCase(parseUnionObject.getStr("sex"))) {
|
|
|
|
+ gender = "W";
|
|
|
|
+ }
|
|
|
|
+ houseContactVO.setGender(gender);
|
|
|
|
+ houseContactVO.setOpenId(fromUserName);
|
|
|
|
+ houseContactVO.setMemberId(NumberUtils.toLong(arrs[1]));
|
|
|
|
+ boolean saved = pinanbaoContactService.createOrUpdateMyContact(NumberUtils.toLong(arrs[0]), houseContactVO);
|
|
|
|
+ if (!saved) {
|
|
|
|
+ log.error("保存订阅用户出现错误: " + JSONUtil.toJsonStr(houseContactVO));
|
|
|
|
+ return "failure";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ // 正式环境
|
|
|
|
+ String templateId = "W7tT8QGmrBQNVimt6l6w55DBwSH5MBUiFgJxf3gjIV4";
|
|
|
|
+ // 测试环境
|
|
|
|
+// String templateId = "gvJ1g3JOThT5IuQc1In6D2cwKwmKz9MBIkGdkXtXOTI";
|
|
|
|
+
|
|
|
|
+ Map<String, TemplateDataDTO> data = new HashMap<>();
|
|
|
|
+ data.put("first", new TemplateDataDTO("您已关联该监护人", "#459ae9"));
|
|
|
|
+ data.put("keyword1", new TemplateDataDTO(careDevice.getDevName(), "#459ae9"));
|
|
|
|
+ data.put("keyword2", new TemplateDataDTO(simpleDateFormat.format(new Date()), "#459ae9"));
|
|
|
|
+ data.put("remark", new TemplateDataDTO("请补全您的联系信息, 便于能及时收到事件通知", "#459ae9"));
|
|
|
|
+
|
|
|
|
+ String openId = fromUserName;
|
|
|
|
+ log.info("生成小程序跳转URL: " + "/pages/supplement/index?memberId=" + arrs[1] + "&openId=" + fromUserName);
|
|
|
|
+ boolean flag = wxTemplateService.sendTemplateMsgOriginal(openId, templateId, "wxda02870032b8f928", "/pages/supplement/index?memberId=" + arrs[1] + "&openId=" + openId, data);
|
|
|
|
+ log.info("发送消息模板: openId: " + openId + ", templateId: " + templateId + " 状态: " + flag);
|
|
|
|
|
|
// String eventKey = ObjectUtils.toString(map.get("EventKey"));
|
|
// String eventKey = ObjectUtils.toString(map.get("EventKey"));
|
|
// if (StringUtils.isNotBlank(eventKey) && eventKey.indexOf("_") != -1) {
|
|
// if (StringUtils.isNotBlank(eventKey) && eventKey.indexOf("_") != -1) {
|
|
@@ -210,18 +228,18 @@ public class WxMsgController {
|
|
|
|
|
|
// careHouseContactService.save();
|
|
// careHouseContactService.save();
|
|
return "success";
|
|
return "success";
|
|
-// }
|
|
|
|
|
|
+ }
|
|
} else if (MessageUtil.UNSUBSCIBE_EVENT.equals(eventType)) {//处理取消订阅事件
|
|
} else if (MessageUtil.UNSUBSCIBE_EVENT.equals(eventType)) {//处理取消订阅事件
|
|
System.out.println("事件类型为:"+eventType);
|
|
System.out.println("事件类型为:"+eventType);
|
|
- JSONObject parseUnionObject = WxTemplateUtil.parseWxOpenIdBySubscribe(wxAccessTokenVO.getAccessToken(), fromUserName);
|
|
|
|
- if (parseUnionObject != null && parseUnionObject.containsKey("unionid")) {
|
|
|
|
|
|
+// JSONObject parseUnionObject = WxTemplateUtil.parseWxOpenIdBySubscribe(wxAccessTokenVO.getAccessToken(), fromUserName);
|
|
|
|
+// if (parseUnionObject != null && parseUnionObject.containsKey("unionid")) {
|
|
// boolean updated = careOfficialMemberInfoService.cancelSubscribe(parseUnionObject.getStr("unionid"));
|
|
// boolean updated = careOfficialMemberInfoService.cancelSubscribe(parseUnionObject.getStr("unionid"));
|
|
// if (updated) {
|
|
// if (updated) {
|
|
// return "success";
|
|
// return "success";
|
|
// } else {
|
|
// } else {
|
|
// return "failure";
|
|
// return "failure";
|
|
// }
|
|
// }
|
|
- }
|
|
|
|
|
|
+// }
|
|
return "success";
|
|
return "success";
|
|
// message = MessageUtil.unsubscribe(toUserName, fromUserName);
|
|
// message = MessageUtil.unsubscribe(toUserName, fromUserName);
|
|
}
|
|
}
|