mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	【新增】MALL: 新增退款订阅消息发送
This commit is contained in:
		| @@ -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)) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 puhui999
					puhui999