Commit 7de546385a2c09c59eb6e23d7cffb37fe4c0b1b9

Authored by YunaiV
1 parent abe2f858

【代码优化】SYSTEM:微信小程序的订阅

yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
... ... @@ -63,16 +63,16 @@ public class AppSocialUserController {
63 63  
64 64 @PostMapping("/wxa-qrcode")
65 65 @Operation(summary = "获得微信小程序码(base64 image)")
66   - public CommonResult<String> getWxaQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
  66 + public CommonResult<String> getWxaQrcode(@RequestBody @Valid AppSocialWxaQrcodeReqVO reqVO) {
67 67 byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class));
68 68 return success(Base64.encode(wxQrcode));
69 69 }
70 70  
71 71 @GetMapping("/get-subscribe-template-list")
72 72 @Operation(summary = "获得微信小程订阅模板列表")
73   - public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplateList() {
  73 + public CommonResult<List<AppSocialWxaSubscribeTemplateRespVO>> getSubscribeTemplateList() {
74 74 List<SocialWxaSubscribeTemplateRespDTO> template = socialClientApi.getWxaSubscribeTemplateList(UserTypeEnum.MEMBER.getValue());
75   - return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class));
  75 + return success(BeanUtils.toBean(template, AppSocialWxaSubscribeTemplateRespVO.class));
76 76 }
77 77  
78 78 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxaQrcodeReqVO.java
... ... @@ -7,7 +7,7 @@ import lombok.Data;
7 7  
8 8 @Schema(description = "用户 APP - 获得获取小程序码 Request VO")
9 9 @Data
10   -public class AppSocialWxQrcodeReqVO {
  10 +public class AppSocialWxaQrcodeReqVO {
11 11  
12 12 /**
13 13 * 页面路径不能携带参数(参数请放在scene字段里)
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxSubscribeTemplateRespVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxaSubscribeTemplateRespVO.java
... ... @@ -5,7 +5,7 @@ import lombok.Data;
5 5  
6 6 @Schema(description = "用户 APP - 获得小程序订阅模版 Response VO")
7 7 @Data
8   -public class AppSocialWxSubscribeTemplateRespVO {
  8 +public class AppSocialWxaSubscribeTemplateRespVO {
9 9  
10 10 @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED,
11 11 example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU")
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
... ... @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
8 8 import cn.iocoder.yudao.module.system.api.social.dto.*;
9 9 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
10 10 import cn.iocoder.yudao.module.system.service.social.SocialClientService;
  11 +import cn.iocoder.yudao.module.system.service.social.SocialUserService;
11 12 import jakarta.annotation.Resource;
12 13 import lombok.extern.slf4j.Slf4j;
13 14 import me.chanjar.weixin.common.bean.WxJsapiSignature;
... ... @@ -33,7 +34,7 @@ public class SocialClientApiImpl implements SocialClientApi {
33 34 @Resource
34 35 private SocialClientService socialClientService;
35 36 @Resource
36   - public SocialUserApi socialUserApi;
  37 + private SocialUserService socialUserService;
37 38  
38 39 @Override
39 40 public String getAuthorizeUrl(Integer socialType, Integer userType, String redirectUri) {
... ... @@ -68,29 +69,29 @@ public class SocialClientApiImpl implements SocialClientApi {
68 69 @Override
69 70 public void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO) {
70 71 // 1.1 获得订阅模版列表
71   - List<SocialWxaSubscribeTemplateRespDTO> templateList = getWxaSubscribeTemplateList(reqDTO.getUserType());
  72 + List<TemplateInfo> templateList = socialClientService.getSubscribeTemplateList(reqDTO.getUserType());
72 73 if (CollUtil.isEmpty(templateList)) {
73 74 log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
74 75 return;
75 76 }
76 77 // 1.2 获得需要使用的模版
77   - SocialWxaSubscribeTemplateRespDTO template = findOne(templateList, item ->
  78 + TemplateInfo template = findOne(templateList, item ->
78 79 ObjUtil.equal(item.getTitle(), reqDTO.getTemplateTitle()));
79 80 if (template == null) {
80   - log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
  81 + log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
81 82 return;
82 83 }
83 84  
84 85 // 2. 获得社交用户
85   - SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(),
  86 + SocialUserRespDTO socialUser = socialUserService.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(),
86 87 SocialTypeEnum.WECHAT_MINI_APP.getType());
87 88 if (StrUtil.isBlankIfStr(socialUser.getOpenid())) {
88   - log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO);
  89 + log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO);
89 90 return;
90 91 }
91 92  
92 93 // 3. 发送订阅消息
93   - socialClientService.sendSubscribeMessage(reqDTO, template.getId(), socialUser.getOpenid());
  94 + socialClientService.sendSubscribeMessage(reqDTO, template.getPriTmplId(), socialUser.getOpenid());
94 95 }
95 96  
96 97 }
... ...