From 4c846ef4ce4567dd7ea7c14eda70a888d5e73cda Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 30 Jul 2024 15:40:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91MALL:?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E9=80=80=E6=AC=BE=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/social/AppSocialUserController.java | 2 +- .../pay/enums/MessageTemplateConstants.java | 3 +- .../wallet/PayWalletRechargeServiceImpl.java | 41 +++++++++++++------ .../system/api/social/SocialClientApi.java | 8 ++-- ... SocialWxaSubscribeMessageSendReqDTO.java} | 13 +----- ...=> SocialWxaSubscribeTemplateRespDTO.java} | 2 +- .../api/social/SocialClientApiImpl.java | 21 ++++------ .../admin/socail/SocialClientController.java | 6 +-- .../service/social/SocialClientService.java | 4 +- .../social/SocialClientServiceImpl.java | 13 +++--- 10 files changed, 60 insertions(+), 53 deletions(-) rename yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/{SocialWxSubscribeMessageSendReqDTO.java => SocialWxaSubscribeMessageSendReqDTO.java} (78%) rename yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/{SocialWxSubscribeTemplateRespDTO.java => SocialWxaSubscribeTemplateRespDTO.java} (91%) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java index b3b045171c..e8de23c2b6 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java +++ b/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 { @GetMapping("/get-subscribe-template-list") @Operation(summary = "获得微信小程订阅模板列表") public CommonResult> getSubscribeTemplateList() { - List template = socialClientApi.getSubscribeTemplateList(UserTypeEnum.MEMBER.getValue()); + List template = socialClientApi.getWxaSubscribeTemplateList(UserTypeEnum.MEMBER.getValue()); return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class)); } diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java index bf28724dce..7031f1d427 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java +++ b/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 { //======================= 小程序订阅消息 ======================= - String PAY_WALLET_CHANGE = "充值成功通知"; + String WALLET_RECHARGER_PAID = "充值成功通知"; + String WALLET_RECHARGE_REFUNDED = "退款申请通知"; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java index 6213b90787..a5d1cec3d2 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java +++ b/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; 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) { diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java index 07aedd3bac..3324eea09d 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java +++ b/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 { */ SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url); + //======================= 微信小程序独有 ======================= + /** * 获得微信小程序的手机信息 * @@ -49,20 +51,18 @@ public interface SocialClientApi { */ byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO); - // TODO @puhui999:要不是统一都叫 getWxaSubscribeTemplateList、SocialWxaSubscribeTemplateRespDTO /** * 获得微信小程订阅模板 * * @return 小程序订阅消息模版 */ - List getSubscribeTemplateList(Integer userType); + List getWxaSubscribeTemplateList(Integer userType); - // TODO @puhui999:sendWxaSubscribeMessage、SocialWxaSubscribeMessageSendReqDTO;然后不传递 socialType;就是专门给微信小程序的 /** * 发送微信小程序订阅消息 * * @param reqDTO 请求 */ - void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO); + void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageSendReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeMessageSendReqDTO.java similarity index 78% rename from yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageSendReqDTO.java rename to yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeMessageSendReqDTO.java index 66ef781efc..2677a3485a 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageSendReqDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeMessageSendReqDTO.java @@ -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 messages; - public SocialWxSubscribeMessageSendReqDTO addMessage(String key, String value) { + public SocialWxaSubscribeMessageSendReqDTO addMessage(String key, String value) { if (messages == null) { messages = new HashMap<>(); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeTemplateRespDTO.java similarity index 91% rename from yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java rename to yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeTemplateRespDTO.java index d4b7bdde2d..ae14cc5432 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxaSubscribeTemplateRespDTO.java @@ -9,7 +9,7 @@ import lombok.Data; * @author HUIHUI */ @Data -public class SocialWxSubscribeTemplateRespDTO { +public class SocialWxaSubscribeTemplateRespDTO { /** * 模版编号 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java index 71af73f473..b69221a0c6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java +++ b/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; 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 getSubscribeTemplateList(Integer userType) { + public List getWxaSubscribeTemplateList(Integer userType) { List 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 templateList = getSubscribeTemplateList(reqDTO.getUserType()); + List 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; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java index aedc3282ce..e91a3d8a0b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java +++ b/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; 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); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java index 6f34808693..ff4e95a982 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java +++ b/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; 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; @@ -87,7 +87,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); // =================== 客户端管理 =================== diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java index ac115448f8..552faf8655 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java +++ b/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; 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,7 +19,7 @@ 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; @@ -276,7 +277,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 +294,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 messages = reqDTO.getMessages(); if (CollUtil.isNotEmpty(messages)) { From 5307852fb2c826c07ca06d207d9ce665d18fca2e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 30 Jul 2024 16:05:25 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91SYSTEM:?= =?UTF-8?q?=20=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=AE=A2=E9=98=85=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E8=8E=B7=E5=8F=96=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/system/dal/redis/RedisKeyConstants.java | 9 +++++++++ .../system/service/social/SocialClientService.java | 3 +++ .../system/service/social/SocialClientServiceImpl.java | 3 +++ 3 files changed, 15 insertions(+) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/redis/RedisKeyConstants.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/redis/RedisKeyConstants.java index 4964a2be24..1cd58306b6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/redis/RedisKeyConstants.java +++ b/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 { * VALUE 数据格式:String 模版信息 */ String SMS_TEMPLATE = "sms_template"; + + /** + * 小程序订阅模版的缓存 + * + * KEY 格式:wxa_subscribe_template:{userType} + * VALUE 数据格式 String, 模版信息 + */ + String WXA_SUBSCRIBE_TEMPLATE = "wxa_subscribe_template"; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java index ff4e95a982..5b293c41c9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java @@ -76,6 +76,9 @@ public interface SocialClientService { /** * 获得微信小程订阅模板 * + * 缓存的目的:考虑到微信小程序订阅消息选择好模版后几乎不会变动,缓存增加查询效率 + * + * @param userType 用户类型 * @return 微信小程订阅模板 */ List getSubscribeTemplateList(Integer userType); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java index 552faf8655..e6474c23d1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java @@ -24,6 +24,7 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialCl 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; @@ -48,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; @@ -265,6 +267,7 @@ public class SocialClientServiceImpl implements SocialClientService { } @Override + @Cacheable(cacheNames = RedisKeyConstants.WXA_SUBSCRIBE_TEMPLATE, key = "#userType", condition = "#result != null") public List getSubscribeTemplateList(Integer userType) { WxMaService service = getWxMaService(userType); try { From 0cca6be63a22f8a3e625356ed3b3daa5f7b1fbaa Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 30 Jul 2024 16:55:58 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91MALL:?= =?UTF-8?q?=20=E8=AE=A2=E5=8D=95=E5=8F=91=E8=B4=A7=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/MessageTemplateConstants.java | 12 +--------- .../order/TradeOrderUpdateServiceImpl.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java index 0aebe56137..1bed7864d3 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java +++ b/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 { //======================= 小程序订阅消息模版 ======================= String TRADE_AFTER_SALE_CHANGE = "售后进度通知"; - - /** - * 售后进度通知相关参数枚举 - * - * @author HUIHUI - */ - class TradeAfterSaleChangeReqParams { - - public static final String ORDER_DELIVERY = "order_delivery"; - - } + String DELIVERY_ORDER = "订单发货通知"; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index c5ab35d62f..a6b206798e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -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())); // 收货地址 } /**