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,10 +5,7 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | 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 | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; | 9 | import cn.iocoder.yudao.module.system.api.social.SocialClientApi; |
| 13 | import cn.iocoder.yudao.module.system.api.social.SocialUserApi; | 10 | import cn.iocoder.yudao.module.system.api.social.SocialUserApi; |
| 14 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | 11 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| @@ -23,6 +20,8 @@ import jakarta.validation.Valid; | @@ -23,6 +20,8 @@ import jakarta.validation.Valid; | ||
| 23 | import org.springframework.validation.annotation.Validated; | 20 | import org.springframework.validation.annotation.Validated; |
| 24 | import org.springframework.web.bind.annotation.*; | 21 | import org.springframework.web.bind.annotation.*; |
| 25 | 22 | ||
| 23 | +import java.util.List; | ||
| 24 | + | ||
| 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 27 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 26 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 28 | 27 | ||
| @@ -72,4 +71,10 @@ public class AppSocialUserController { | @@ -72,4 +71,10 @@ public class AppSocialUserController { | ||
| 72 | return success(Base64.encode(wxQrcode)); | 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,9 +3,12 @@ package cn.iocoder.yudao.module.system.api.social; | ||
| 3 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | 3 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; |
| 4 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | 4 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; |
| 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 6 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeTemplateRespDTO; | ||
| 6 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 7 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 7 | import jakarta.validation.Valid; | 8 | import jakarta.validation.Valid; |
| 8 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 9 | /** | 12 | /** |
| 10 | * 社交应用的 API 接口 | 13 | * 社交应用的 API 接口 |
| 11 | * | 14 | * |
| @@ -16,8 +19,8 @@ public interface SocialClientApi { | @@ -16,8 +19,8 @@ public interface SocialClientApi { | ||
| 16 | /** | 19 | /** |
| 17 | * 获得社交平台的授权 URL | 20 | * 获得社交平台的授权 URL |
| 18 | * | 21 | * |
| 19 | - * @param socialType 社交平台的类型 {@link SocialTypeEnum} | ||
| 20 | - * @param userType 用户类型 | 22 | + * @param socialType 社交平台的类型 {@link SocialTypeEnum} |
| 23 | + * @param userType 用户类型 | ||
| 21 | * @param redirectUri 重定向 URL | 24 | * @param redirectUri 重定向 URL |
| 22 | * @return 社交平台的授权 URL | 25 | * @return 社交平台的授权 URL |
| 23 | */ | 26 | */ |
| @@ -27,7 +30,7 @@ public interface SocialClientApi { | @@ -27,7 +30,7 @@ public interface SocialClientApi { | ||
| 27 | * 创建微信公众号 JS SDK 初始化所需的签名 | 30 | * 创建微信公众号 JS SDK 初始化所需的签名 |
| 28 | * | 31 | * |
| 29 | * @param userType 用户类型 | 32 | * @param userType 用户类型 |
| 30 | - * @param url 访问的 URL 地址 | 33 | + * @param url 访问的 URL 地址 |
| 31 | * @return 签名 | 34 | * @return 签名 |
| 32 | */ | 35 | */ |
| 33 | SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url); | 36 | SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url); |
| @@ -35,7 +38,7 @@ public interface SocialClientApi { | @@ -35,7 +38,7 @@ public interface SocialClientApi { | ||
| 35 | /** | 38 | /** |
| 36 | * 获得微信小程序的手机信息 | 39 | * 获得微信小程序的手机信息 |
| 37 | * | 40 | * |
| 38 | - * @param userType 用户类型 | 41 | + * @param userType 用户类型 |
| 39 | * @param phoneCode 手机授权码 | 42 | * @param phoneCode 手机授权码 |
| 40 | * @return 手机信息 | 43 | * @return 手机信息 |
| 41 | */ | 44 | */ |
| @@ -49,4 +52,11 @@ public interface SocialClientApi { | @@ -49,4 +52,11 @@ public interface SocialClientApi { | ||
| 49 | */ | 52 | */ |
| 50 | byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO); | 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,8 +121,9 @@ public interface ErrorCodeConstants { | ||
| 121 | 121 | ||
| 122 | ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败"); | 122 | ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败"); |
| 123 | ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败"); | 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 | // ========== OAuth2 客户端 1-002-020-000 ========= | 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,12 +5,15 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; |
| 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; | 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; |
| 7 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; | 7 | import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; |
| 8 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeTemplateRespDTO; | ||
| 8 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; | 9 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; |
| 10 | +import jakarta.annotation.Resource; | ||
| 9 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 11 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 12 | +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; | ||
| 10 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.validation.annotation.Validated; | 14 | import org.springframework.validation.annotation.Validated; |
| 12 | 15 | ||
| 13 | -import jakarta.annotation.Resource; | 16 | +import java.util.List; |
| 14 | 17 | ||
| 15 | /** | 18 | /** |
| 16 | * 社交应用的 API 实现类 | 19 | * 社交应用的 API 实现类 |
| @@ -46,4 +49,10 @@ public class SocialClientApiImpl implements SocialClientApi { | @@ -46,4 +49,10 @@ public class SocialClientApiImpl implements SocialClientApi { | ||
| 46 | return socialClientService.getWxaQrcode(reqVO); | 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,6 +10,9 @@ import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | ||
| 10 | import com.xingyuv.jushauth.model.AuthUser; | 10 | import com.xingyuv.jushauth.model.AuthUser; |
| 11 | import jakarta.validation.Valid; | 11 | import jakarta.validation.Valid; |
| 12 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 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 | * 社交应用 Service 接口 | 18 | * 社交应用 Service 接口 |
| @@ -109,4 +112,11 @@ public interface SocialClientService { | @@ -109,4 +112,11 @@ public interface SocialClientService { | ||
| 109 | */ | 112 | */ |
| 110 | PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO); | 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 | package cn.iocoder.yudao.module.system.service.social; | 1 | package cn.iocoder.yudao.module.system.service.social; |
| 2 | 2 | ||
| 3 | import cn.binarywang.wx.miniapp.api.WxMaService; | 3 | import cn.binarywang.wx.miniapp.api.WxMaService; |
| 4 | +import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; | ||
| 4 | import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; | 5 | import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
| 5 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | 6 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 6 | import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; | 7 | import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; |
| @@ -36,6 +37,7 @@ import jakarta.annotation.Resource; | @@ -36,6 +37,7 @@ import jakarta.annotation.Resource; | ||
| 36 | import lombok.SneakyThrows; | 37 | import lombok.SneakyThrows; |
| 37 | import lombok.extern.slf4j.Slf4j; | 38 | import lombok.extern.slf4j.Slf4j; |
| 38 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 39 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 40 | +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; | ||
| 39 | import me.chanjar.weixin.common.error.WxErrorException; | 41 | import me.chanjar.weixin.common.error.WxErrorException; |
| 40 | import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; | 42 | import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; |
| 41 | import me.chanjar.weixin.mp.api.WxMpService; | 43 | import me.chanjar.weixin.mp.api.WxMpService; |
| @@ -46,6 +48,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; | @@ -46,6 +48,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; | ||
| 46 | import org.springframework.stereotype.Service; | 48 | import org.springframework.stereotype.Service; |
| 47 | 49 | ||
| 48 | import java.time.Duration; | 50 | import java.time.Duration; |
| 51 | +import java.util.List; | ||
| 49 | import java.util.Objects; | 52 | import java.util.Objects; |
| 50 | 53 | ||
| 51 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 54 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -364,4 +367,16 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -364,4 +367,16 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 364 | return socialClientMapper.selectPage(pageReqVO); | 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 | } |