mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
【代码评审】SYSTEM:微信小程序的订阅
This commit is contained in:
parent
3be6ee271b
commit
a9862b798d
@ -145,16 +145,16 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
|
|||||||
|
|
||||||
@Async
|
@Async
|
||||||
public void sendPayWalletChangeMessage(Long payOrderId, PayWalletRechargeDO walletRecharge) {
|
public void sendPayWalletChangeMessage(Long payOrderId, PayWalletRechargeDO walletRecharge) {
|
||||||
// 1.1 获得会员钱包信息
|
// 1. 获得会员钱包信息
|
||||||
PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId());
|
PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId());
|
||||||
// 1.2 构建并发送模版消息
|
// 2. 构建并发送模版消息
|
||||||
socialClientApi.sendSubscribeMessage(new SocialWxSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH)
|
socialClientApi.sendSubscribeMessage(new SocialWxSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH)
|
||||||
.setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(PAY_WALLET_CHANGE)
|
.setUserId(wallet.getUserId()).setUserType(wallet.getUserType())
|
||||||
.setSocialType(SocialTypeEnum.WECHAT_MINI_APP.getType())
|
.setTemplateTitle(PAY_WALLET_CHANGE).setSocialType(SocialTypeEnum.WECHAT_MINI_APP.getType())
|
||||||
// 添加模版消息
|
.addMessage("character_string1", String.valueOf(payOrderId))
|
||||||
.addMessage("phrase4", "充值成功").addMessage("character_string1", String.valueOf(payOrderId))
|
|
||||||
.addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice()))
|
.addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice()))
|
||||||
.addMessage("time3", LocalDateTimeUtil.formatNormal(LocalDateTime.now())));
|
.addMessage("time3", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))
|
||||||
|
.addMessage("phrase4", "充值成功"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,6 +49,7 @@ public interface SocialClientApi {
|
|||||||
*/
|
*/
|
||||||
byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO);
|
byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO);
|
||||||
|
|
||||||
|
// TODO @puhui999:要不是统一都叫 getWxaSubscribeTemplateList、SocialWxaSubscribeTemplateRespDTO
|
||||||
/**
|
/**
|
||||||
* 获得微信小程订阅模板
|
* 获得微信小程订阅模板
|
||||||
*
|
*
|
||||||
@ -56,6 +57,7 @@ public interface SocialClientApi {
|
|||||||
*/
|
*/
|
||||||
List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType);
|
List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType);
|
||||||
|
|
||||||
|
// TODO @puhui999:sendWxaSubscribeMessage、SocialWxaSubscribeMessageSendReqDTO;然后不传递 socialType;就是专门给微信小程序的
|
||||||
/**
|
/**
|
||||||
* 发送微信小程序订阅消息
|
* 发送微信小程序订阅消息
|
||||||
*
|
*
|
||||||
|
@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.system.api.social.dto;
|
|||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -16,17 +18,19 @@ import java.util.Map;
|
|||||||
public class SocialWxSubscribeMessageSendReqDTO {
|
public class SocialWxSubscribeMessageSendReqDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户 id
|
* 用户编号
|
||||||
*
|
*
|
||||||
* 关联 MemberUserDO 的 id 编号
|
* 关联 MemberUserDO 的 id 编号
|
||||||
* 关联 AdminUserDO 的 id 编号
|
* 关联 AdminUserDO 的 id 编号
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "用户编号不能为空")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
/**
|
/**
|
||||||
* 用户类型, 预留 多商户转帐可能需要用到
|
* 用户类型
|
||||||
*
|
*
|
||||||
* 关联 {@link UserTypeEnum}
|
* 关联 {@link UserTypeEnum}
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "用户类型不能为空")
|
||||||
private Integer userType;
|
private Integer userType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,11 +38,13 @@ public class SocialWxSubscribeMessageSendReqDTO {
|
|||||||
*
|
*
|
||||||
* 枚举 {@link SocialTypeEnum}
|
* 枚举 {@link SocialTypeEnum}
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "社交类型不能为空")
|
||||||
private Integer socialType;
|
private Integer socialType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息模版标题
|
* 消息模版标题
|
||||||
*/
|
*/
|
||||||
|
@NotEmpty(message = "消息模版标题不能为空")
|
||||||
private String templateTitle;
|
private String templateTitle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,9 +64,8 @@ public class SocialClientApiImpl implements SocialClientApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType) {
|
public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType) {
|
||||||
List<TemplateInfo> subscribeTemplate = socialClientService.getSubscribeTemplateList(userType);
|
List<TemplateInfo> list = socialClientService.getSubscribeTemplateList(userType);
|
||||||
return convertList(subscribeTemplate, item -> BeanUtils.toBean(item, SocialWxSubscribeTemplateRespDTO.class)
|
return convertList(list, item -> BeanUtils.toBean(item, SocialWxSubscribeTemplateRespDTO.class).setId(item.getPriTmplId()));
|
||||||
.setId(item.getPriTmplId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -297,13 +297,13 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||||||
*/
|
*/
|
||||||
private WxMaSubscribeMessage buildMessageSendReqDTO(SocialWxSubscribeMessageSendReqDTO reqDTO,
|
private WxMaSubscribeMessage buildMessageSendReqDTO(SocialWxSubscribeMessageSendReqDTO reqDTO,
|
||||||
String templateId, String openId) {
|
String templateId, String openId) {
|
||||||
// 1.1 设置订阅消息基本参数
|
// 设置订阅消息基本参数
|
||||||
WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage().setLang("zh_CN").setMiniprogramState(envVersion)
|
WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage().setLang("zh_CN").setMiniprogramState(envVersion)
|
||||||
.setTemplateId(templateId).setToUser(openId).setPage(reqDTO.getPage());
|
.setTemplateId(templateId).setToUser(openId).setPage(reqDTO.getPage());
|
||||||
// 1.2 设置具体消息参数
|
// 设置具体消息参数
|
||||||
Map<String, String> messages = reqDTO.getMessages();
|
Map<String, String> messages = reqDTO.getMessages();
|
||||||
if (CollUtil.isNotEmpty(messages)) {
|
if (CollUtil.isNotEmpty(messages)) {
|
||||||
messages.keySet().forEach(key -> findAndThen(messages, key, value ->
|
reqDTO.getMessages().keySet().forEach(key -> findAndThen(messages, key, value ->
|
||||||
subscribeMessage.addData(new WxMaSubscribeMessage.MsgData(key, value))));
|
subscribeMessage.addData(new WxMaSubscribeMessage.MsgData(key, value))));
|
||||||
}
|
}
|
||||||
return subscribeMessage;
|
return subscribeMessage;
|
||||||
|
Loading…
Reference in New Issue
Block a user