Commit 7f87f26f3a09fbcba5dfca7fa51af9362605aa13

Authored by YunaiV
1 parent b917d92a

【代码评审】SYSTEM:微信小程序的订阅消息

yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
... ... @@ -15,7 +15,10 @@ public interface MessageTemplateConstants {
15 15  
16 16 //======================= 订阅消息模版 =======================
17 17  
  18 + // TODO @puhui999:建议 TRADE_AFTER_SALE_CHANGE
18 19 String ORDER_AFTERSALE_CHANGE = "售后进度通知";
  20 +
  21 + // TODO @puhui999:是不是改成 PAY_WALLET_CHANGE 放在 PAY 模块
19 22 String MONEY_CHANGE = "充值成功通知";
20 23  
21 24 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
... ... @@ -8,10 +8,7 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
8 8 import cn.iocoder.yudao.module.member.controller.app.social.vo.*;
9 9 import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
10 10 import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
11   -import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
12   -import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
13   -import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
14   -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
  11 +import cn.iocoder.yudao.module.system.api.social.dto.*;
15 12 import io.swagger.v3.oas.annotations.Operation;
16 13 import io.swagger.v3.oas.annotations.Parameter;
17 14 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -74,7 +71,8 @@ public class AppSocialUserController {
74 71 @GetMapping("/get-subscribe-template")
75 72 @Operation(summary = "获得微信小程订阅模板")
76 73 public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplate() {
77   - return success(BeanUtils.toBean(socialClientApi.getSubscribeTemplate(), AppSocialWxSubscribeTemplateRespVO.class));
  74 + List<SocialWxSubscribeTemplateRespDTO> template = socialClientApi.getSubscribeTemplate();
  75 + return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class));
78 76 }
79 77  
80 78 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxSubscribeTemplateRespVO.java
... ... @@ -7,19 +7,22 @@ import lombok.Data;
7 7 @Data
8 8 public class AppSocialWxSubscribeTemplateRespVO {
9 9  
10   - @Schema(description = "添加至账号下的模板 id,发送小程序订阅消息时所需", requiredMode = Schema.RequiredMode.REQUIRED, example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU")
  10 + // TODO @puhui999:是不是使用 id 作为字段,更干净些哈;
  11 + @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED,
  12 + example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU")
11 13 private String priTmplId;
12 14  
13 15 @Schema(description = "模版标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单支付通知")
14 16 private String title;
15 17  
16   - @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED)
  18 + @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED,
  19 + example = "{ {result.DATA} }\\n\\n领奖金额:{ {withdrawMoney.DATA} }\\n领奖时间: { {withdrawTime.DATA} }")
