Commit 9a263f8dab735d8b8ba3829b0ac08c2adf09e351
1 parent
c4ab00ea
【新增】SYSTEM: 微信小程序订阅消息模版获取接口
Showing
8 changed files
with
125 additions
and
11 deletions
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
| ... | ... | @@ -5,10 +5,7 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 7 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 8 | -import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; | |
| 9 | -import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO; | |
| 10 | -import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | |
| 11 | -import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialWxQrcodeReqVO; | |
| 8 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.*; | |
| 12 | 9 | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; |
| 13 | 10 | import cn.iocoder.yudao.module.system.api.social.SocialUserApi; |
| 14 | 11 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| ... | ... | @@ -23,6 +20,8 @@ import jakarta.validation.Valid; |
| 23 | 20 | import org.springframework.validation.annotation.Validated; |
| 24 | 21 | import org.springframework.web.bind.annotation.*; |
| 25 | 22 | |
| 23 | +import java.util.List; | |
| 24 | + | |
| 26 | 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 27 | 26 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 28 | 27 | |
| ... | ... | @@ -72,4 +71,10 @@ public class AppSocialUserController { |
| 72 | 71 | return success(Base64.encode(wxQrcode)); |
| 73 | 72 | } |
| 74 | 73 | |
| 74 | + @GetMapping("/get-subscribe-template") | |
| 75 | + @Operation(summary = "获得微信小程订阅模板") | |
| 76 | + public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplate() { | |
| 77 | + return success(BeanUtils.toBean(socialClientApi.getSubscribeTemplate(), AppSocialWxSubscribeTemplateRespVO.class)); | |
| 78 | + } | |
| 79 | + | |
| 75 | 80 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxSubscribeTemplateRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.social.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +@Schema(description = "用户 APP - 获得小程序订阅模版 Response VO") | |
| 7 | +@Data | |
| 8 | +public class AppSocialWxSubscribeTemplateRespVO { | |
| 9 | + | |
| 10 | + @Schema(description = "添加至账号下的模板 id,发送小程序订阅消息时所需", requiredMode = Schema.RequiredMode.REQUIRED, example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU") | |
| 11 | + private String priTmplId; | |
| 12 | + | |
| 13 | + @Schema(description = "模版标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单支付通知") | |
| 14 | + private String title; | |
| 15 | + | |
| 16 | + @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 17 | + private String content; | |
| 18 | + | |
| 19 | + @Schema(description = "模板内容示例", requiredMode = Schema.RequiredMode.REQUIRED, example = "下单时间:2016年8月8日") | |
| 20 | + private String example; | |
| 21 | + | |
| 22 | + @Schema(description = "模版类型,2 为一次性订阅,3 为长期订阅", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | |
| 23 | + private Integer type; | |
| 24 | + | |
| 25 | +} | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApi.java
| ... | ... | @@ -3,9 +3,12 @@ package cn.iocoder.yudao.module.system.api.social; |
| 3 | 3 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; |
| 4 | 4 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 6 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeTemplateRespDTO; | |
| 6 | 7 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 7 | 8 | import jakarta.validation.Valid; |
| 8 | 9 | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 9 | 12 | /** |
| 10 | 13 | * 社交应用的 API 接口 |
| 11 | 14 | * |
| ... | ... | @@ -16,8 +19,8 @@ public interface SocialClientApi { |
| 16 | 19 | /** |
| 17 | 20 | * 获得社交平台的授权 URL |
| 18 | 21 | * |
| 19 | - * @param socialType 社交平台的类型 {@link SocialTypeEnum} | |
| 20 | - * @param userType 用户类型 | |
| 22 | + * @param socialType 社交平台的类型 {@link SocialTypeEnum} | |
| 23 | + * @param userType 用户类型 | |
| 21 | 24 | * @param redirectUri 重定向 URL |
| 22 | 25 | * @return 社交平台的授权 URL |
| 23 | 26 | */ |
| ... | ... | @@ -27,7 +30,7 @@ public interface SocialClientApi { |
| 27 | 30 | * 创建微信公众号 JS SDK 初始化所需的签名 |
| 28 | 31 | * |
| 29 | 32 | * @param userType 用户类型 |
| 30 | - * @param url 访问的 URL 地址 | |
| 33 | + * @param url 访问的 URL 地址 | |
| 31 | 34 | * @return 签名 |
| 32 | 35 | */ |
| 33 | 36 | SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url); |
| ... | ... | @@ -35,7 +38,7 @@ public interface SocialClientApi { |
| 35 | 38 | /** |
| 36 | 39 | * 获得微信小程序的手机信息 |
| 37 | 40 | * |
| 38 | - * @param userType 用户类型 | |
| 41 | + * @param userType 用户类型 | |
| 39 | 42 | * @param phoneCode 手机授权码 |
| 40 | 43 | * @return 手机信息 |
| 41 | 44 | */ |
| ... | ... | @@ -49,4 +52,11 @@ public interface SocialClientApi { |
| 49 | 52 | */ |
| 50 | 53 | byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO); |
| 51 | 54 | |
| 55 | + /** | |
| 56 | + * 获得微信小程订阅模板 | |
| 57 | + * | |
| 58 | + * @return 小程序订阅消息模版 | |
| 59 | + */ | |
| 60 | + List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate(); | |
| 61 | + | |
| 52 | 62 | } | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeTemplateRespDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.api.social.dto; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 小程序订阅消息模版 Response DTO | |
| 8 | + * | |
| 9 | + * @author HUIHUI | |
| 10 | + */ | |
| 11 | +@Data | |
| 12 | +public class SocialWxSubscribeTemplateRespDTO { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 添加至账号下的模板 id,发送小程序订阅消息时所需 | |
| 16 | + */ | |
| 17 | + private String priTmplId; | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 模版标题 | |
| 21 | + */ | |
| 22 | + private String title; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 模版内容 | |
| 26 | + */ | |
| 27 | + private String content; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 模板内容示例 | |
| 31 | + */ | |
| 32 | + private String example; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 模版类型,2 为一次性订阅,3 为长期订阅 | |
| 36 | + */ | |
| 37 | + private Integer type; | |
| 38 | + | |
| 39 | +} | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
| ... | ... | @@ -121,8 +121,9 @@ public interface ErrorCodeConstants { |
| 121 | 121 | |
| 122 | 122 | ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败"); |
| 123 | 123 | ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败"); |
| 124 | - ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_202, "社交客户端不存在"); | |
| 125 | - ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_203, "社交客户端已存在配置"); | |
| 124 | + ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR = new ErrorCode(1_002_018_202, "获得小程序订阅消息模版失败"); | |
| 125 | + ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_210, "社交客户端不存在"); | |
| 126 | + ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_211, "社交客户端已存在配置"); | |
| 126 | 127 | |
| 127 | 128 | |
| 128 | 129 | // ========== OAuth2 客户端 1-002-020-000 ========= | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
| ... | ... | @@ -5,12 +5,15 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; |
| 6 | 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; |
| 7 | 7 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 8 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeTemplateRespDTO; | |
| 8 | 9 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; |
| 10 | +import jakarta.annotation.Resource; | |
| 9 | 11 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 12 | +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; | |
| 10 | 13 | import org.springframework.stereotype.Service; |
| 11 | 14 | import org.springframework.validation.annotation.Validated; |
| 12 | 15 | |
| 13 | -import jakarta.annotation.Resource; | |
| 16 | +import java.util.List; | |
| 14 | 17 | |
| 15 | 18 | /** |
| 16 | 19 | * 社交应用的 API 实现类 |
| ... | ... | @@ -46,4 +49,10 @@ public class SocialClientApiImpl implements SocialClientApi { |
| 46 | 49 | return socialClientService.getWxaQrcode(reqVO); |
| 47 | 50 | } |
| 48 | 51 | |
| 52 | + @Override | |
| 53 | + public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate() { | |
| 54 | + List<TemplateInfo> subscribeTemplate = socialClientService.getSubscribeTemplate(); | |
| 55 | + return BeanUtils.toBean(subscribeTemplate, SocialWxSubscribeTemplateRespDTO.class); | |
| 56 | + } | |
| 57 | + | |
| 49 | 58 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
| ... | ... | @@ -10,6 +10,9 @@ import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 10 | 10 | import com.xingyuv.jushauth.model.AuthUser; |
| 11 | 11 | import jakarta.validation.Valid; |
| 12 | 12 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 13 | +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; | |
| 14 | + | |
| 15 | +import java.util.List; | |
| 13 | 16 | |
| 14 | 17 | /** |
| 15 | 18 | * 社交应用 Service 接口 |
| ... | ... | @@ -109,4 +112,11 @@ public interface SocialClientService { |
| 109 | 112 | */ |
| 110 | 113 | PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO); |
| 111 | 114 | |
| 115 | + /** | |
| 116 | + * 获得微信小程订阅模板 | |
| 117 | + * | |
| 118 | + * @return 微信小程订阅模板 | |
| 119 | + */ | |
| 120 | + List<TemplateInfo> getSubscribeTemplate(); | |
| 121 | + | |
| 112 | 122 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.social; |
| 2 | 2 | |
| 3 | 3 | import cn.binarywang.wx.miniapp.api.WxMaService; |
| 4 | +import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; | |
| 4 | 5 | import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
| 5 | 6 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 6 | 7 | import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; |
| ... | ... | @@ -36,6 +37,7 @@ import jakarta.annotation.Resource; |
| 36 | 37 | import lombok.SneakyThrows; |
| 37 | 38 | import lombok.extern.slf4j.Slf4j; |
| 38 | 39 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 40 | +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; | |
| 39 | 41 | import me.chanjar.weixin.common.error.WxErrorException; |
| 40 | 42 | import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; |
| 41 | 43 | import me.chanjar.weixin.mp.api.WxMpService; |
| ... | ... | @@ -46,6 +48,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; |
| 46 | 48 | import org.springframework.stereotype.Service; |
| 47 | 49 | |
| 48 | 50 | import java.time.Duration; |
| 51 | +import java.util.List; | |
| 49 | 52 | import java.util.Objects; |
| 50 | 53 | |
| 51 | 54 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -364,4 +367,16 @@ public class SocialClientServiceImpl implements SocialClientService { |
| 364 | 367 | return socialClientMapper.selectPage(pageReqVO); |
| 365 | 368 | } |
| 366 | 369 | |
| 370 | + @Override | |
| 371 | + public List<TemplateInfo> getSubscribeTemplate() { | |
| 372 | + WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue()); | |
| 373 | + try { | |
| 374 | + WxMaSubscribeService subscribeService = service.getSubscribeService(); | |
| 375 | + return subscribeService.getTemplateList(); | |
| 376 | + }catch (WxErrorException e) { | |
| 377 | + log.error("[getSubscribeTemplate][获得小程序订阅消息模版]", e); | |
| 378 | + throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR); | |
| 379 | + } | |
| 380 | + } | |
| 381 | + | |
| 367 | 382 | } | ... | ... |