!1024 【新增】MALL: 订单发货订阅消息、钱包退款订阅消息
Merge pull request !1024 from puhui999/develop
This commit is contained in:
commit
9058c152d8
|
@ -17,16 +17,6 @@ public interface MessageTemplateConstants {
|
|||
//======================= 小程序订阅消息模版 =======================
|
||||
|
||||
String TRADE_AFTER_SALE_CHANGE = "售后进度通知";
|
||||
|
||||
/**
|
||||
* 售后进度通知相关参数枚举
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
class TradeAfterSaleChangeReqParams {
|
||||
|
||||
public static final String ORDER_DELIVERY = "order_delivery";
|
||||
|
||||
}
|
||||
String DELIVERY_ORDER = "订单发货通知";
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.yudao.module.trade.service.order;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
@ -19,6 +20,8 @@ import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO;
|
|||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
||||
import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi;
|
||||
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
|
||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO;
|
||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO;
|
||||
|
@ -52,6 +55,7 @@ import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculat
|
|||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -67,6 +71,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.min
|
|||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal;
|
||||
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants.DELIVERY_ORDER;
|
||||
|
||||
/**
|
||||
* 交易订单【写】Service 实现类
|
||||
|
@ -78,6 +83,8 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
|
|||
@Slf4j
|
||||
public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
|
||||
public static final String ORDER_DETAIL_PATH = "pages/order/detail"; // 订单详情页
|
||||
|
||||
@Resource
|
||||
private TradeOrderMapper tradeOrderMapper;
|
||||
@Resource
|
||||
|
@ -103,6 +110,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||
private MemberAddressApi addressApi;
|
||||
@Resource
|
||||
private ProductCommentApi productCommentApi;
|
||||
@Resource
|
||||
public SocialClientApi socialClientApi;
|
||||
|
||||
@Resource
|
||||
private TradeOrderProperties tradeOrderProperties;
|
||||
|
@ -367,6 +376,21 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||
// 4. 发送站内信
|
||||
tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO()
|
||||
.setOrderId(order.getId()).setUserId(order.getUserId()).setMessage(null));
|
||||
// 5. 发送订阅消息
|
||||
getSelf().sendDeliveryOrderMessage(order, deliveryReqVO);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendDeliveryOrderMessage(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) {
|
||||
// 构建并发送模版消息
|
||||
Long orderId = order.getId();
|
||||
socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(ORDER_DETAIL_PATH + "?id=" + orderId)
|
||||
.setUserId(order.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setTemplateTitle(DELIVERY_ORDER)
|
||||
.addMessage("character_string3", String.valueOf(orderId)) // 订单编号
|
||||
.addMessage("phrase6", TradeOrderStatusEnum.DELIVERED.getName()) // 订单状态
|
||||
.addMessage("date4", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))// 发货时间
|
||||
.addMessage("character_string5", deliveryReqVO.getLogisticsNo()) // 快递单号
|
||||
.addMessage("thing9", order.getReceiverDetailAddress())); // 收货地址
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,7 @@ public class AppSocialUserController {
|
|||
@GetMapping("/get-subscribe-template-list")
|
||||
@Operation(summary = "获得微信小程订阅模板列表")
|
||||
public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplateList() {
|
||||
List<SocialWxSubscribeTemplateRespDTO> template = socialClientApi.getSubscribeTemplateList(UserTypeEnum.MEMBER.getValue());
|
||||
List<SocialWxaSubscribeTemplateRespDTO> template = socialClientApi.getWxaSubscribeTemplateList(UserTypeEnum.MEMBER.getValue());
|
||||
return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class));
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ public interface MessageTemplateConstants {
|
|||
|
||||
//======================= 小程序订阅消息 =======================
|
||||
|
||||
String PAY_WALLET_CHANGE = "充值成功通知";
|
||||
String WALLET_RECHARGER_PAID = "充值成功通知";
|
||||
String WALLET_RECHARGE_REFUNDED = "退款申请通知";
|
||||
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
|
|||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
|
||||
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
@ -40,7 +39,8 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString
|
|||
import static cn.iocoder.yudao.framework.common.util.number.MoneyUtils.fenToYuanStr;
|
||||
import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.PAY_WALLET_CHANGE;
|
||||
import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGER_PAID;
|
||||
import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGE_REFUNDED;
|
||||
import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*;
|
||||
|
||||
/**
|
||||
|
@ -140,21 +140,20 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
|
|||
PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice());
|
||||
|
||||
// 4. 发送订阅消息
|
||||
getSelf().sendPayWalletChangeMessage(payOrderId, walletRecharge);
|
||||
getSelf().sendWalletRechargerPaidMessage(payOrderId, walletRecharge);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendPayWalletChangeMessage(Long payOrderId, PayWalletRechargeDO walletRecharge) {
|
||||
public void sendWalletRechargerPaidMessage(Long payOrderId, PayWalletRechargeDO walletRecharge) {
|
||||
// 1. 获得会员钱包信息
|
||||
PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId());
|
||||
// 2. 构建并发送模版消息
|
||||
socialClientApi.sendSubscribeMessage(new SocialWxSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH)
|
||||
.setUserId(wallet.getUserId()).setUserType(wallet.getUserType())
|
||||
.setTemplateTitle(PAY_WALLET_CHANGE).setSocialType(SocialTypeEnum.WECHAT_MINI_APP.getType())
|
||||
.addMessage("character_string1", String.valueOf(payOrderId))
|
||||
.addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice()))
|
||||
.addMessage("time3", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))
|
||||
.addMessage("phrase4", "充值成功"));
|
||||
socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH)
|
||||
.setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(WALLET_RECHARGER_PAID)
|
||||
.addMessage("character_string1", String.valueOf(payOrderId)) // 支付单编号
|
||||
.addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) // 充值金额
|
||||
.addMessage("time3", LocalDateTimeUtil.formatNormal(walletRecharge.getCreateTime())) // 充值时间
|
||||
.addMessage("phrase4", "充值成功")); // 充值状态
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -219,6 +218,24 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
|
|||
}
|
||||
// 3. 更新钱包充值的退款字段
|
||||
walletRechargeMapper.updateByIdAndRefunded(id, WAITING.getStatus(), updateObj);
|
||||
|
||||
// 4. 发送订阅消息
|
||||
getSelf().sendWalletRechargeRefundedMessage(walletRecharge.getWalletId(), payRefund);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void sendWalletRechargeRefundedMessage(Long walletId, PayRefundDO payRefund) {
|
||||
// 1. 获得会员钱包信息
|
||||
PayWalletDO wallet = payWalletService.getWallet(walletId);
|
||||
// 2. 构建并发送模版消息
|
||||
String thing8 = PayRefundStatusEnum.isSuccess(payRefund.getStatus()) ? SUCCESS.getName() : FAILURE.getName();
|
||||
socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH)
|
||||
.setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(WALLET_RECHARGE_REFUNDED)
|
||||
.addMessage("character_string1", String.valueOf(payRefund.getId())) // 退款订单编号
|
||||
.addMessage("time7", LocalDateTimeUtil.formatNormal(payRefund.getCreateTime())) // 申请时间
|
||||
.addMessage("amount3", fenToYuanStr(payRefund.getRefundPrice())) // 退款金额
|
||||
.addMessage("thing4", payRefund.getReason()) // 退款原因
|
||||
.addMessage("thing8", thing8 + ",点击卡片查看详情")); // 温馨提示
|
||||
}
|
||||
|
||||
private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) {
|
||||
|
|
|
@ -32,6 +32,8 @@ public interface SocialClientApi {
|
|||
*/
|
||||
SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url);
|
||||
|
||||
//======================= 微信小程序独有 =======================
|
||||
|
||||
/**
|
||||
* 获得微信小程序的手机信息
|
||||
*
|
||||
|
@ -49,20 +51,18 @@ public interface SocialClientApi {
|
|||
*/
|
||||
byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO);
|
||||
|
||||
// TODO @puhui999:要不是统一都叫 getWxaSubscribeTemplateList、SocialWxaSubscribeTemplateRespDTO
|
||||
/**
|
||||
* 获得微信小程订阅模板
|
||||
*
|
||||
* @return 小程序订阅消息模版
|
||||
*/
|
||||
List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType);
|
||||
List<SocialWxaSubscribeTemplateRespDTO> getWxaSubscribeTemplateList(Integer userType);
|
||||
|
||||
// TODO @puhui999:sendWxaSubscribeMessage、SocialWxaSubscribeMessageSendReqDTO;然后不传递 socialType;就是专门给微信小程序的
|
||||
/**
|
||||
* 发送微信小程序订阅消息
|
||||
*
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO);
|
||||
void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.system.api.social.dto;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
@ -15,7 +14,7 @@ import java.util.Map;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class SocialWxSubscribeMessageSendReqDTO {
|
||||
public class SocialWxaSubscribeMessageSendReqDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
|
@ -33,14 +32,6 @@ public class SocialWxSubscribeMessageSendReqDTO {
|
|||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 社交类型
|
||||
*
|
||||
* 枚举 {@link SocialTypeEnum}
|
||||
*/
|
||||
@NotNull(message = "社交类型不能为空")
|
||||
private Integer socialType;
|
||||
|
||||
/**
|
||||
* 消息模版标题
|
||||
*/
|
||||
|
@ -59,7 +50,7 @@ public class SocialWxSubscribeMessageSendReqDTO {
|
|||
*/
|
||||
private Map<String, String> messages;
|
||||
|
||||
public SocialWxSubscribeMessageSendReqDTO addMessage(String key, String value) {
|
||||
public SocialWxaSubscribeMessageSendReqDTO addMessage(String key, String value) {
|
||||
if (messages == null) {
|
||||
messages = new HashMap<>();
|
||||
}
|
|
@ -9,7 +9,7 @@ import lombok.Data;
|
|||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class SocialWxSubscribeTemplateRespDTO {
|
||||
public class SocialWxaSubscribeTemplateRespDTO {
|
||||
|
||||
/**
|
||||
* 模版编号
|
|
@ -6,12 +6,12 @@ import cn.hutool.core.util.ObjUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.*;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
@ -30,11 +30,6 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
|
|||
@Slf4j
|
||||
public class SocialClientApiImpl implements SocialClientApi {
|
||||
|
||||
/**
|
||||
* 小程序版本
|
||||
*/
|
||||
@Value("${yudao.wxa-code.env-version}")
|
||||
public String envVersion;
|
||||
@Resource
|
||||
private SocialClientService socialClientService;
|
||||
@Resource
|
||||
|
@ -51,6 +46,8 @@ public class SocialClientApiImpl implements SocialClientApi {
|
|||
return BeanUtils.toBean(signature, SocialWxJsapiSignatureRespDTO.class);
|
||||
}
|
||||
|
||||
//======================= 微信小程序独有 =======================
|
||||
|
||||
@Override
|
||||
public SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode) {
|
||||
WxMaPhoneNumberInfo info = socialClientService.getWxMaPhoneNumberInfo(userType, phoneCode);
|
||||
|
@ -63,21 +60,21 @@ public class SocialClientApiImpl implements SocialClientApi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType) {
|
||||
public List<SocialWxaSubscribeTemplateRespDTO> getWxaSubscribeTemplateList(Integer userType) {
|
||||
List<TemplateInfo> list = socialClientService.getSubscribeTemplateList(userType);
|
||||
return convertList(list, item -> BeanUtils.toBean(item, SocialWxSubscribeTemplateRespDTO.class).setId(item.getPriTmplId()));
|
||||
return convertList(list, item -> BeanUtils.toBean(item, SocialWxaSubscribeTemplateRespDTO.class).setId(item.getPriTmplId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO) {
|
||||
public void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO) {
|
||||
// 1.1 获得订阅模版列表
|
||||
List<SocialWxSubscribeTemplateRespDTO> templateList = getSubscribeTemplateList(reqDTO.getUserType());
|
||||
List<SocialWxaSubscribeTemplateRespDTO> templateList = getWxaSubscribeTemplateList(reqDTO.getUserType());
|
||||
if (CollUtil.isEmpty(templateList)) {
|
||||
log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
|
||||
return;
|
||||
}
|
||||
// 1.2 获得需要使用的模版
|
||||
SocialWxSubscribeTemplateRespDTO template = findOne(templateList, item ->
|
||||
SocialWxaSubscribeTemplateRespDTO template = findOne(templateList, item ->
|
||||
ObjUtil.equal(item.getTitle(), reqDTO.getTemplateTitle()));
|
||||
if (template == null) {
|
||||
log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
|
||||
|
@ -86,7 +83,7 @@ public class SocialClientApiImpl implements SocialClientApi {
|
|||
|
||||
// 2. 获得社交用户
|
||||
SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(),
|
||||
reqDTO.getSocialType());
|
||||
SocialTypeEnum.WECHAT_MINI_APP.getType());
|
||||
if (StrUtil.isBlankIfStr(socialUser.getOpenid())) {
|
||||
log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO);
|
||||
return;
|
||||
|
|
|
@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
|
||||
|
@ -76,8 +76,8 @@ public class SocialClientController {
|
|||
@PostMapping("/send-subscribe-message")
|
||||
@Operation(summary = "发送订阅消息") // 用于测试
|
||||
@PreAuthorize("@ss.hasPermission('system:social-client:query')")
|
||||
public void sendSubscribeMessage(@RequestBody SocialWxSubscribeMessageSendReqDTO reqDTO) {
|
||||
socialClientApi.sendSubscribeMessage(reqDTO);
|
||||
public void sendSubscribeMessage(@RequestBody SocialWxaSubscribeMessageSendReqDTO reqDTO) {
|
||||
socialClientApi.sendWxaSubscribeMessage(reqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -98,4 +98,13 @@ public interface RedisKeyConstants {
|
|||
* VALUE 数据格式:String 模版信息
|
||||
*/
|
||||
String SMS_TEMPLATE = "sms_template";
|
||||
|
||||
/**
|
||||
* 小程序订阅模版的缓存
|
||||
*
|
||||
* KEY 格式:wxa_subscribe_template:{userType}
|
||||
* VALUE 数据格式 String, 模版信息
|
||||
*/
|
||||
String WXA_SUBSCRIBE_TEMPLATE = "wxa_subscribe_template";
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.service.social;
|
|||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
|
@ -76,6 +76,9 @@ public interface SocialClientService {
|
|||
/**
|
||||
* 获得微信小程订阅模板
|
||||
*
|
||||
* 缓存的目的:考虑到微信小程序订阅消息选择好模版后几乎不会变动,缓存增加查询效率
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @return 微信小程订阅模板
|
||||
*/
|
||||
List<TemplateInfo> getSubscribeTemplateList(Integer userType);
|
||||
|
@ -87,7 +90,7 @@ public interface SocialClientService {
|
|||
* @param templateId 模版编号
|
||||
* @param openId 会员 openId
|
||||
*/
|
||||
void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, String templateId, String openId);
|
||||
void sendSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO, String templateId, String openId);
|
||||
|
||||
// =================== 客户端管理 ===================
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
|
||||
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
@ -18,11 +19,12 @@ import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
|
|||
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
|
||||
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
|
||||
|
@ -47,6 +49,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
|||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -264,6 +267,7 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = RedisKeyConstants.WXA_SUBSCRIBE_TEMPLATE, key = "#userType", condition = "#result != null")
|
||||
public List<TemplateInfo> getSubscribeTemplateList(Integer userType) {
|
||||
WxMaService service = getWxMaService(userType);
|
||||
try {
|
||||
|
@ -276,7 +280,7 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, String templateId, String openId) {
|
||||
public void sendSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO, String templateId, String openId) {
|
||||
WxMaService service = getWxMaService(reqDTO.getUserType());
|
||||
try {
|
||||
WxMaSubscribeService subscribeService = service.getSubscribeService();
|
||||
|
@ -293,13 +297,13 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||
* @param reqDTO 请求
|
||||
* @param templateId 模版编号
|
||||
* @param openId 会员 openId
|
||||
* @return 微信小程序订阅消息发送
|
||||
* @return 微信小程序订阅消息请求参数
|
||||
*/
|
||||
private WxMaSubscribeMessage buildMessageSendReqDTO(SocialWxSubscribeMessageSendReqDTO reqDTO,
|
||||
private WxMaSubscribeMessage buildMessageSendReqDTO(SocialWxaSubscribeMessageSendReqDTO reqDTO,
|
||||
String templateId, String openId) {
|
||||
// 设置订阅消息基本参数
|
||||
WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage().setLang("zh_CN").setMiniprogramState(envVersion)
|
||||
.setTemplateId(templateId).setToUser(openId).setPage(reqDTO.getPage());
|
||||
WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage().setLang(WxMaConstants.MiniProgramLang.ZH_CN)
|
||||
.setMiniprogramState(envVersion).setTemplateId(templateId).setToUser(openId).setPage(reqDTO.getPage());
|
||||
// 设置具体消息参数
|
||||
Map<String, String> messages = reqDTO.getMessages();
|
||||
if (CollUtil.isNotEmpty(messages)) {
|
||||
|
|
Loading…
Reference in New Issue