Commit b917d92af5ba64231da71c7fe1e653cbc5971006

Authored by 芋道源码
Committed by Gitee
2 parents 401de303 8054847b

!1018 新增小程序订阅消息相关接口

Merge pull request !1018 from puhui999/develop
Showing 12 changed files with 266 additions and 20 deletions
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
@@ -13,4 +13,9 @@ public interface MessageTemplateConstants { @@ -13,4 +13,9 @@ public interface MessageTemplateConstants {
13 String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过) 13 String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过)
14 String BROKERAGE_WITHDRAW_AUDIT_REJECT = "brokerage_withdraw_audit_reject"; // 佣金提现(审核不通过) 14 String BROKERAGE_WITHDRAW_AUDIT_REJECT = "brokerage_withdraw_audit_reject"; // 佣金提现(审核不通过)
15 15
  16 + //======================= 订阅消息模版 =======================
  17 +
  18 + String ORDER_AFTERSALE_CHANGE = "售后进度通知";
  19 + String MONEY_CHANGE = "充值成功通知";
  20 +
16 } 21 }
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
1 package cn.iocoder.yudao.module.system.api.social; 1 package cn.iocoder.yudao.module.system.api.social;
2 2
3 -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;  
4 -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;  
5 -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; 3 +import cn.iocoder.yudao.module.system.api.social.dto.*;
6 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; 4 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
7 import jakarta.validation.Valid; 5 import jakarta.validation.Valid;
8 6
  7 +import java.util.List;
  8 +
9 /** 9 /**
10 * 社交应用的 API 接口 10 * 社交应用的 API 接口
11 * 11 *
@@ -16,8 +16,8 @@ public interface SocialClientApi { @@ -16,8 +16,8 @@ public interface SocialClientApi {
16 /** 16 /**
17 * 获得社交平台的授权 URL 17 * 获得社交平台的授权 URL
18 * 18 *
19 - * @param socialType 社交平台的类型 {@link SocialTypeEnum}  
20 - * @param userType 用户类型 19 + * @param socialType 社交平台的类型 {@link SocialTypeEnum}
  20 + * @param userType 用户类型
21 * @param redirectUri 重定向 URL 21 * @param redirectUri 重定向 URL
22 * @return 社交平台的授权 URL 22 * @return 社交平台的授权 URL
23 */ 23 */
@@ -27,7 +27,7 @@ public interface SocialClientApi { @@ -27,7 +27,7 @@ public interface SocialClientApi {
27 * 创建微信公众号 JS SDK 初始化所需的签名 27 * 创建微信公众号 JS SDK 初始化所需的签名
28 * 28 *
29 * @param userType 用户类型 29 * @param userType 用户类型
30 - * @param url 访问的 URL 地址 30 + * @param url 访问的 URL 地址
31 * @return 签名 31 * @return 签名
32 */ 32 */
33 SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url); 33 SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url);
@@ -35,7 +35,7 @@ public interface SocialClientApi { @@ -35,7 +35,7 @@ public interface SocialClientApi {
35 /** 35 /**
36 * 获得微信小程序的手机信息 36 * 获得微信小程序的手机信息
37 * 37 *
38 - * @param userType 用户类型 38 + * @param userType 用户类型
39 * @param phoneCode 手机授权码 39 * @param phoneCode 手机授权码
40 * @return 手机信息 40 * @return 手机信息
41 */ 41 */
@@ -49,4 +49,18 @@ public interface SocialClientApi { @@ -49,4 +49,18 @@ public interface SocialClientApi {
49 */ 49 */
50 byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO); 50 byte[] getWxaQrcode(@Valid SocialWxQrcodeReqDTO reqVO);
51 51
  52 + /**
  53 + * 获得微信小程订阅模板
  54 + *
  55 + * @return 小程序订阅消息模版
  56 + */
  57 + List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate();
  58 +
  59 + /**
  60 + * 发送订阅消息
  61 + *
  62 + * @param reqDTO 请求
  63 + */
  64 + void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO);
  65 +
52 } 66 }
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageReqDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.api.social.dto;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.KeyValue;
  4 +import lombok.Data;
  5 +
  6 +import java.util.ArrayList;
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * 微信小程序订阅消息 Request DTO
  11 + *
  12 + * @author HUIHUI
  13 + */
  14 +@Data
  15 +public class SocialWxSubscribeMessageReqDTO {
  16 +
  17 + /**
  18 + * 接收者(用户)的 openid.
  19 + * <pre>
  20 + * 参数:touser
  21 + * 是否必填: 是
  22 + * 描述: 接收者(用户)的 openid
  23 + * </pre>
  24 + */
  25 + private String toUser;
  26 +
  27 + /**
  28 + * 所需下发的模板消息的id.
  29 + * <pre>
  30 + * 参数:template_id
  31 + * 是否必填: 是
  32 + * 描述: 所需下发的模板消息的id
  33 + * </pre>
  34 + */
  35 + private String templateId;
  36 +
  37 + /**
  38 + * 点击模板卡片后的跳转页面,仅限本小程序内的页面.
  39 + * <pre>
  40 + * 参数:page
  41 + * 是否必填: 否
  42 + * 描述: 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  43 + * </pre>
  44 + */
  45 + private String page;
  46 +
  47 + /**
  48 + * 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
  49 + *
  50 + * 枚举 WxMaConstants.MiniProgramState
  51 + */
  52 + private String miniprogramState;
  53 +
  54 + /**
  55 + * 进入小程序查看的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
  56 + *
  57 + * 枚举 WxMaConstants.MiniProgramLang
  58 + */
  59 + private String lang;
  60 +
  61 + /**
  62 + * 模板内容,不填则下发空模板.
  63 + * <pre>
  64 + * 参数:data
  65 + * 是否必填: 是
  66 + * 描述: 模板内容,不填则下发空模板
  67 + * </pre>
  68 + */
  69 + private List<KeyValue<String, String>> messages;
  70 +
  71 + public SocialWxSubscribeMessageReqDTO addData(String key, String value) {
  72 + if (messages == null) {
  73 + messages = new ArrayList<>();
  74 + }
  75 + messages.add(new KeyValue<>(key, value));
  76 + return this;
  77 + }
  78 +
  79 +}
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,10 @@ public interface ErrorCodeConstants { @@ -121,8 +121,10 @@ 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_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR = new ErrorCode(1_002_018_203, "发送小程序订阅消息失败");
  126 + ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_210, "社交客户端不存在");
  127 + ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_211, "社交客户端已存在配置");
