Merge branch 'master' into cc_20251028_decoration
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
package com.cool.store.builder;
|
||||
|
||||
import com.cool.store.config.weixin.WechatMiniappProperties;
|
||||
import com.cool.store.dto.wechat.WechatTemplateMessageDTO;
|
||||
import com.cool.store.enums.wechat.WechatTemplateEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/10/10 14:34
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Component
|
||||
public class TemplateMessageBuilder {
|
||||
|
||||
@Autowired
|
||||
private WechatMiniappProperties wechatMiniappProperties;
|
||||
|
||||
/**
|
||||
* 构建普通模板消息
|
||||
*/
|
||||
public WechatTemplateMessageDTO buildNormalTemplate(String openId,
|
||||
WechatTemplateEnum template,
|
||||
Map<String, Object> data) {
|
||||
WechatTemplateMessageDTO messageDTO = new WechatTemplateMessageDTO();
|
||||
messageDTO.setToUser(openId);
|
||||
messageDTO.setTemplateId(template.getTemplateId());
|
||||
|
||||
// 设置URL(如果data中包含url)
|
||||
if (data.containsKey("url")) {
|
||||
messageDTO.setUrl((String) data.get("url"));
|
||||
}
|
||||
|
||||
// 构建模板数据
|
||||
messageDTO.setData(buildTemplateData(data));
|
||||
|
||||
return messageDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建小程序跳转模板消息
|
||||
*/
|
||||
public WechatTemplateMessageDTO buildMiniappTemplate(String openId,
|
||||
WechatTemplateEnum template,
|
||||
Map<String, Object> data,
|
||||
String miniAppPagePath) {
|
||||
WechatTemplateMessageDTO messageDTO = new WechatTemplateMessageDTO();
|
||||
messageDTO.setToUser(openId);
|
||||
messageDTO.setTemplateId(template.getTemplateId());
|
||||
|
||||
// 设置小程序跳转
|
||||
WechatTemplateMessageDTO.MiniprogramDTO miniProgram = new WechatTemplateMessageDTO.MiniprogramDTO();
|
||||
miniProgram.setAppid(wechatMiniappProperties.getAppId());
|
||||
miniProgram.setPagepath(miniAppPagePath != null ? miniAppPagePath : wechatMiniappProperties.getDefaultPagePath());
|
||||
messageDTO.setMiniprogram(miniProgram);
|
||||
|
||||
// 设置备用URL(如果data中包含url)
|
||||
if (data.containsKey("url")) {
|
||||
messageDTO.setUrl((String) data.get("url"));
|
||||
}
|
||||
|
||||
// 构建模板数据
|
||||
messageDTO.setData(buildTemplateData(data));
|
||||
|
||||
return messageDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建小程序跳转模板消息(带备用URL)
|
||||
*/
|
||||
public WechatTemplateMessageDTO buildMiniAppTemplateWithUrl(String openId,
|
||||
WechatTemplateEnum template,
|
||||
Map<String, Object> data,
|
||||
String miniAppPagePath,
|
||||
String backupUrl) {
|
||||
WechatTemplateMessageDTO messageDTO = buildMiniappTemplate(openId, template, data, miniAppPagePath);
|
||||
|
||||
// 设置备用URL
|
||||
if (backupUrl != null && !backupUrl.trim().isEmpty()) {
|
||||
messageDTO.setUrl(backupUrl);
|
||||
}
|
||||
|
||||
return messageDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建模板数据
|
||||
*/
|
||||
private Map<String, WechatTemplateMessageDTO.TemplateDataItemDTO> buildTemplateData(Map<String, Object> data) {
|
||||
Map<String, WechatTemplateMessageDTO.TemplateDataItemDTO> templateData = new HashMap<>();
|
||||
|
||||
data.forEach((key, value) -> {
|
||||
if (!"url".equals(key) && value != null) {
|
||||
WechatTemplateMessageDTO.TemplateDataItemDTO item =
|
||||
new WechatTemplateMessageDTO.TemplateDataItemDTO(
|
||||
value.toString(),
|
||||
getColorByField(key)
|
||||
);
|
||||
templateData.put(key, item);
|
||||
}
|
||||
});
|
||||
|
||||
return templateData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段名获取颜色
|
||||
*/
|
||||
private String getColorByField(String fieldName) {
|
||||
switch (fieldName) {
|
||||
case "amount":
|
||||
case "refundAmount":
|
||||
case "couponValue":
|
||||
case "character_string2":
|
||||
return "#FF0000"; // 金额类字段用红色
|
||||
case "orderNo":
|
||||
case "expressNo":
|
||||
return "#173177"; // 编号类字段用蓝色
|
||||
default:
|
||||
return "#333333"; // 默认用深灰色
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.cool.store.config.weixin;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/10/10 14:41
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "wechat.miniapp")
|
||||
public class WechatMiniappProperties {
|
||||
|
||||
/**
|
||||
* 小程序appId
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 小程序页面路径
|
||||
*/
|
||||
private String defaultPagePath ;
|
||||
|
||||
/**
|
||||
* 是否使用小程序跳转
|
||||
*/
|
||||
private boolean enabled = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.cool.store.config.weixin;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/10/10 14:29
|
||||
* @Version 1.0
|
||||
* 微信服务号配置
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "wechat.mp")
|
||||
public class WechatMpProperties {
|
||||
|
||||
/**
|
||||
* 公众号appId
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 公众号appSecret
|
||||
*/
|
||||
private String appSecret;
|
||||
|
||||
/**
|
||||
* 获取access_token的URL
|
||||
*/
|
||||
private String accessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
|
||||
/**
|
||||
* 发送模板消息的URL
|
||||
*/
|
||||
private String sendTemplateMessageUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send";
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.cool.store.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.dao.PartnerUserWechatBindDAO;
|
||||
import com.cool.store.dto.wechat.WechatUserInfoDTO;
|
||||
import com.cool.store.service.wechat.WechatTemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/10/14 14:56
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class WeChatHandler {
|
||||
|
||||
@Resource
|
||||
PartnerUserWechatBindDAO partnerUserWechatBindDAO;
|
||||
@Resource
|
||||
WechatTemplateService wechatTemplateService;
|
||||
|
||||
public Map<String, Object> parseXmlToMap(String xmlContent) throws Exception {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.parse(new InputSource(new StringReader(xmlContent)));
|
||||
|
||||
NodeList nodes = document.getDocumentElement().getChildNodes();
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Node node = nodes.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
String tagName = node.getNodeName();
|
||||
String textContent = node.getTextContent();
|
||||
result.put(tagName, textContent);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public String processMessage(Map<String, Object> messageMap) {
|
||||
String msgType = (String) messageMap.get("MsgType");
|
||||
String event = (String) messageMap.get("Event");
|
||||
|
||||
switch (msgType) {
|
||||
case "event":
|
||||
return handleEvent(messageMap);
|
||||
|
||||
// case "text":
|
||||
// return handleTextMessage(message);
|
||||
//
|
||||
// case "image":
|
||||
// return handleImageMessage(message);
|
||||
|
||||
default:
|
||||
// 其他类型的消息直接回复success
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
private String handleEvent(Map<String, Object> messageMap) {
|
||||
String event = (String) messageMap.get("Event");
|
||||
String fromUserName = (String) messageMap.get("FromUserName");
|
||||
String toUserName = (String) messageMap.get("ToUserName");
|
||||
|
||||
switch (event) {
|
||||
case "subscribe":
|
||||
// 关注事件 - 绑定用户
|
||||
return handleSubscribeEvent(fromUserName,toUserName);
|
||||
|
||||
case "unsubscribe":
|
||||
// 取消关注事件 - 解绑用户
|
||||
return handleUnsubscribeEvent(fromUserName,toUserName);
|
||||
|
||||
default:
|
||||
return buildWelcomeReply(fromUserName, toUserName);
|
||||
}
|
||||
}
|
||||
|
||||
private String handleSubscribeEvent(String fromUserName,String toUserName) {
|
||||
try {
|
||||
|
||||
//根据openId 获取用户信息
|
||||
WechatUserInfoDTO userInfo = wechatTemplateService.getUserInfo(fromUserName, null);
|
||||
|
||||
log.info("handleSubscribeEvent: {}", JSONObject.toJSONString(userInfo));
|
||||
|
||||
//根据unionId 更新服务号ID
|
||||
if (userInfo != null) {
|
||||
partnerUserWechatBindDAO.updateByUnionId(userInfo.getUnionid(),fromUserName);
|
||||
}
|
||||
|
||||
// 立即回复欢迎消息
|
||||
return buildWelcomeReply(fromUserName, toUserName);
|
||||
|
||||
} catch (Exception e) {
|
||||
// 即使处理失败也要返回success
|
||||
return buildWelcomeReply(fromUserName, toUserName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理取消关注事件
|
||||
*/
|
||||
private String handleUnsubscribeEvent(String fromUserName,String toUserName) {
|
||||
|
||||
// 异步处理用户解绑
|
||||
//userBindingService.unbindOfficialAccountUser(openId);
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
private String buildSuccessReply(String fromUser, String toUser) {
|
||||
return String.format(
|
||||
"<xml>" +
|
||||
"<ToUserName><![CDATA[%s]]></ToUserName>" +
|
||||
"<FromUserName><![CDATA[%s]]></FromUserName>" +
|
||||
"<CreateTime>%d</CreateTime>" +
|
||||
"<MsgType><![CDATA[text]]></MsgType>" +
|
||||
"<Content><![CDATA[success]]></Content>" +
|
||||
"</xml>",
|
||||
fromUser, toUser, System.currentTimeMillis() / 1000
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private String buildWelcomeReply(String fromUser, String toUser) {
|
||||
return String.format(
|
||||
"<xml>" +
|
||||
"<ToUserName><![CDATA[%s]]></ToUserName>" +
|
||||
"<FromUserName><![CDATA[%s]]></FromUserName>" +
|
||||
"<CreateTime>%d</CreateTime>" +
|
||||
"<MsgType><![CDATA[text]]></MsgType>" +
|
||||
"<Content><![CDATA[欢迎关注!您已成功绑定通知服务,可以接收小程序的重要消息通知。]]></Content>" +
|
||||
"</xml>",
|
||||
fromUser, toUser, System.currentTimeMillis() / 1000
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -73,6 +73,8 @@ public class BuildInformationServiceImpl implements BuildInformationService {
|
||||
private OrderSysInfoDAO orderSysInfoDAO;
|
||||
@Autowired
|
||||
private BigRegionDAO bigRegionDAO;
|
||||
@Resource
|
||||
private AcceptanceInfoDAO acceptanceInfoDAO;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -252,7 +254,14 @@ public class BuildInformationServiceImpl implements BuildInformationService {
|
||||
if (StringUtils.isBlank(response.getAddresseeAddress())) {
|
||||
response.setAddresseeAddress(shopInfo.getDetailAddress());
|
||||
}
|
||||
|
||||
// 不存在的情况下从装修验收中获取
|
||||
if (StringUtils.isBlank(response.getDoorPhoto()) || StringUtils.isBlank(response.getInStorePhoto())) {
|
||||
AcceptanceInfoDO acceptanceInfoDO = acceptanceInfoDAO.selectByShopId(shopId);
|
||||
if (Objects.nonNull(acceptanceInfoDO)) {
|
||||
response.setDoorPhoto(StringUtils.isNotBlank(response.getDoorPhoto()) ? response.getDoorPhoto() : acceptanceInfoDO.getShopDoorwayPhoto());
|
||||
response.setInStorePhoto(StringUtils.isNotBlank(response.getInStorePhoto()) ? response.getInStorePhoto() : acceptanceInfoDO.getShopInteriorPhoto());
|
||||
}
|
||||
}
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.dao.*;
|
||||
import com.cool.store.entity.*;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
@@ -10,14 +12,12 @@ import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.request.*;
|
||||
import com.cool.store.service.DecorationDesignInfoService;
|
||||
import com.cool.store.utils.poi.StringUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -40,6 +40,8 @@ public class DecorationDesignInfoServiceImpl implements DecorationDesignInfoServ
|
||||
private ShopStageInfoDAO shopStageInfoDAO;
|
||||
@Resource
|
||||
private LineInfoDAO lineInfoDAO;
|
||||
@Resource
|
||||
private BuildInformationDAO buildInformationDAO;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -277,8 +279,28 @@ public class DecorationDesignInfoServiceImpl implements DecorationDesignInfoServ
|
||||
if (shopSubStageInfo.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_122.getShopSubStageStatus())) {
|
||||
shopStageInfoDAO.updateShopStageInfo(shopInfoDO.getId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_123);
|
||||
}
|
||||
// 覆盖建店资料中的门头照和内景照
|
||||
BuildInformationDO buildInformation = BuildInformationDO.builder().shopId(request.getShopId()).doorPhoto(buildJson(request.getShopDoorwayPhotoUrl()))
|
||||
.inStorePhoto(buildJson(request.getShopInteriorPhotoUrl())).build();
|
||||
buildInformationDAO.updateByShopIdSelective(buildInformation);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String buildJson(List<String> urls) {
|
||||
if (CollectionUtils.isEmpty(urls)) {
|
||||
return null;
|
||||
}
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (String url : urls) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("url", url);
|
||||
jsonObject.put("type", extractImageSuffix(url));
|
||||
jsonArray.add(jsonObject);
|
||||
}
|
||||
return jsonArray.toJSONString();
|
||||
}
|
||||
|
||||
public String extractImageSuffix(String url) {
|
||||
return url.substring(url.lastIndexOf(".") + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@ import com.cool.store.dto.notice.MessageTemplateCountDTO;
|
||||
import com.cool.store.dto.notice.NoticeDTO;
|
||||
import com.cool.store.dto.store.AuthStoreUserDTO;
|
||||
import com.cool.store.dto.store.StoreAreaDTO;
|
||||
import com.cool.store.dto.wechat.ServiceAccountOpenIdDTO;
|
||||
import com.cool.store.entity.*;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.enums.notice.*;
|
||||
import com.cool.store.enums.wechat.WechatTemplateDetailEnum;
|
||||
import com.cool.store.enums.wechat.WechatTemplateEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.mapper.StoreGroupMappingMapper;
|
||||
import com.cool.store.mapper.StoreMapper;
|
||||
@@ -19,12 +22,16 @@ import com.cool.store.request.notice.*;
|
||||
import com.cool.store.response.bigdata.ApiResponse;
|
||||
import com.cool.store.service.MessageTemplateService;
|
||||
import com.cool.store.service.StoreService;
|
||||
import com.cool.store.service.wechat.WechatTemplateService;
|
||||
import com.cool.store.utils.CoolDateUtils;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.cool.store.utils.poi.DateUtils;
|
||||
import com.cool.store.vo.PartnerUserInfoVO;
|
||||
import com.cool.store.vo.notice.*;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -67,10 +74,14 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
|
||||
@Resource
|
||||
MatterConfigDAO matterConfigDAO;
|
||||
@Resource
|
||||
WechatTemplateService wechatTemplateService;
|
||||
@Resource
|
||||
RedisUtilPool redisUtilPool;
|
||||
@Resource
|
||||
TaskExecutor noticeThreadPool;
|
||||
@Resource
|
||||
HyPartnerUserInfoDAO hyPartnerUserInfoDAO;
|
||||
@Resource
|
||||
MessageIssueService messageIssueService;
|
||||
|
||||
|
||||
@@ -210,10 +221,38 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
|
||||
JSONObject.toJSONString(request.getStoreInfoList()),
|
||||
JSONObject.toJSONString(request.getUserInfoList()),
|
||||
userId);
|
||||
|
||||
//发送通知
|
||||
Set<String> userIds = authUser.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
|
||||
|
||||
//分批 查询用户信息
|
||||
List<String> openIdList = new ArrayList<>();
|
||||
Lists.partition(new ArrayList<>(userIds), 100).forEach(x->{
|
||||
List<EnterpriseUserDO> userInfoByUserIds = enterpriseUserDAO.getUserInfoByUserIds(x);
|
||||
//取出用户的手机号,过滤掉空的手机号
|
||||
List<String> mobileList = userInfoByUserIds.stream().filter(user -> StringUtils.isNotBlank(user.getMobile())).map(EnterpriseUserDO::getMobile).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(mobileList)){
|
||||
List<ServiceAccountOpenIdDTO> serviceAccountOpenIdDTOS = hyPartnerUserInfoDAO.selectLastBindRecord(mobileList);
|
||||
if (CollectionUtils.isNotEmpty(serviceAccountOpenIdDTOS)){
|
||||
//服务号ID
|
||||
openIdList.addAll(serviceAccountOpenIdDTOS.stream().map(ServiceAccountOpenIdDTO::getServiceAccountOpenId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
MessageTemplateDO messageTemplateDO = list.get(0);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put(WechatTemplateDetailEnum.THING6.getCode(), messageTemplateDO.getMessageTitle());
|
||||
data.put(WechatTemplateDetailEnum.TIME33.getCode(), DateUtils.parseDateToStr(DateUtils.SPECIAL_DATE_START, new Date()));
|
||||
data.put(WechatTemplateDetailEnum.CHARACTER_STRING14.getCode(), messageTemplateDO.getMessageCode());
|
||||
openIdList.forEach(x->{
|
||||
wechatTemplateService.sendMiniAppTemplate(x, WechatTemplateEnum.NEW_QUESTION_NOTICE,data,"pages/notification/index");
|
||||
});
|
||||
// 即时消息下发
|
||||
messageIssueService.issueMessage(realtimeMessageList);
|
||||
} catch (Exception e) {
|
||||
log.info("发布流程异常,已取消发布");
|
||||
log.info("发布流程异常 e:{}",e.getMessage());
|
||||
} finally {
|
||||
releaseLocks(lockKeys);
|
||||
log.info("发布流程结束,已释放Redis锁");
|
||||
|
||||
@@ -273,6 +273,18 @@ public class SyncDataServiceImpl implements SyncDataService {
|
||||
} catch (Exception e) {
|
||||
log.info("getUrl error:{},JSON:{}", e.getMessage(), json);
|
||||
}
|
||||
return getUrlListByComma(json);
|
||||
}
|
||||
|
||||
private static List<String> getUrlListByComma(String str) {
|
||||
if (StringUtils.isBlank(str)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Arrays.asList(str.split(","));
|
||||
} catch (Exception e) {
|
||||
log.info("getUrlListByComma error:{},str:{}", e.getMessage(), str);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,9 +111,16 @@ public class WechatMiniAppServiceImpl implements WechatMiniAppService {
|
||||
PartnerUserWechatBindDO bindDO = new PartnerUserWechatBindDO();
|
||||
bindDO.setBindTime(new Date());
|
||||
bindDO.setOpenId(openid);
|
||||
bindDO.setUnionId(unionId);
|
||||
bindDO.setPartnerId(hyPartnerUserInfoDO.getPartnerId());
|
||||
bindDO.setCreateTime(new Date());
|
||||
partnerUserWechatBindDAO.insertSelective(bindDO);
|
||||
}else {
|
||||
//维护unionId 针对老数据没有unionId
|
||||
if (zlPartnerUserBindDO.getUnionId()==null){
|
||||
zlPartnerUserBindDO.setUnionId(unionId);
|
||||
partnerUserWechatBindDAO.update(zlPartnerUserBindDO);
|
||||
}
|
||||
}
|
||||
BeanUtil.copyProperties(hyPartnerUserInfoDO, userInfoVO);
|
||||
fillLineInfo(userInfoVO, hyPartnerUserInfoDO.getPartnerId());
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.cool.store.service.wechat;
|
||||
|
||||
import com.cool.store.builder.TemplateMessageBuilder;
|
||||
import com.cool.store.config.weixin.WechatMpProperties;
|
||||
import com.cool.store.dto.wechat.AccessTokenDTO;
|
||||
import com.cool.store.dto.wechat.WechatTemplateMessageDTO;
|
||||
import com.cool.store.dto.wechat.WechatUserInfoDTO;
|
||||
import com.cool.store.enums.wechat.WechatTemplateEnum;
|
||||
import com.cool.store.utils.OkHttpUtil;
|
||||
import com.cool.store.utils.poi.StringUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/10/10 14:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WechatTemplateService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private WechatMpProperties wechatMpProperties;
|
||||
|
||||
@Autowired
|
||||
private TemplateMessageBuilder templateMessageBuilder;
|
||||
|
||||
@Autowired
|
||||
private OkHttpUtil okHttpUtil;
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
public String getAccessToken() {
|
||||
String url = String.format("%s?grant_type=client_credential&appid=%s&secret=%s",
|
||||
wechatMpProperties.getAccessTokenUrl(),
|
||||
wechatMpProperties.getAppId(),
|
||||
wechatMpProperties.getAppSecret());
|
||||
try {
|
||||
String result = okHttpUtil.doGet(url);
|
||||
log.info("获取access_token响应: {}", result);
|
||||
|
||||
if (StringUtils.isNotEmpty( result)){
|
||||
AccessTokenDTO responseDTO = objectMapper.readValue(result, AccessTokenDTO.class);
|
||||
return responseDTO.getAccess_token();
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
log.error("获取access_token失败", e);
|
||||
} catch (Exception e) {
|
||||
log.error("解析access_token响应失败", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WechatUserInfoDTO getUserInfo(String openId, String lang) {
|
||||
String accessToken = getAccessToken();
|
||||
//默认中国
|
||||
lang = StringUtils.isEmpty(lang)?"zh_CN":lang;
|
||||
if (accessToken == null) {
|
||||
log.error("获取access_token失败");
|
||||
return null;
|
||||
}
|
||||
String url = String.format("https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s",
|
||||
accessToken, openId);
|
||||
|
||||
if (lang != null && !lang.trim().isEmpty()) {
|
||||
url += "&lang=" + lang;
|
||||
}
|
||||
try {
|
||||
String result = okHttpUtil.doGet(url);
|
||||
log.debug("获取用户信息响应: {}", result);
|
||||
WechatUserInfoDTO userInfo = objectMapper.readValue(result, WechatUserInfoDTO.class);
|
||||
return userInfo;
|
||||
} catch (IOException e) {
|
||||
log.error("获取用户信息失败", e);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("解析用户信息响应失败", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean sendNormalTemplate(String openId, WechatTemplateEnum template, Map<String, Object> data) {
|
||||
WechatTemplateMessageDTO messageDTO = templateMessageBuilder.buildNormalTemplate(openId, template, data);
|
||||
return sendTemplateMessage(messageDTO);
|
||||
}
|
||||
|
||||
public boolean sendMiniAppTemplate(String openId, WechatTemplateEnum template,
|
||||
Map<String, Object> data, String miniAppPagePath) {
|
||||
WechatTemplateMessageDTO messageDTO = templateMessageBuilder.buildMiniappTemplate(
|
||||
openId, template, data, miniAppPagePath);
|
||||
return sendTemplateMessage(messageDTO);
|
||||
}
|
||||
|
||||
public boolean sendMiniAppTemplateWithUrl(String openId, WechatTemplateEnum template,
|
||||
Map<String, Object> data, String miniAppPagePath, String backupUrl) {
|
||||
WechatTemplateMessageDTO messageDTO = templateMessageBuilder.buildMiniAppTemplateWithUrl(
|
||||
openId, template, data, miniAppPagePath, backupUrl);
|
||||
return sendTemplateMessage(messageDTO);
|
||||
}
|
||||
|
||||
private boolean sendTemplateMessage(WechatTemplateMessageDTO messageDTO) {
|
||||
String accessToken = getAccessToken();
|
||||
if (accessToken == null) {
|
||||
log.error("获取access_token失败,无法发送模板消息");
|
||||
return false;
|
||||
}
|
||||
|
||||
String url = String.format("%s?access_token=%s",
|
||||
wechatMpProperties.getSendTemplateMessageUrl(), accessToken);
|
||||
|
||||
log.info("发送模板消息: {}", messageDTO);
|
||||
try {
|
||||
String result = okHttpUtil.doPostJson(url, messageDTO);
|
||||
log.info("发送模板消息响应: {}", result);
|
||||
|
||||
return Boolean.TRUE;
|
||||
} catch (Exception e) {
|
||||
log.error("解析模板消息响应失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user