Commit a9862b798d44622e3086fd7a753f57921d2c5772
1 parent
3be6ee27
【代码评审】SYSTEM:微信小程序的订阅
Showing
5 changed files
with
22 additions
and
15 deletions
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
| ... | ... | @@ -145,16 +145,16 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { |
| 145 | 145 | |
| 146 | 146 | @Async |
| 147 | 147 | public void sendPayWalletChangeMessage(Long payOrderId, PayWalletRechargeDO walletRecharge) { |
| 148 | - // 1.1 获得会员钱包信息 | |
| 148 | + // 1. 获得会员钱包信息 | |
| 149 | 149 | PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId()); |
| 150 | - // 1.2 构建并发送模版消息 | |
| 150 | + // 2. 构建并发送模版消息 | |
| 151 | 151 | socialClientApi.sendSubscribeMessage(new SocialWxSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH) |
| 152 | - .setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(PAY_WALLET_CHANGE) | |
| 153 | - .setSocialType(SocialTypeEnum.WECHAT_MINI_APP.getType()) | |
| 154 | - // 添加模版消息 | |
| 155 | - .addMessage("phrase4", "充值成功").addMessage("character_string1", String.valueOf(payOrderId)) | |
| 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)) | |
| 156 | 155 | .addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) |
| 157 | - .addMessage("time3", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))); | |
| 156 | + .addMessage("time3", LocalDateTimeUtil.formatNormal(LocalDateTime.now())) | |
| 157 | + .addMessage("phrase4", "充值成功")); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | @Override | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java
| ... | ... | @@ -49,6 +49,7 @@ public interface SocialClientApi { |
| 49 | 49 | */ |
| 50 | 50 | byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO); |
| 51 | 51 | |
| 52 | + // TODO @puhui999:要不是统一都叫 getWxaSubscribeTemplateList、SocialWxaSubscribeTemplateRespDTO | |
| 52 | 53 | /** |
| 53 | 54 | * 获得微信小程订阅模板 |
| 54 | 55 | * |
| ... | ... | @@ -56,6 +57,7 @@ public interface SocialClientApi { |
| 56 | 57 | */ |
| 57 | 58 | List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType); |
| 58 | 59 | |
| 60 | + // TODO @puhui999:sendWxaSubscribeMessage、SocialWxaSubscribeMessageSendReqDTO;然后不传递 socialType;就是专门给微信小程序的 | |
| 59 | 61 | /** |
| 60 | 62 | * 发送微信小程序订阅消息 |
| 61 | 63 | * | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageSendReqDTO.java
| ... | ... | @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.system.api.social.dto; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 5 | +import jakarta.validation.constraints.NotEmpty; | |
| 6 | +import jakarta.validation.constraints.NotNull; | |
| 5 | 7 | import lombok.Data; |
| 6 | 8 | |
| 7 | 9 | import java.util.HashMap; |
| ... | ... | @@ -16,17 +18,19 @@ import java.util.Map; |
| 16 | 18 | public class SocialWxSubscribeMessageSendReqDTO { |
| 17 | 19 | |
| 18 | 20 | /** |
| 19 | - * 用户 id | |
| 21 | + * 用户编号 | |
| 20 | 22 | * |
| 21 | 23 | * 关联 MemberUserDO 的 id 编号 |
| 22 | 24 | * 关联 AdminUserDO 的 id 编号 |
| 23 | 25 | */ |
| 26 | + @NotNull(message = "用户编号不能为空") | |
| 24 | 27 | private Long userId; |
| 25 | 28 | /** |
| 26 | - * 用户类型, 预留 多商户转帐可能需要用到 | |
| 29 | + * 用户类型 | |
| 27 | 30 | * |
| 28 | 31 | * 关联 {@link UserTypeEnum} |
| 29 | 32 | */ |
| 33 | + @NotNull(message = "用户类型不能为空") | |
| 30 | 34 | private Integer userType; |
| 31 | 35 | |
| 32 | 36 | /** |
| ... | ... | @@ -34,11 +38,13 @@ public class SocialWxSubscribeMessageSendReqDTO { |
| 34 | 38 | * |
| 35 | 39 | * 枚举 {@link SocialTypeEnum} |
| 36 | 40 | */ |
| 41 | + @NotNull(message = "社交类型不能为空") | |
| 37 | 42 | private Integer socialType; |
| 38 | 43 | |
| 39 | 44 | /** |
| 40 | 45 | * 消息模版标题 |
| 41 | 46 | */ |
| 47 | + @NotEmpty(message = "消息模版标题不能为空") | |
| 42 | 48 | private String templateTitle; |
| 43 | 49 | |
| 44 | 50 | /** | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
| ... | ... | @@ -64,9 +64,8 @@ public class SocialClientApiImpl implements SocialClientApi { |
| 64 | 64 | |
| 65 | 65 | @Override |
| 66 | 66 | public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType) { |
| 67 | - List<TemplateInfo> subscribeTemplate = socialClientService.getSubscribeTemplateList(userType); | |
| 68 | - return convertList(subscribeTemplate, item -> BeanUtils.toBean(item, SocialWxSubscribeTemplateRespDTO.class) | |
| 69 | - .setId(item.getPriTmplId())); | |
| 67 | + List<TemplateInfo> list = socialClientService.getSubscribeTemplateList(userType); | |
| 68 | + return convertList(list, item -> BeanUtils.toBean(item, SocialWxSubscribeTemplateRespDTO.class).setId(item.getPriTmplId())); | |
| 70 | 69 | } |
| 71 | 70 | |
| 72 | 71 | @Override | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| ... | ... | @@ -297,13 +297,13 @@ public class SocialClientServiceImpl implements SocialClientService { |
| 297 | 297 | */ |
| 298 | 298 | private WxMaSubscribeMessage buildMessageSendReqDTO(SocialWxSubscribeMessageSendReqDTO reqDTO, |
| 299 | 299 | String templateId, String openId) { |
| 300 | - // 1.1 设置订阅消息基本参数 | |
| 300 | + // 设置订阅消息基本参数 | |
| 301 | 301 | WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage().setLang("zh_CN").setMiniprogramState(envVersion) |
| 302 | 302 | .setTemplateId(templateId).setToUser(openId).setPage(reqDTO.getPage()); |
| 303 | - // 1.2 设置具体消息参数 | |
| 303 | + // 设置具体消息参数 | |
| 304 | 304 | Map<String, String> messages = reqDTO.getMessages(); |
| 305 | 305 | if (CollUtil.isNotEmpty(messages)) { |
| 306 | - messages.keySet().forEach(key -> findAndThen(messages, key, value -> | |
| 306 | + reqDTO.getMessages().keySet().forEach(key -> findAndThen(messages, key, value -> | |
| 307 | 307 | subscribeMessage.addData(new WxMaSubscribeMessage.MsgData(key, value)))); |
| 308 | 308 | } |
| 309 | 309 | return subscribeMessage; | ... | ... |