126 128
127 129
128 // ========== OAuth2 客户端 1-002-020-000 ========= 130 // ========== OAuth2 客户端 1-002-020-000 =========
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
@@ -2,15 +2,15 @@ package cn.iocoder.yudao.module.system.api.social; @@ -2,15 +2,15 @@ package cn.iocoder.yudao.module.system.api.social;
2 2
3 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; 3 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;  
6 -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;  
7 -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; 5 +import cn.iocoder.yudao.module.system.api.social.dto.*;
8 import cn.iocoder.yudao.module.system.service.social.SocialClientService; 6 import cn.iocoder.yudao.module.system.service.social.SocialClientService;
  7 +import jakarta.annotation.Resource;
9 import me.chanjar.weixin.common.bean.WxJsapiSignature; 8 import me.chanjar.weixin.common.bean.WxJsapiSignature;
  9 +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
10 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
11 import org.springframework.validation.annotation.Validated; 11 import org.springframework.validation.annotation.Validated;
12 12
13 -import jakarta.annotation.Resource; 13 +import java.util.List;
14 14
15 /** 15 /**
16 * 社交应用的 API 实现类 16 * 社交应用的 API 实现类
@@ -46,4 +46,15 @@ public class SocialClientApiImpl implements SocialClientApi { @@ -46,4 +46,15 @@ public class SocialClientApiImpl implements SocialClientApi {
46 return socialClientService.getWxaQrcode(reqVO); 46 return socialClientService.getWxaQrcode(reqVO);
47 } 47 }
48 48
  49 + @Override
  50 + public List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate() {
  51 + List<TemplateInfo> subscribeTemplate = socialClientService.getSubscribeTemplate();
  52 + return BeanUtils.toBean(subscribeTemplate, SocialWxSubscribeTemplateRespDTO.class);
  53 + }
  54 +
  55 + @Override
  56 + public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) {
  57 + socialClientService.sendSubscribeMessage(reqDTO);
  58 + }
  59 +
49 } 60 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.http 0 → 100644
  1 +### 请求 /system/social-client/send-subscribe-message 接口 => 发送测试订阅消息
  2 +POST {{baseUrl}}/system/social-client/send-subscribe-message
  3 +Authorization: Bearer {{token}}
  4 +#Authorization: Bearer test100
  5 +tenant-id: {{adminTenentId}}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.socail; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.socail;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  6 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageReqDTO;
6 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; 7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO; 8 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO;
8 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; 9 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
@@ -11,13 +12,12 @@ import cn.iocoder.yudao.module.system.service.social.SocialClientService; @@ -11,13 +12,12 @@ import cn.iocoder.yudao.module.system.service.social.SocialClientService;
11 import io.swagger.v3.oas.annotations.Operation; 12 import io.swagger.v3.oas.annotations.Operation;
12 import io.swagger.v3.oas.annotations.Parameter; 13 import io.swagger.v3.oas.annotations.Parameter;
13 import io.swagger.v3.oas.annotations.tags.Tag; 14 import io.swagger.v3.oas.annotations.tags.Tag;
  15 +import jakarta.annotation.Resource;
  16 +import jakarta.validation.Valid;
14 import org.springframework.security.access.prepost.PreAuthorize; 17 import org.springframework.security.access.prepost.PreAuthorize;
15 import org.springframework.validation.annotation.Validated; 18 import org.springframework.validation.annotation.Validated;
16 import org.springframework.web.bind.annotation.*; 19 import org.springframework.web.bind.annotation.*;
17 20
18 -import jakarta.annotation.Resource;  
19 -import jakarta.validation.Valid;  
20 -  
21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
22 22
23 @Tag(name = "管理后台 - 社交客户端") 23 @Tag(name = "管理后台 - 社交客户端")
@@ -70,4 +70,16 @@ public class SocialClientController { @@ -70,4 +70,16 @@ public class SocialClientController {
70 return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class)); 70 return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class));
71 } 71 }
72 72
  73 + //======================= TODO 测试发送订阅消息 =======================
  74 +
  75 + @PostMapping("/send-subscribe-message")
  76 + public void testSendSubscribeMessage() {
  77 + SocialWxSubscribeMessageReqDTO reqDTO = new SocialWxSubscribeMessageReqDTO().setLang("zh_CN")
  78 + .setMiniprogramState("developer").setTemplateId("W4ybDTIwCfKHtMKR7fSfx83DtmVKEeXQo3Ti7GCw4_4")
  79 + .setToUser("oKNkb4xxw2H135-MVPKtEMkumK08");
  80 + reqDTO.addData("character_string1", "11111111").addData("amount2", "6666").addData("time3", "2024-01-01 10:10:10")
  81 + .addData("phrase4", "成功");
  82 + socialClientService.sendSubscribeMessage(reqDTO);
  83 + }
  84 +
73 } 85 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.social; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.social;
3 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; 3 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.SocialWxSubscribeMessageReqDTO;
6 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; 7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; 8 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
8 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; 9 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
@@ -10,6 +11,9 @@ import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; @@ -10,6 +11,9 @@ import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
10 import com.xingyuv.jushauth.model.AuthUser; 11 import com.xingyuv.jushauth.model.AuthUser;
11 import jakarta.validation.Valid; 12 import jakarta.validation.Valid;
12 import me.chanjar.weixin.common.bean.WxJsapiSignature; 13 import me.chanjar.weixin.common.bean.WxJsapiSignature;
  14 +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
  15 +
  16 +import java.util.List;
13 17
14 /** 18 /**
15 * 社交应用 Service 接口 19 * 社交应用 Service 接口
@@ -69,6 +73,20 @@ public interface SocialClientService { @@ -69,6 +73,20 @@ public interface SocialClientService {
69 */ 73 */
70 byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO); 74 byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO);
71 75
  76 + /**
  77 + * 获得微信小程订阅模板
  78 + *
  79 + * @return 微信小程订阅模板
  80 + */
  81 + List<TemplateInfo> getSubscribeTemplate();
  82 +
  83 + /**
  84 + * 发送订阅消息
  85 + *
  86 + * @param reqDTO 请求
  87 + */
  88 + void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO);
  89 +
