mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 07:11:52 +08:00
【新增】MALL: 新增退款订阅消息发送
This commit is contained in:
parent
a9862b798d
commit
4c846ef4ce
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
// =================== 客户端管理 ===================
|
||||
|
||||
|
@ -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<String, String> messages = reqDTO.getMessages();
|
||||
if (CollUtil.isNotEmpty(messages)) {
|
||||
|
Loading…
Reference in New Issue
Block a user