17 20 private String content;
18 21  
19 22 @Schema(description = "模板内容示例", requiredMode = Schema.RequiredMode.REQUIRED, example = "下单时间:2016年8月8日")
20 23 private String example;
21 24  
22   - @Schema(description = "模版类型,2 为一次性订阅,3 为长期订阅", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
23   - private Integer type;
  25 + @Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  26 + private Integer type; // 2 为一次性订阅,3 为长期订阅
24 27  
25 28 }
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java
... ... @@ -57,7 +57,7 @@ public interface SocialClientApi {
57 57 List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate();
58 58  
59 59 /**
60   - * 发送订阅消息
  60 + * 发送微信小程序订阅消息
61 61 *
62 62 * @param reqDTO 请求
63 63 */
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageReqDTO.java
... ... @@ -6,6 +6,7 @@ import lombok.Data;
6 6 import java.util.ArrayList;
7 7 import java.util.List;
8 8  
  9 +// TODO @puhui99:1)参考 SocialWxQrcodeReqDTO,可以 @see 文档。这样,注释会更见见一点。2)是不是少了 Send:SocialWxSubscribeMessageSendReqDTO
9 10 /**
10 11 * 微信小程序订阅消息 Request DTO
11 12 *
... ... @@ -14,6 +15,7 @@ import java.util.List;
14 15 @Data
15 16 public class SocialWxSubscribeMessageReqDTO {
16 17  
  18 + // TODO @puhui999:参数校验
17 19 /**
18 20 * 接收者(用户)的 openid.
19 21 * <pre>
... ... @@ -58,6 +60,7 @@ public class SocialWxSubscribeMessageReqDTO {
58 60 */
59 61 private String lang;
60 62  
  63 + // TODO @puhui999:是必须 List<KeyValue<String, String>>,还是 Map<String, String 即可)
61 64 /**
62 65 * 模板内容,不填则下发空模板.
63 66 * <pre>
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java
... ... @@ -11,6 +11,7 @@ import lombok.Data;
11 11 @Data
12 12 public class SocialWxSubscribeTemplateRespDTO {
13 13  
  14 + // TODO @puhui999:建议搞成 id
14 15 /**
15 16 * 添加至账号下的模板 id,发送小程序订阅消息时所需
16 17 */
... ... @@ -31,8 +32,12 @@ public class SocialWxSubscribeTemplateRespDTO {
31 32 */
32 33 private String example;
33 34  
  35 + // TODO @puhui999:这个在 wxjava 里面,有枚举字段么?
34 36 /**
35   - * 模版类型,2 为一次性订阅,3 为长期订阅
  37 + * 模版类型
  38 + *
  39 + * 2 为一次性订阅
  40 + * 3 为长期订阅
36 41 */
37 42 private Integer type;
38 43  
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java
... ... @@ -72,6 +72,7 @@ public class SocialClientController {
72 72  
73 73 //======================= TODO 测试发送订阅消息 =======================
74 74  
  75 + // TODO @puhui999:这个接口,其实可以留着。然后把参数挪到 .http 文件。先直接用 SocialWxSubscribeMessageReqDTO 接参数
75 76 @PostMapping("/send-subscribe-message")
76 77 public void testSendSubscribeMessage() {
77 78 SocialWxSubscribeMessageReqDTO reqDTO = new SocialWxSubscribeMessageReqDTO().setLang("zh_CN")
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
... ... @@ -81,7 +81,7 @@ public interface SocialClientService {
81 81 List<TemplateInfo> getSubscribeTemplate();
82 82  
83 83 /**
84   - * 发送订阅消息
  84 + * 发送微信小程序订阅消息
85 85 *
86 86 * @param reqDTO 请求
87 87 */
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
... ... @@ -236,6 +236,7 @@ public class SocialClientServiceImpl implements SocialClientService {
236 236 try {
237 237 return service.getUserService().getPhoneNoInfo(phoneCode);
238 238 } catch (WxErrorException e) {
  239 + // TODO @puhui999:这里的日志,reqDTO 要打进去
239 240 log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e);
240 241 throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR);
241 242 }
... ... @@ -262,11 +263,12 @@ public class SocialClientServiceImpl implements SocialClientService {
262 263  
263 264 @Override
264 265 public List<TemplateInfo> getSubscribeTemplate() {
  266 + // TODO @puhui999:这个 userType 最好通过参数,传递过来;然后这个方法名,貌似叫 getSubscribeTemplateList 更合适哈;
265 267 WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
266 268 try {
267 269 WxMaSubscribeService subscribeService = service.getSubscribeService();
268 270 return subscribeService.getTemplateList();
269   - }catch (WxErrorException e) {
  271 + } catch (WxErrorException e) {
270 272 log.error("[getSubscribeTemplate][获得小程序订阅消息模版]", e);
271 273 throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR);
272 274 }
... ... @@ -274,13 +276,15 @@ public class SocialClientServiceImpl implements SocialClientService {
274 276  
275 277 @Override
276 278 public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) {
  279 + // TODO @puhui999:这个 userType 最好通过参数,
277 280 WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
278 281 try {
279 282 WxMaSubscribeService subscribeService = service.getSubscribeService();
280 283 WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class);
281 284 reqDTO.getMessages().forEach(item-> message.addData(new WxMaSubscribeMessage.MsgData(item.getKey(), item.getValue())));
282 285 subscribeService.sendSubscribeMsg(message);
283   - }catch (WxErrorException e) {
  286 + } catch (WxErrorException e) {
  287 + // TODO @puhui999:这里的日志,reqDTO 要打进去
284 288 log.error("[sendSubscribeMessage][发送小程序订阅消息]", e);
285 289 throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR);
286 290 }
... ...