mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 20:28:44 +08:00 
			
		
		
		
	【新增】SYSTEM: 发送微信小程序订阅消息
This commit is contained in:
		@@ -1,9 +1,6 @@
 | 
				
			|||||||
package cn.iocoder.yudao.module.system.api.social;
 | 
					package cn.iocoder.yudao.module.system.api.social;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
 | 
					import cn.iocoder.yudao.module.system.api.social.dto.*;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
 | 
					 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
 | 
					 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeTemplateRespDTO;
 | 
					 | 
				
			||||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
 | 
					import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
 | 
				
			||||||
import jakarta.validation.Valid;
 | 
					import jakarta.validation.Valid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -59,4 +56,11 @@ public interface SocialClientApi {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate();
 | 
					    List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 发送订阅消息
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param reqDTO 请求
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,70 @@
 | 
				
			|||||||
 | 
					package cn.iocoder.yudao.module.system.api.social.dto;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import cn.iocoder.yudao.framework.common.core.KeyValue;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 微信小程序订阅消息 Request DTO
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author HUIHUI
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					public class SocialWxSubscribeMessageReqDTO {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 接收者(用户)的 openid.
 | 
				
			||||||
 | 
					     * <pre>
 | 
				
			||||||
 | 
					     * 参数:touser
 | 
				
			||||||
 | 
					     * 是否必填: 是
 | 
				
			||||||
 | 
					     * 描述: 接收者(用户)的 openid
 | 
				
			||||||
 | 
					     * </pre>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String toUser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 所需下发的模板消息的id.
 | 
				
			||||||
 | 
					     * <pre>
 | 
				
			||||||
 | 
					     * 参数:template_id
 | 
				
			||||||
 | 
					     * 是否必填: 是
 | 
				
			||||||
 | 
					     * 描述: 所需下发的模板消息的id
 | 
				
			||||||
 | 
					     * </pre>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String templateId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 点击模板卡片后的跳转页面,仅限本小程序内的页面.
 | 
				
			||||||
 | 
					     * <pre>
 | 
				
			||||||
 | 
					     * 参数:page
 | 
				
			||||||
 | 
					     * 是否必填: 否
 | 
				
			||||||
 | 
					     * 描述: 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
 | 
				
			||||||
 | 
					     * </pre>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String page;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * 枚举 WxMaConstants.MiniProgramState
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String miniprogramState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 进入小程序查看的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * 枚举 WxMaConstants.MiniProgramLang
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String lang;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 模板内容,不填则下发空模板.
 | 
				
			||||||
 | 
					     * <pre>
 | 
				
			||||||
 | 
					     * 参数:data
 | 
				
			||||||
 | 
					     * 是否必填: 是
 | 
				
			||||||
 | 
					     * 描述: 模板内容,不填则下发空模板
 | 
				
			||||||
 | 
					     * </pre>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private List<KeyValue<String, String>> data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -122,6 +122,7 @@ public interface ErrorCodeConstants {
 | 
				
			|||||||
    ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败");
 | 
					    ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败");
 | 
				
			||||||
    ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败");
 | 
					    ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败");
 | 
				
			||||||
    ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR = new ErrorCode(1_002_018_202, "获得小程序订阅消息模版失败");
 | 
					    ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR = new ErrorCode(1_002_018_202, "获得小程序订阅消息模版失败");
 | 
				
			||||||
 | 
					    ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR = new ErrorCode(1_002_018_203, "发送小程序订阅消息失败");
 | 
				
			||||||
    ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_210, "社交客户端不存在");
 | 
					    ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_210, "社交客户端不存在");
 | 
				
			||||||
    ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_211, "社交客户端已存在配置");
 | 
					    ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_211, "社交客户端已存在配置");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.system.api.social;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
 | 
					import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
 | 
				
			||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
					import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
 | 
					import cn.iocoder.yudao.module.system.api.social.dto.*;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
 | 
					 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
 | 
					 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeTemplateRespDTO;
 | 
					 | 
				
			||||||
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
 | 
					import cn.iocoder.yudao.module.system.service.social.SocialClientService;
 | 
				
			||||||
import jakarta.annotation.Resource;
 | 
					import jakarta.annotation.Resource;
 | 
				
			||||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
 | 
					import me.chanjar.weixin.common.bean.WxJsapiSignature;
 | 
				
			||||||
