Commit 469610521054d9b38bc78221a5b07fd7ca1ffb75
1 parent
7f87f26f
【优化】SYSTEM: 根据代码评审优化小程序的订阅消息
Showing
13 changed files
with
109 additions
and
62 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
| ... | ... | @@ -13,12 +13,8 @@ public interface MessageTemplateConstants { |
| 13 | 13 | String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过) |
| 14 | 14 | String BROKERAGE_WITHDRAW_AUDIT_REJECT = "brokerage_withdraw_audit_reject"; // 佣金提现(审核不通过) |
| 15 | 15 | |
| 16 | - //======================= 订阅消息模版 ======================= | |
| 16 | + //======================= 小程序订阅消息模版 ======================= | |
| 17 | 17 | |
| 18 | - // TODO @puhui999:建议 TRADE_AFTER_SALE_CHANGE | |
| 19 | - String ORDER_AFTERSALE_CHANGE = "售后进度通知"; | |
| 20 | - | |
| 21 | - // TODO @puhui999:是不是改成 PAY_WALLET_CHANGE 放在 PAY 模块 | |
| 22 | - String MONEY_CHANGE = "充值成功通知"; | |
| 18 | + String TRADE_AFTER_SALE_CHANGE = "售后进度通知"; | |
| 23 | 19 | |
| 24 | 20 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
| ... | ... | @@ -68,10 +68,10 @@ public class AppSocialUserController { |
| 68 | 68 | return success(Base64.encode(wxQrcode)); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - @GetMapping("/get-subscribe-template") | |
| 72 | - @Operation(summary = "获得微信小程订阅模板") | |
| 73 | - public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplate() { | |
| 74 | - List<SocialWxSubscribeTemplateRespDTO> template = socialClientApi.getSubscribeTemplate(); | |
| 71 | + @GetMapping("/get-subscribe-template-list") | |
| 72 | + @Operation(summary = "获得微信小程订阅模板列表") | |
| 73 | + public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplateList() { | |
| 74 | + List<SocialWxSubscribeTemplateRespDTO> template = socialClientApi.getSubscribeTemplateList(UserTypeEnum.MEMBER.getValue()); | |
| 75 | 75 | return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class)); |
| 76 | 76 | } |
| 77 | 77 | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxSubscribeTemplateRespVO.java
| ... | ... | @@ -7,10 +7,9 @@ import lombok.Data; |
| 7 | 7 | @Data |
| 8 | 8 | public class AppSocialWxSubscribeTemplateRespVO { |
| 9 | 9 | |
| 10 | - // TODO @puhui999:是不是使用 id 作为字段,更干净些哈; | |
| 11 | 10 | @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, |
| 12 | 11 | example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU") |
| 13 | - private String priTmplId; | |
| 12 | + private String id; | |
| 14 | 13 | |
| 15 | 14 | @Schema(description = "模版标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单支付通知") |
| 16 | 15 | private String title; | ... | ... |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.enums; | |
| 2 | + | |
| 3 | +// TODO @芋艿:枚举 | |
| 4 | +/** | |
| 5 | + * 通知模板枚举类 | |
| 6 | + * | |
| 7 | + * @author HUIHUI | |
| 8 | + */ | |
| 9 | +public interface MessageTemplateConstants { | |
| 10 | + | |
| 11 | + //======================= 小程序订阅消息 ======================= | |
| 12 | + | |
| 13 | + String PAY_WALLET_CHANGE = "充值成功通知"; | |
| 14 | + | |
| 15 | +} | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java
| ... | ... | @@ -54,13 +54,13 @@ public interface SocialClientApi { |
| 54 | 54 | * |
| 55 | 55 | * @return 小程序订阅消息模版 |
| 56 | 56 | */ |
| 57 | - List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate(); | |
| 57 | + List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType); | |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * 发送微信小程序订阅消息 |
| 61 | 61 | * |
| 62 | 62 | * @param reqDTO 请求 |
| 63 | 63 | */ |
| 64 | - void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO); | |
| 64 | + void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, Integer userType); | |
| 65 | 65 | |
| 66 | 66 | } | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageReqDTO.java renamed to yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageSendReqDTO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.api.social.dto; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.core.KeyValue; | |
| 3 | +import jakarta.validation.constraints.NotNull; | |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | |
| 6 | -import java.util.ArrayList; | |
| 7 | -import java.util.List; | |
| 6 | +import java.util.HashMap; | |
| 7 | +import java.util.Map; | |
| 8 | 8 | |
| 9 | -// TODO @puhui99:1)参考 SocialWxQrcodeReqDTO,可以 @see 文档。这样,注释会更见见一点。2)是不是少了 Send:SocialWxSubscribeMessageSendReqDTO | |
| 10 | 9 | /** |
| 11 | - * 微信小程序订阅消息 Request DTO | |
| 10 | + * 微信小程序订阅消息发送 Request DTO | |
| 12 | 11 | * |
| 12 | + * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html">接口文档</a> | |
| 13 | 13 | * @author HUIHUI |
| 14 | 14 | */ |
| 15 | 15 | @Data |
| 16 | -public class SocialWxSubscribeMessageReqDTO { | |
| 16 | +public class SocialWxSubscribeMessageSendReqDTO { | |
| 17 | 17 | |
| 18 | - // TODO @puhui999:参数校验 | |
| 19 | 18 | /** |
| 20 | 19 | * 接收者(用户)的 openid. |
| 21 | 20 | * <pre> |
| ... | ... | @@ -24,6 +23,7 @@ public class SocialWxSubscribeMessageReqDTO { |
| 24 | 23 | * 描述: 接收者(用户)的 openid |
| 25 | 24 | * </pre> |
| 26 | 25 | */ |
| 26 | + @NotNull(message = "接收者(用户)的 openid不能为空") | |
| 27 | 27 | private String toUser; |
| 28 | 28 | |
| 29 | 29 | /** |
| ... | ... | @@ -34,6 +34,7 @@ public class SocialWxSubscribeMessageReqDTO { |
| 34 | 34 | * 描述: 所需下发的模板消息的id |
| 35 | 35 | * </pre> |
| 36 | 36 | */ |
| 37 | + @NotNull(message = "模板消息的id不能为空") | |
| 37 | 38 | private String templateId; |
| 38 | 39 | |
| 39 | 40 | /** |
| ... | ... | @@ -51,6 +52,7 @@ public class SocialWxSubscribeMessageReqDTO { |
| 51 | 52 | * |
| 52 | 53 | * 枚举 WxMaConstants.MiniProgramState |
| 53 | 54 | */ |
| 55 | + @NotNull(message = "跳转小程序类型不能为空") | |
| 54 | 56 | private String miniprogramState; |
| 55 | 57 | |
| 56 | 58 | /** |
| ... | ... | @@ -58,9 +60,9 @@ public class SocialWxSubscribeMessageReqDTO { |
| 58 | 60 | * |
| 59 | 61 | * 枚举 WxMaConstants.MiniProgramLang |
| 60 | 62 | */ |
| 63 | + @NotNull(message = "进入小程序查看的语言类型不能为空") | |
| 61 | 64 | private String lang; |
| 62 | 65 | |
| 63 | - // TODO @puhui999:是必须 List<KeyValue<String, String>>,还是 Map<String, String 即可) | |
| 64 | 66 | /** |
| 65 | 67 | * 模板内容,不填则下发空模板. |
| 66 | 68 | * <pre> |
| ... | ... | @@ -69,13 +71,13 @@ public class SocialWxSubscribeMessageReqDTO { |
| 69 | 71 | * 描述: 模板内容,不填则下发空模板 |
| 70 | 72 | * </pre> |
| 71 | 73 | */ |
| 72 | - private List<KeyValue<String, String>> messages; | |
| 74 | + private Map<String, String> messages; | |
| 73 | 75 | |
| 74 | - public SocialWxSubscribeMessageReqDTO addData(String key, String value) { | |
| 76 | + public SocialWxSubscribeMessageSendReqDTO addData(String key, String value) { | |
| 75 | 77 | if (messages == null) { |
| 76 | - messages = new ArrayList<>(); | |
| 78 | + messages = new HashMap<>(); | |
| 77 | 79 | } |
| 78 | - messages.add(new KeyValue<>(key, value)); | |
| 80 | + messages.put(key, value); | |
| 79 | 81 | return this; |
| 80 | 82 | } |
| 81 | 83 | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java
| ... | ... | @@ -11,11 +11,10 @@ import lombok.Data; |
| 11 | 11 | @Data |
| 12 | 12 | public class SocialWxSubscribeTemplateRespDTO { |
| 13 | 13 | |
| 14 | - // TODO @puhui999:建议搞成 id | |
| 15 | 14 | /** |
| 16 | 15 | * 添加至账号下的模板 id,发送小程序订阅消息时所需 |
| 17 | 16 | */ |
| 18 | - private String priTmplId; | |
| 17 | + private String id; | |
| 19 | 18 | |
| 20 | 19 | /** |
| 21 | 20 | * 模版标题 |
| ... | ... | @@ -32,7 +31,7 @@ public class SocialWxSubscribeTemplateRespDTO { |
| 32 | 31 | */ |
| 33 | 32 | private String example; |
| 34 | 33 | |
| 35 | - // TODO @puhui999:这个在 wxjava 里面,有枚举字段么? | |
| 34 | + // TODO @puhui999:这个在 wxjava 里面,有枚举字段么?没得🤣 | |
| 36 | 35 | /** |
| 37 | 36 | * 模版类型 |
| 38 | 37 | * | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.api.social; |
| 3 | 3 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.social.dto.*; |
| 6 | +import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; | |
| 6 | 7 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; |
| 7 | 8 | import jakarta.annotation.Resource; |
| 8 | 9 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| ... | ... | @@ -47,14 +48,14 @@ public class SocialClientApiImpl implements SocialClientApi { |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | @Override |
| 50 | - public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate() { | |
| 51 | - List<TemplateInfo> subscribeTemplate = socialClientService.getSubscribeTemplate(); | |
| 52 | - return BeanUtils.toBean(subscribeTemplate, SocialWxSubscribeTemplateRespDTO.class); | |
| 51 | + public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplateList(Integer userType) { | |
| 52 | + List<TemplateInfo> subscribeTemplate = socialClientService.getSubscribeTemplateList(userType); | |
| 53 | + return SocialUserConvert.INSTANCE.convertList(subscribeTemplate); | |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | 56 | @Override |
| 56 | - public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) { | |
| 57 | - socialClientService.sendSubscribeMessage(reqDTO); | |
| 57 | + public void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, Integer userType) { | |
| 58 | + socialClientService.sendSubscribeMessage(reqDTO, userType); | |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.http
| 1 | 1 | ### 请求 /system/social-client/send-subscribe-message 接口 => 发送测试订阅消息 |
| 2 | 2 | POST {{baseUrl}}/system/social-client/send-subscribe-message |
| 3 | 3 | Authorization: Bearer {{token}} |
| 4 | +Content-Type: application/json | |
| 4 | 5 | #Authorization: Bearer test100 |
| 5 | 6 | tenant-id: {{adminTenentId}} |
| 7 | + | |
| 8 | +{ | |
| 9 | + "toUser": "oKNkb4xxw2H135-MVPKtEMkumK08", | |
| 10 | + "templateId": "W4ybDTIwCfKHtMKR7fSfx83DtmVKEeXQo3Ti7GCw4_4", | |
| 11 | + "miniprogramState": "developer", | |
| 12 | + "lang": "zh_CN", | |
| 13 | + "messages": { | |
| 14 | + "character_string1":"5616122165165", | |
| 15 | + "amount2":"1000.00", | |
| 16 | + "time3":"2024-01-01 10:10:10", | |
| 17 | + "phrase4":"成功" | |
| 18 | + } | |
| 19 | +} | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.socail; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageReqDTO; | |
| 7 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 7 | 8 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO; |
| 9 | 10 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; |
| ... | ... | @@ -72,15 +73,9 @@ public class SocialClientController { |
| 72 | 73 | |
| 73 | 74 | //======================= TODO 测试发送订阅消息 ======================= |
| 74 | 75 | |
| 75 | - // TODO @puhui999:这个接口,其实可以留着。然后把参数挪到 .http 文件。先直接用 SocialWxSubscribeMessageReqDTO 接参数 | |
| 76 | 76 | @PostMapping("/send-subscribe-message") |
| 77 | - public void testSendSubscribeMessage() { | |
| 78 | - SocialWxSubscribeMessageReqDTO reqDTO = new SocialWxSubscribeMessageReqDTO().setLang("zh_CN") | |
| 79 | - .setMiniprogramState("developer").setTemplateId("W4ybDTIwCfKHtMKR7fSfx83DtmVKEeXQo3Ti7GCw4_4") | |
| 80 | - .setToUser("oKNkb4xxw2H135-MVPKtEMkumK08"); | |
| 81 | - reqDTO.addData("character_string1", "11111111").addData("amount2", "6666").addData("time3", "2024-01-01 10:10:10") | |
| 82 | - .addData("phrase4", "成功"); | |
| 83 | - socialClientService.sendSubscribeMessage(reqDTO); | |
| 77 | + public void testSendSubscribeMessage(@RequestBody SocialWxSubscribeMessageSendReqDTO reqDTO) { | |
| 78 | + socialClientService.sendSubscribeMessage(reqDTO, UserTypeEnum.MEMBER.getValue()); | |
| 84 | 79 | } |
| 85 | 80 | |
| 86 | 81 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.system.convert.social; |
| 2 | 2 | |
| 3 | +import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; | |
| 4 | +import cn.hutool.core.collection.CollUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 3 | 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| 7 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 8 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeTemplateRespDTO; | |
| 4 | 9 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserBindReqVO; |
| 10 | +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; | |
| 5 | 11 | import org.mapstruct.Mapper; |
| 6 | 12 | import org.mapstruct.Mapping; |
| 7 | 13 | import org.mapstruct.factory.Mappers; |
| 8 | 14 | |
| 15 | +import java.util.ArrayList; | |
| 16 | +import java.util.List; | |
| 17 | +import java.util.Map; | |
| 18 | + | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | |
| 20 | + | |
| 9 | 21 | @Mapper |
| 10 | 22 | public interface SocialUserConvert { |
| 11 | 23 | |
| ... | ... | @@ -14,4 +26,24 @@ public interface SocialUserConvert { |
| 14 | 26 | @Mapping(source = "reqVO.type", target = "socialType") |
| 15 | 27 | SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO); |
| 16 | 28 | |
| 29 | + default WxMaSubscribeMessage convert(SocialWxSubscribeMessageSendReqDTO reqDTO) { | |
| 30 | + WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class); | |
| 31 | + Map<String, String> messages = reqDTO.getMessages(); | |
| 32 | + if (CollUtil.isNotEmpty(messages)) { | |
| 33 | + messages.keySet().forEach(key -> { | |
| 34 | + findAndThen(messages, key, value -> message.addData(new WxMaSubscribeMessage.MsgData(key, value))); | |
| 35 | + }); | |
| 36 | + } | |
| 37 | + return message; | |
| 38 | + } | |
| 39 | + | |
| 40 | + @Mapping(target = "id", source = "priTmplId") | |
| 41 | + SocialWxSubscribeTemplateRespDTO convert(TemplateInfo templateInfo); | |
| 42 | + | |
| 43 | + default List<SocialWxSubscribeTemplateRespDTO> convertList(List<TemplateInfo> subscribeTemplate) { | |
| 44 | + List<SocialWxSubscribeTemplateRespDTO> list = new ArrayList<>(); | |
| 45 | + subscribeTemplate.forEach(templateInfo -> list.add(convert(templateInfo))); | |
| 46 | + return list; | |
| 47 | + } | |
| 48 | + | |
| 17 | 49 | } | ... | ... |
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; |
| 3 | 3 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 6 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageReqDTO; | |
| 6 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 7 | 7 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; |
| ... | ... | @@ -78,14 +78,14 @@ public interface SocialClientService { |
| 78 | 78 | * |
| 79 | 79 | * @return 微信小程订阅模板 |
| 80 | 80 | */ |
| 81 | - List<TemplateInfo> getSubscribeTemplate(); | |
| 81 | + List<TemplateInfo> getSubscribeTemplateList(Integer userType); | |
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * 发送微信小程序订阅消息 |
| 85 | 85 | * |
| 86 | 86 | * @param reqDTO 请求 |
| 87 | 87 | */ |
| 88 | - void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO); | |
| 88 | + void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, Integer userType); | |
| 89 | 89 | |
| 90 | 90 | // =================== 客户端管理 =================== |
| 91 | 91 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| ... | ... | @@ -4,7 +4,6 @@ import cn.binarywang.wx.miniapp.api.WxMaService; |
| 4 | 4 | import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; |
| 5 | 5 | import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
| 6 | 6 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 7 | -import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; | |
| 8 | 7 | import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; |
| 9 | 8 | import cn.hutool.core.bean.BeanUtil; |
| 10 | 9 | import cn.hutool.core.lang.Assert; |
| ... | ... | @@ -17,9 +16,10 @@ import cn.iocoder.yudao.framework.common.util.cache.CacheUtils; |
| 17 | 16 | import cn.iocoder.yudao.framework.common.util.http.HttpUtils; |
| 18 | 17 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 19 | 18 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 20 | -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageReqDTO; | |
| 19 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageSendReqDTO; | |
| 21 | 20 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; |
| 22 | 21 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; |
| 22 | +import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; | |
| 23 | 23 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; |
| 24 | 24 | import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; |
| 25 | 25 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| ... | ... | @@ -236,7 +236,6 @@ public class SocialClientServiceImpl implements SocialClientService { |
| 236 | 236 | try { |
| 237 | 237 | return service.getUserService().getPhoneNoInfo(phoneCode); |
| 238 | 238 | } catch (WxErrorException e) { |
| 239 | - // TODO @puhui999:这里的日志,reqDTO 要打进去 | |
| 240 | 239 | log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e); |
| 241 | 240 | throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR); |
| 242 | 241 | } |
| ... | ... | @@ -256,36 +255,31 @@ public class SocialClientServiceImpl implements SocialClientService { |
| 256 | 255 | null, |
| 257 | 256 | ObjUtil.defaultIfNull(reqVO.getHyaline(), SocialWxQrcodeReqDTO.HYALINE)); |
| 258 | 257 | } catch (WxErrorException e) { |
| 259 | - log.error("[getWxQrcode][reqVO({})) 获得小程序码失败]", reqVO, e); | |
| 258 | + log.error("[getWxQrcode][reqVO({}) 获得小程序码失败]", reqVO, e); | |
| 260 | 259 | throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR); |
| 261 | 260 | } |
| 262 | 261 | } |
| 263 | 262 | |
| 264 | 263 | @Override |
| 265 | - public List<TemplateInfo> getSubscribeTemplate() { | |
| 266 | - // TODO @puhui999:这个 userType 最好通过参数,传递过来;然后这个方法名,貌似叫 getSubscribeTemplateList 更合适哈; | |
| 267 | - WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue()); | |
| 264 | + public List<TemplateInfo> getSubscribeTemplateList(Integer userType) { | |
| 265 | + WxMaService service = getWxMaService(userType); | |
| 268 | 266 | try { |
| 269 | 267 | WxMaSubscribeService subscribeService = service.getSubscribeService(); |
| 270 | 268 | return subscribeService.getTemplateList(); |
| 271 | 269 | } catch (WxErrorException e) { |
| 272 | - log.error("[getSubscribeTemplate][获得小程序订阅消息模版]", e); | |
| 270 | + log.error("[getSubscribeTemplate][userType({}) 获得小程序订阅消息模版]", userType, e); | |
| 273 | 271 | throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR); |
| 274 | 272 | } |
| 275 | 273 | } |
| 276 | 274 | |
| 277 | 275 | @Override |
| 278 | - public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) { | |
| 279 | - // TODO @puhui999:这个 userType 最好通过参数, | |
| 280 | - WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue()); | |
| 276 | + public void sendSubscribeMessage(SocialWxSubscribeMessageSendReqDTO reqDTO, Integer userType) { | |
| 277 | + WxMaService service = getWxMaService(userType); | |
| 281 | 278 | try { |
| 282 | 279 | WxMaSubscribeService subscribeService = service.getSubscribeService(); |
| 283 | - WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class); | |
| 284 | - reqDTO.getMessages().forEach(item-> message.addData(new WxMaSubscribeMessage.MsgData(item.getKey(), item.getValue()))); | |
| 285 | - subscribeService.sendSubscribeMsg(message); | |
| 280 | + subscribeService.sendSubscribeMsg(SocialUserConvert.INSTANCE.convert(reqDTO)); | |
| 286 | 281 | } catch (WxErrorException e) { |
| 287 | - // TODO @puhui999:这里的日志,reqDTO 要打进去 | |
| 288 | - log.error("[sendSubscribeMessage][发送小程序订阅消息]", e); | |
| 282 | + log.error("[sendSubscribeMessage][reqVO({}) userType({}) 发送小程序订阅消息]", reqDTO, userType, e); | |
| 289 | 283 | throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR); |
| 290 | 284 | } |
| 291 | 285 | } | ... | ... |