Commit 8054847b05bb10f6e9fc0f934c2c257a29dd7e86

Authored by puhui999
1 parent 63e319e6

【新增】SYSTEM: 发送微信小程序订阅消息测试接口

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-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialWxSubscribeMessageReqDTO.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.api.social.dto; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.api.social.dto;
3 import cn.iocoder.yudao.framework.common.core.KeyValue; 3 import cn.iocoder.yudao.framework.common.core.KeyValue;
4 import lombok.Data; 4 import lombok.Data;
5 5
  6 +import java.util.ArrayList;
6 import java.util.List; 7 import java.util.List;
7 8
8 /** 9 /**
@@ -65,6 +66,14 @@ public class SocialWxSubscribeMessageReqDTO { @@ -65,6 +66,14 @@ public class SocialWxSubscribeMessageReqDTO {
65 * 描述: 模板内容,不填则下发空模板 66 * 描述: 模板内容,不填则下发空模板
66 * </pre> 67 * </pre>
67 */ 68 */
68 - private List<KeyValue<String, String>> data; 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 + }
69 78
70 } 79 }
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/SocialClientServiceImpl.java
@@ -278,7 +278,7 @@ public class SocialClientServiceImpl implements SocialClientService { @@ -278,7 +278,7 @@ public class SocialClientServiceImpl implements SocialClientService {
278 try { 278 try {
279 WxMaSubscribeService subscribeService = service.getSubscribeService(); 279 WxMaSubscribeService subscribeService = service.getSubscribeService();
280 WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class); 280 WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class);
281 - reqDTO.getData().forEach(item-> message.addData(new WxMaSubscribeMessage.MsgData(item.getKey(), item.getValue()))); 281 + reqDTO.getMessages().forEach(item-> message.addData(new WxMaSubscribeMessage.MsgData(item.getKey(), item.getValue())));
282 subscribeService.sendSubscribeMsg(message); 282 subscribeService.sendSubscribeMsg(message);
283 }catch (WxErrorException e) { 283 }catch (WxErrorException e) {
284 log.error("[sendSubscribeMessage][发送小程序订阅消息]", e); 284 log.error("[sendSubscribeMessage][发送小程序订阅消息]", e);