@@ -55,4 +52,9 @@ public class SocialClientApiImpl implements SocialClientApi {
 | 
				
			|||||||
        return BeanUtils.toBean(subscribeTemplate, SocialWxSubscribeTemplateRespDTO.class);
 | 
					        return BeanUtils.toBean(subscribeTemplate, SocialWxSubscribeTemplateRespDTO.class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) {
 | 
				
			||||||
 | 
					        socialClientService.sendSubscribeMessage(reqDTO);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.social;
 | 
				
			|||||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
 | 
					import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
 | 
				
			||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
					import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
 | 
					import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
 | 
				
			||||||
 | 
					import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageReqDTO;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
 | 
					import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
 | 
					import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
 | 
					import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
 | 
				
			||||||
@@ -72,6 +73,20 @@ public interface SocialClientService {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO);
 | 
					    byte[] getWxaQrcode(SocialWxQrcodeReqDTO reqVO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 获得微信小程订阅模板
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return 微信小程订阅模板
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    List<TemplateInfo> getSubscribeTemplate();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 发送订阅消息
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param reqDTO 请求
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // =================== 客户端管理 ===================
 | 
					    // =================== 客户端管理 ===================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -112,11 +127,4 @@ public interface SocialClientService {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO);
 | 
					    PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * 获得微信小程订阅模板
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return 微信小程订阅模板
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    List<TemplateInfo> getSubscribeTemplate();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
 | 
				
			|||||||
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
 | 
					import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
 | 
				
			||||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
 | 
					import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
 | 
				
			||||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
 | 
					import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
 | 
				
			||||||
 | 
					import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
 | 
				
			||||||
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
 | 
					import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
 | 
				
			||||||
import cn.hutool.core.bean.BeanUtil;
 | 
					import cn.hutool.core.bean.BeanUtil;
 | 
				
			||||||
import cn.hutool.core.lang.Assert;
 | 
					import cn.hutool.core.lang.Assert;
 | 
				
			||||||
@@ -16,6 +17,7 @@ import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
 | 
				
			|||||||
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
 | 
					import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
 | 
				
			||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
					import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
 | 
					import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
 | 
				
			||||||
 | 
					import cn.iocoder.yudao.module.system.api.social.dto.SocialWxSubscribeMessageReqDTO;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
 | 
					import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
 | 
					import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO;
 | 
				
			||||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
 | 
					import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
 | 
				
			||||||
@@ -258,6 +260,32 @@ public class SocialClientServiceImpl implements SocialClientService {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<TemplateInfo> getSubscribeTemplate() {
 | 
				
			||||||
 | 
					        WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            WxMaSubscribeService subscribeService = service.getSubscribeService();
 | 
				
			||||||
 | 
					            return subscribeService.getTemplateList();
 | 
				
			||||||
 | 
					        }catch (WxErrorException e) {
 | 
				
			||||||
 | 
					            log.error("[getSubscribeTemplate][获得小程序订阅消息模版]", e);
 | 
				
			||||||
 | 
					            throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) {
 | 
				
			||||||
 | 
					        WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            WxMaSubscribeService subscribeService = service.getSubscribeService();
 | 
				
			||||||
 | 
					            WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class);
 | 
				
			||||||
 | 
					            reqDTO.getData().forEach(item-> message.addData(new WxMaSubscribeMessage.MsgData(item.getKey(), item.getValue())));
 | 
				
			||||||
 | 
					            subscribeService.sendSubscribeMsg(message);
 | 
				
			||||||
 | 
					        }catch (WxErrorException e) {
 | 
				
			||||||
 | 
					            log.error("[sendSubscribeMessage][发送小程序订阅消息]", e);
 | 
				
			||||||
 | 
					            throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 获得 clientId + clientSecret 对应的 WxMpService 对象
 | 
					     * 获得 clientId + clientSecret 对应的 WxMpService 对象
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -367,16 +395,4 @@ public class SocialClientServiceImpl implements SocialClientService {
 | 
				
			|||||||
        return socialClientMapper.selectPage(pageReqVO);
 | 
					        return socialClientMapper.selectPage(pageReqVO);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<TemplateInfo> getSubscribeTemplate() {
 | 
					 | 
				
			||||||
        WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            WxMaSubscribeService subscribeService = service.getSubscribeService();
 | 
					 | 
				
			||||||
            return subscribeService.getTemplateList();
 | 
					 | 
				
			||||||
        }catch (WxErrorException e) {
 | 
					 | 
				
			||||||
            log.error("[getSubscribeTemplate][获得小程序订阅消息模版]", e);
 | 
					 | 
				
			||||||
            throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user