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