72 // =================== 客户端管理 =================== 90 // =================== 客户端管理 ===================
73 91
74 /** 92 /**
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;
  7 +import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
6 import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; 8 import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
7 import cn.hutool.core.bean.BeanUtil; 9 import cn.hutool.core.bean.BeanUtil;
8 import cn.hutool.core.lang.Assert; 10 import cn.hutool.core.lang.Assert;
@@ -15,6 +17,7 @@ import cn.iocoder.yudao.framework.common.util.cache.CacheUtils; @@ -15,6 +17,7 @@ import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
15 import cn.iocoder.yudao.framework.common.util.http.HttpUtils; 17 import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
16 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 18 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
17 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO; 19 import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
  20 +import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageReqDTO;
18 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; 21 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
19 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; 22 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
20 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; 23 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
@@ -36,6 +39,7 @@ import jakarta.annotation.Resource; @@ -36,6 +39,7 @@ import jakarta.annotation.Resource;
36 import lombok.SneakyThrows; 39 import lombok.SneakyThrows;
37 import lombok.extern.slf4j.Slf4j; 40 import lombok.extern.slf4j.Slf4j;
38 import me.chanjar.weixin.common.bean.WxJsapiSignature; 41 import me.chanjar.weixin.common.bean.WxJsapiSignature;
  42 +import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
39 import me.chanjar.weixin.common.error.WxErrorException; 43 import me.chanjar.weixin.common.error.WxErrorException;
40 import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; 44 import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
41 import me.chanjar.weixin.mp.api.WxMpService; 45 import me.chanjar.weixin.mp.api.WxMpService;
@@ -46,6 +50,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; @@ -46,6 +50,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
46 import org.springframework.stereotype.Service; 50 import org.springframework.stereotype.Service;
47 51
48 import java.time.Duration; 52 import java.time.Duration;
  53 +import java.util.List;
49 import java.util.Objects; 54 import java.util.Objects;
50 55
51 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 56 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -255,6 +260,32 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -255,6 +260,32 @@ public class SocialClientServiceImpl implements SocialClientService {
255 } 260 }
256 } 261 }
257 262
  263 + @Override
  264 + public List<TemplateInfo> getSubscribeTemplate() {
  265 + WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
  266 + try {
  267 + WxMaSubscribeService subscribeService = service.getSubscribeService();
  268 + return subscribeService.getTemplateList();
  269 + }catch (WxErrorException e) {
  270 + log.error("[getSubscribeTemplate][获得小程序订阅消息模版]", e);
  271 + throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR);
  272 + }
  273 + }
  274 +
  275 + @Override
  276 + public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) {
  277 + WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
  278 + try {
  279 + WxMaSubscribeService subscribeService = service.getSubscribeService();
  280 + WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class);
  281 + reqDTO.getMessages().forEach(item-> message.addData(new WxMaSubscribeMessage.MsgData(item.getKey(), item.getValue())));
  282 + subscribeService.sendSubscribeMsg(message);
  283 + }catch (WxErrorException e) {
  284 + log.error("[sendSubscribeMessage][发送小程序订阅消息]", e);
  285 + throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR);
  286 + }
  287 + }
  288 +
258 /** 289 /**
259 * 获得 clientId + clientSecret 对应的 WxMpService 对象 290 * 获得 clientId + clientSecret 对应的 WxMpService 对象
260 * 291 *