Commit 9058c152d899f359f0e53c08d168bd8721c8804f
Committed by
Gitee
!1024 【新增】MALL: 订单发货订阅消息、钱包退款订阅消息
Merge pull request !1024 from puhui999/develop
Showing
13 changed files
with
100 additions
and
64 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
| ... | ... | @@ -17,16 +17,6 @@ public interface MessageTemplateConstants { |
| 17 | 17 | //======================= 小程序订阅消息模版 ======================= |
| 18 | 18 | |
| 19 | 19 | String TRADE_AFTER_SALE_CHANGE = "售后进度通知"; |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 售后进度通知相关参数枚举 | |
| 23 | - * | |
| 24 | - * @author HUIHUI | |
| 25 | - */ | |
| 26 | - class TradeAfterSaleChangeReqParams { | |
| 27 | - | |
| 28 | - public static final String ORDER_DELIVERY = "order_delivery"; | |
| 29 | - | |
| 30 | - } | |
| 20 | + String DELIVERY_ORDER = "订单发货通知"; | |
| 31 | 21 | |
| 32 | 22 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.service.order; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.date.LocalDateTimeUtil; | |
| 4 | 5 | import cn.hutool.core.lang.Assert; |
| 5 | 6 | import cn.hutool.core.map.MapUtil; |
| 6 | 7 | import cn.hutool.core.util.ObjUtil; |
| ... | ... | @@ -19,6 +20,8 @@ import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; |
| 19 | 20 | import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; |
| 20 | 21 | import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; |
| 21 | 22 | import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; |
| 23 | +import cn.iocoder.yudao.module.system.api.social.SocialClientApi; | |
| 24 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; | |
| 22 | 25 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; |
| 23 | 26 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; |
| 24 | 27 | 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 |
| 52 | 55 | import jakarta.annotation.Resource; |
| 53 | 56 | import jakarta.validation.constraints.NotNull; |
| 54 | 57 | import lombok.extern.slf4j.Slf4j; |
| 58 | +import org.springframework.scheduling.annotation.Async; | |
| 55 | 59 | import org.springframework.stereotype.Service; |
| 56 | 60 | import org.springframework.transaction.annotation.Transactional; |
| 57 | 61 | |
| ... | ... | @@ -67,6 +71,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.min |
| 67 | 71 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 68 | 72 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; |
| 69 | 73 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 74 | +import static cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants.DELIVERY_ORDER; | |
| 70 | 75 | |
| 71 | 76 | /** |
| 72 | 77 | * 交易订单【写】Service 实现类 |
| ... | ... | @@ -78,6 +83,8 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 78 | 83 | @Slf4j |
| 79 | 84 | public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 80 | 85 | |
| 86 | + public static final String ORDER_DETAIL_PATH = "pages/order/detail"; // 订单详情页 | |
| 87 | + | |
| 81 | 88 | @Resource |
| 82 | 89 | private TradeOrderMapper tradeOrderMapper; |
| 83 | 90 | @Resource |
| ... | ... | @@ -103,6 +110,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 103 | 110 | private MemberAddressApi addressApi; |
| 104 | 111 | @Resource |
| 105 | 112 | private ProductCommentApi productCommentApi; |
| 113 | + @Resource | |
| 114 | + public SocialClientApi socialClientApi; | |
| 106 | 115 | |
| 107 | 116 | @Resource |
| 108 | 117 | private TradeOrderProperties tradeOrderProperties; |
| ... | ... | @@ -367,6 +376,21 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 367 | 376 | // 4. 发送站内信 |
| 368 | 377 | tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO() |
| 369 | 378 | .setOrderId(order.getId()).setUserId(order.getUserId()).setMessage(null)); |
| 379 | + // 5. 发送订阅消息 | |
| 380 | + getSelf().sendDeliveryOrderMessage(order, deliveryReqVO); | |
| 381 | + } | |
| 382 | + | |
| 383 | + @Async | |
| 384 | + public void sendDeliveryOrderMessage(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { | |
| 385 | + // 构建并发送模版消息 | |
| 386 | + Long orderId = order.getId(); | |
| 387 | + socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(ORDER_DETAIL_PATH + "?id=" + orderId) | |
| 388 | + .setUserId(order.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setTemplateTitle(DELIVERY_ORDER) | |
| 389 | + .addMessage("character_string3", String.valueOf(orderId)) // 订单编号 | |
| 390 | + .addMessage("phrase6", TradeOrderStatusEnum.DELIVERED.getName()) // 订单状态 | |
| 391 | + .addMessage("date4", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))// 发货时间 | |
| 392 | + .addMessage("character_string5", deliveryReqVO.getLogisticsNo()) // 快递单号 | |
| 393 | + .addMessage("thing9", order.getReceiverDetailAddress())); // 收货地址 | |
| 370 | 394 | } |
| 371 | 395 | |
| 372 | 396 | /** | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
| ... | ... | @@ -71,7 +71,7 @@ public class AppSocialUserController { |
| 71 | 71 | @GetMapping("/get-subscribe-template-list") |
| 72 | 72 | @Operation(summary = "获得微信小程订阅模板列表") |
| 73 | 73 | public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplateList() { |
| 74 | - List<SocialWxSubscribeTemplateRespDTO> template = socialClientApi.getSubscribeTemplateList(UserTypeEnum.MEMBER.getValue()); | |
| 74 | + List<SocialWxaSubscribeTemplateRespDTO> template = socialClientApi.getWxaSubscribeTemplateList(UserTypeEnum.MEMBER.getValue()); | |
| 75 | 75 | return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class)); |
| 76 | 76 | } |
| 77 | 77 | ... | ... |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java
| ... | ... | @@ -9,6 +9,7 @@ public interface MessageTemplateConstants { |
| 9 | 9 | |
| 10 | 10 | //======================= 小程序订阅消息 ======================= |
| 11 | 11 | |
| 12 | - String PAY_WALLET_CHANGE = "充值成功通知"; | |
| 12 | + String WALLET_RECHARGER_PAID = "充值成功通知"; | |
| 13 | + String WALLET_RECHARGE_REFUNDED = "退款申请通知"; | |
| 13 | 14 | |
| 14 | 15 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
| ... | ... | @@ -21,8 +21,7 @@ import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum; |
| 21 | 21 | import cn.iocoder.yudao.module.pay.service.order.PayOrderService; |
| 22 | 22 | import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; |
| 23 | 23 | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; |
| 24 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 25 | -import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | |
| 24 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; | |
| 26 | 25 | import jakarta.annotation.Resource; |
| 27 | 26 | import lombok.extern.slf4j.Slf4j; |
| 28 | 27 | import org.springframework.scheduling.annotation.Async; |
| ... | ... | @@ -40,7 +39,8 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString |
| 40 | 39 | import static cn.iocoder.yudao.framework.common.util.number.MoneyUtils.fenToYuanStr; |
| 41 | 40 | import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE; |
| 42 | 41 | import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; |
| 43 | -import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.PAY_WALLET_CHANGE; | |
| 42 | +import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGER_PAID; | |
| 43 | +import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGE_REFUNDED; | |
| 44 | 44 | import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*; |
| 45 | 45 | |
| 46 | 46 | /** |
| ... | ... | @@ -140,21 +140,20 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { |
| 140 | 140 | PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice()); |
| 141 | 141 | |
| 142 | 142 | // 4. 发送订阅消息 |
| 143 | - getSelf().sendPayWalletChangeMessage(payOrderId, walletRecharge); | |
| 143 | + getSelf().sendWalletRechargerPaidMessage(payOrderId, walletRecharge); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | @Async |
| 147 | - public void sendPayWalletChangeMessage(Long payOrderId, PayWalletRechargeDO walletRecharge) { | |
| 147 | + public void sendWalletRechargerPaidMessage(Long payOrderId, PayWalletRechargeDO walletRecharge) { | |
| 148 | 148 | // 1. 获得会员钱包信息 |
| 149 | 149 | PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId()); |
| 150 | 150 | // 2. 构建并发送模版消息 |
| 151 | - socialClientApi.sendSubscribeMessage(new SocialWxSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH) | |
| 152 | - .setUserId(wallet.getUserId()).setUserType(wallet.getUserType()) | |
| 153 | - .setTemplateTitle(PAY_WALLET_CHANGE).setSocialType(SocialTypeEnum.WECHAT_MINI_APP.getType()) | |
| 154 | - .addMessage("character_string1", String.valueOf(payOrderId)) | |
| 155 | - .addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) | |
| 156 | - .addMessage("time3", LocalDateTimeUtil.formatNormal(LocalDateTime.now())) | |
| 157 | - .addMessage("phrase4", "充值成功")); | |
| 151 | + socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH) | |
| 152 | + .setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(WALLET_RECHARGER_PAID) | |
| 153 | + .addMessage("character_string1", String.valueOf(payOrderId)) // 支付单编号 | |
| 154 | + .addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) // 充值金额 | |
| 155 | + .addMessage("time3", LocalDateTimeUtil.formatNormal(walletRecharge.getCreateTime())) // 充值时间 | |
| 156 | + .addMessage("phrase4", "充值成功")); // 充值状态 | |
| 158 | 157 | } |
| 159 | 158 | |
| 160 | 159 | @Override |
| ... | ... | @@ -219,6 +218,24 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { |
| 219 | 218 | } |
| 220 | 219 | // 3. 更新钱包充值的退款字段 |
| 221 | 220 | walletRechargeMapper.updateByIdAndRefunded(id, WAITING.getStatus(), updateObj); |
| 221 | + | |
| 222 | + // 4. 发送订阅消息 | |
| 223 | + getSelf().sendWalletRechargeRefundedMessage(walletRecharge.getWalletId(), payRefund); | |
| 224 | + } | |
| 225 | + | |
| 226 | + @Async | |
| 227 | + public void sendWalletRechargeRefundedMessage(Long walletId, PayRefundDO payRefund) { | |
| 228 | + // 1. 获得会员钱包信息 | |
| 229 | + PayWalletDO wallet = payWalletService.getWallet(walletId); | |
| 230 | + // 2. 构建并发送模版消息 | |
| 231 | + String thing8 = PayRefundStatusEnum.isSuccess(payRefund.getStatus()) ? SUCCESS.getName() : FAILURE.getName(); | |
| 232 | + socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH) | |
| 233 | + .setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(WALLET_RECHARGE_REFUNDED) | |
| 234 | + .addMessage("character_string1", String.valueOf(payRefund.getId())) // 退款订单编号 | |
| 235 | + .addMessage("time7", LocalDateTimeUtil.formatNormal(payRefund.getCreateTime())) // 申请时间 | |
| 236 | + .addMessage("amount3", fenToYuanStr(payRefund.getRefundPrice())) // 退款金额 | |
| 237 | + .addMessage("thing4", payRefund.getReason()) // 退款原因 | |
| 238 | + .addMessage("thing8", thing8 + ",点击卡片查看详情")); // 温馨提示 | |
| 222 | 239 | } |
| 223 | 240 | |
| 224 | 241 | private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) { | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java
| ... | ... | @@ -32,6 +32,8 @@ public interface SocialClientApi { |
| 32 | 32 | */ |
| 33 | 33 | SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url); |
| 34 | 34 | |
| 35 | + //======================= 微信小程序独有 ======================= | |
| 36 | + | |
| 35 | 37 | /** |
| 36 | 38 | * 获得微信小程序的手机信息 |
| 37 | 39 | * |
| ... | ... | @@ -49,20 +51,18 @@ public interface SocialClientApi { |
| 49 | 51 | */ |
| 50 | 52 | byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO); |
| 51 | 53 | |
| 52 | - // TODO @puhui999:要不是统一都叫 getWxaSubscribeTemplateList、SocialWxaSubscribeTemplateRespDTO | |
| 53 | 54 | /** |
| 54 | 55 | * 获得微信小程订阅模板 |
| 55 | 56 | * |
| 56 | 57 | * @return 小程序订阅消息模版 |
| 57 | 58 | */ |
| 58 | - List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType); | |
| 59 | + List<SocialWxaSubscribeTemplateRespDTO> getWxaSubscribeTemplateList(Integer userType); | |
| 59 | 60 | |
| 60 | - // TODO @puhui999:sendWxaSubscribeMessage、SocialWxaSubscribeMessageSendReqDTO;然后不传递 socialType;就是专门给微信小程序的 | |
| 61 | 61 | /** |
| 62 | 62 | * 发送微信小程序订阅消息 |
| 63 | 63 | * |
| 64 | 64 | * @param reqDTO 请求 |
| 65 | 65 | */ |
| 66 | - void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO); | |
| 66 | + void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO); | |
| 67 | 67 | |
| 68 | 68 | } | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageSendReqDTO.java renamed to yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeMessageSendReqDTO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.api.social.dto; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | -import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | |
| 5 | 4 | import jakarta.validation.constraints.NotEmpty; |
| 6 | 5 | import jakarta.validation.constraints.NotNull; |
| 7 | 6 | import lombok.Data; |
| ... | ... | @@ -15,7 +14,7 @@ import java.util.Map; |
| 15 | 14 | * @author HUIHUI |
| 16 | 15 | */ |
| 17 | 16 | @Data |
| 18 | -public class SocialWxSubscribeMessageSendReqDTO { | |
| 17 | +public class SocialWxaSubscribeMessageSendReqDTO { | |
| 19 | 18 | |
| 20 | 19 | /** |
| 21 | 20 | * 用户编号 |
| ... | ... | @@ -34,14 +33,6 @@ public class SocialWxSubscribeMessageSendReqDTO { |
| 34 | 33 | private Integer userType; |
| 35 | 34 | |
| 36 | 35 | /** |
| 37 | - * 社交类型 | |
| 38 | - * | |
| 39 | - * 枚举 {@link SocialTypeEnum} | |
| 40 | - */ | |
| 41 | - @NotNull(message = "社交类型不能为空") | |
| 42 | - private Integer socialType; | |
| 43 | - | |
| 44 | - /** | |
| 45 | 36 | * 消息模版标题 |
| 46 | 37 | */ |
| 47 | 38 | @NotEmpty(message = "消息模版标题不能为空") |
| ... | ... | @@ -59,7 +50,7 @@ public class SocialWxSubscribeMessageSendReqDTO { |
| 59 | 50 | */ |
| 60 | 51 | private Map<String, String> messages; |
| 61 | 52 | |
| 62 | - public SocialWxSubscribeMessageSendReqDTO addMessage(String key, String value) { | |
| 53 | + public SocialWxaSubscribeMessageSendReqDTO addMessage(String key, String value) { | |
| 63 | 54 | if (messages == null) { |
| 64 | 55 | messages = new HashMap<>(); |
| 65 | 56 | } | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java renamed to yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeTemplateRespDTO.java
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
| ... | ... | @@ -6,12 +6,12 @@ import cn.hutool.core.util.ObjUtil; |
| 6 | 6 | import cn.hutool.core.util.StrUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | 8 | import cn.iocoder.yudao.module.system.api.social.dto.*; |
| 9 | +import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | |
| 9 | 10 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; |
| 10 | 11 | import jakarta.annotation.Resource; |
| 11 | 12 | import lombok.extern.slf4j.Slf4j; |
| 12 | 13 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 13 | 14 | import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; |
| 14 | -import org.springframework.beans.factory.annotation.Value; | |
| 15 | 15 | import org.springframework.stereotype.Service; |
| 16 | 16 | import org.springframework.validation.annotation.Validated; |
| 17 | 17 | |
| ... | ... | @@ -30,11 +30,6 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 30 | 30 | @Slf4j |
| 31 | 31 | public class SocialClientApiImpl implements SocialClientApi { |
| 32 | 32 | |
| 33 | - /** | |
| 34 | - * 小程序版本 | |
| 35 | - */ | |
| 36 | - @Value("${yudao.wxa-code.env-version}") | |
| 37 | - public String envVersion; | |
| 38 | 33 | @Resource |
| 39 | 34 | private SocialClientService socialClientService; |
| 40 | 35 | @Resource |
| ... | ... | @@ -51,6 +46,8 @@ public class SocialClientApiImpl implements SocialClientApi { |
| 51 | 46 | return BeanUtils.toBean(signature, SocialWxJsapiSignatureRespDTO.class); |
| 52 | 47 | } |
| 53 | 48 | |
| 49 | + //======================= 微信小程序独有 ======================= | |
| 50 | + | |
| 54 | 51 | @Override |
| 55 | 52 | public SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode) { |
| 56 | 53 | WxMaPhoneNumberInfo info = socialClientService.getWxMaPhoneNumberInfo(userType, phoneCode); |
| ... | ... | @@ -63,21 +60,21 @@ public class SocialClientApiImpl implements SocialClientApi { |
| 63 | 60 | } |
| 64 | 61 | |
| 65 | 62 | @Override |
| 66 | - public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType) { | |
| 63 | + public List<SocialWxaSubscribeTemplateRespDTO> getWxaSubscribeTemplateList(Integer userType) { | |
| 67 | 64 | List<TemplateInfo> list = socialClientService.getSubscribeTemplateList(userType); |
| 68 | - return convertList(list, item -> BeanUtils.toBean(item, SocialWxSubscribeTemplateRespDTO.class).setId(item.getPriTmplId())); | |
| 65 | + return convertList(list, item -> BeanUtils.toBean(item, SocialWxaSubscribeTemplateRespDTO.class).setId(item.getPriTmplId())); | |
| 69 | 66 | } |
| 70 | 67 | |
| 71 | 68 | @Override |
| 72 | - public void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO) { | |
| 69 | + public void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO) { | |
| 73 | 70 | // 1.1 获得订阅模版列表 |
| 74 | - List<SocialWxSubscribeTemplateRespDTO> templateList = getSubscribeTemplateList(reqDTO.getUserType()); | |
| 71 | + List<SocialWxaSubscribeTemplateRespDTO> templateList = getWxaSubscribeTemplateList(reqDTO.getUserType()); | |
| 75 | 72 | if (CollUtil.isEmpty(templateList)) { |
| 76 | 73 | log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO); |
| 77 | 74 | return; |
| 78 | 75 | } |
| 79 | 76 | // 1.2 获得需要使用的模版 |
| 80 | - SocialWxSubscribeTemplateRespDTO template = findOne(templateList, item -> | |
| 77 | + SocialWxaSubscribeTemplateRespDTO template = findOne(templateList, item -> | |
| 81 | 78 | ObjUtil.equal(item.getTitle(), reqDTO.getTemplateTitle())); |
| 82 | 79 | if (template == null) { |
| 83 | 80 | log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO); |
| ... | ... | @@ -86,7 +83,7 @@ public class SocialClientApiImpl implements SocialClientApi { |
| 86 | 83 | |
| 87 | 84 | // 2. 获得社交用户 |
| 88 | 85 | SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(), |
| 89 | - reqDTO.getSocialType()); | |
| 86 | + SocialTypeEnum.WECHAT_MINI_APP.getType()); | |
| 90 | 87 | if (StrUtil.isBlankIfStr(socialUser.getOpenid())) { |
| 91 | 88 | log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO); |
| 92 | 89 | return; | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java
| ... | ... | @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 6 | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; |
| 7 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 7 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; | |
| 8 | 8 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO; |
| 10 | 10 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; |
| ... | ... | @@ -76,8 +76,8 @@ public class SocialClientController { |
| 76 | 76 | @PostMapping("/send-subscribe-message") |
| 77 | 77 | @Operation(summary = "发送订阅消息") // 用于测试 |
| 78 | 78 | @PreAuthorize("@ss.hasPermission('system:social-client:query')") |
| 79 | - public void sendSubscribeMessage(@RequestBody SocialWxSubscribeMessageSendReqDTO reqDTO) { | |
| 80 | - socialClientApi.sendSubscribeMessage(reqDTO); | |
| 79 | + public void sendSubscribeMessage(@RequestBody SocialWxaSubscribeMessageSendReqDTO reqDTO) { | |
| 80 | + socialClientApi.sendWxaSubscribeMessage(reqDTO); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/redis/RedisKeyConstants.java
| ... | ... | @@ -98,4 +98,13 @@ public interface RedisKeyConstants { |
| 98 | 98 | * VALUE 数据格式:String 模版信息 |
| 99 | 99 | */ |
| 100 | 100 | String SMS_TEMPLATE = "sms_template"; |
| 101 | + | |
| 102 | + /** | |
| 103 | + * 小程序订阅模版的缓存 | |
| 104 | + * | |
| 105 | + * KEY 格式:wxa_subscribe_template:{userType} | |
| 106 | + * VALUE 数据格式 String, 模版信息 | |
| 107 | + */ | |
| 108 | + String WXA_SUBSCRIBE_TEMPLATE = "wxa_subscribe_template"; | |
| 109 | + | |
| 101 | 110 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.service.social; |
| 3 | 3 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 6 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 6 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; | |
| 7 | 7 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; |
| ... | ... | @@ -76,6 +76,9 @@ public interface SocialClientService { |
| 76 | 76 | /** |
| 77 | 77 | * 获得微信小程订阅模板 |
| 78 | 78 | * |
| 79 | + * 缓存的目的:考虑到微信小程序订阅消息选择好模版后几乎不会变动,缓存增加查询效率 | |
| 80 | + * | |
| 81 | + * @param userType 用户类型 | |
| 79 | 82 | * @return 微信小程订阅模板 |
| 80 | 83 | */ |
| 81 | 84 | List<TemplateInfo> getSubscribeTemplateList(Integer userType); |
| ... | ... | @@ -87,7 +90,7 @@ public interface SocialClientService { |
| 87 | 90 | * @param templateId 模版编号 |
| 88 | 91 | * @param openId 会员 openId |
| 89 | 92 | */ |
| 90 | - void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, String templateId, String openId); | |
| 93 | + void sendSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO, String templateId, String openId); | |
| 91 | 94 | |
| 92 | 95 | // =================== 客户端管理 =================== |
| 93 | 96 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| ... | ... | @@ -6,6 +6,7 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
| 6 | 6 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 7 | 7 | import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; |
| 8 | 8 | import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; |
| 9 | +import cn.binarywang.wx.miniapp.constant.WxMaConstants; | |
| 9 | 10 | import cn.hutool.core.bean.BeanUtil; |
| 10 | 11 | import cn.hutool.core.collection.CollUtil; |
| 11 | 12 | import cn.hutool.core.lang.Assert; |
| ... | ... | @@ -18,11 +19,12 @@ import cn.iocoder.yudao.framework.common.util.cache.CacheUtils; |
| 18 | 19 | import cn.iocoder.yudao.framework.common.util.http.HttpUtils; |
| 19 | 20 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 20 | 21 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 21 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 22 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxaSubscribeMessageSendReqDTO; | |
| 22 | 23 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; |
| 23 | 24 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; |
| 24 | 25 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; |
| 25 | 26 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; |
| 27 | +import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; | |
| 26 | 28 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 27 | 29 | import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; |
| 28 | 30 | import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; |
| ... | ... | @@ -47,6 +49,7 @@ import me.chanjar.weixin.mp.api.WxMpService; |
| 47 | 49 | import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; |
| 48 | 50 | import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; |
| 49 | 51 | import org.springframework.beans.factory.annotation.Value; |
| 52 | +import org.springframework.cache.annotation.Cacheable; | |
| 50 | 53 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 51 | 54 | import org.springframework.stereotype.Service; |
| 52 | 55 | |
| ... | ... | @@ -264,6 +267,7 @@ public class SocialClientServiceImpl implements SocialClientService { |
| 264 | 267 | } |
| 265 | 268 | |
| 266 | 269 | @Override |
| 270 | + @Cacheable(cacheNames = RedisKeyConstants.WXA_SUBSCRIBE_TEMPLATE, key = "#userType", condition = "#result != null") | |
| 267 | 271 | public List<TemplateInfo> getSubscribeTemplateList(Integer userType) { |
| 268 | 272 | WxMaService service = getWxMaService(userType); |
| 269 | 273 | try { |
| ... | ... | @@ -276,7 +280,7 @@ public class SocialClientServiceImpl implements SocialClientService { |
| 276 | 280 | } |
| 277 | 281 | |
| 278 | 282 | @Override |
| 279 | - public void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, String templateId, String openId) { | |
| 283 | + public void sendSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO, String templateId, String openId) { | |
| 280 | 284 | WxMaService service = getWxMaService(reqDTO.getUserType()); |
| 281 | 285 | try { |
| 282 | 286 | WxMaSubscribeService subscribeService = service.getSubscribeService(); |
| ... | ... | @@ -293,13 +297,13 @@ public class SocialClientServiceImpl implements SocialClientService { |
| 293 | 297 | * @param reqDTO 请求 |
| 294 | 298 | * @param templateId 模版编号 |
| 295 | 299 | * @param openId 会员 openId |
| 296 | - * @return 微信小程序订阅消息发送 | |
| 300 | + * @return 微信小程序订阅消息请求参数 | |
| 297 | 301 | */ |
| 298 | - private WxMaSubscribeMessage buildMessageSendReqDTO(SocialWxSubscribeMessageSendReqDTO reqDTO, | |
| 302 | + private WxMaSubscribeMessage buildMessageSendReqDTO(SocialWxaSubscribeMessageSendReqDTO reqDTO, | |
| 299 | 303 | String templateId, String openId) { |
| 300 | 304 | // 设置订阅消息基本参数 |
| 301 | - WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage().setLang("zh_CN").setMiniprogramState(envVersion) | |
| 302 | - .setTemplateId(templateId).setToUser(openId).setPage(reqDTO.getPage()); | |
| 305 | + WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage().setLang(WxMaConstants.MiniProgramLang.ZH_CN) | |
| 306 | + .setMiniprogramState(envVersion).setTemplateId(templateId).setToUser(openId).setPage(reqDTO.getPage()); | |
| 303 | 307 | // 设置具体消息参数 |
| 304 | 308 | Map<String, String> messages = reqDTO.getMessages(); |
| 305 | 309 | if (CollUtil.isNotEmpty(messages)) { | ... | ... |