微信公众号配置、OA审批通知、待办提醒底层消息推送代码。

This commit is contained in:
Echo 2024-11-15 11:45:50 +08:00
parent 4a3d32c0a4
commit a68f23c844
6 changed files with 57 additions and 6 deletions

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.system.api.subscribe.dto;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
import javax.validation.constraints.NotNull;
@ -15,6 +17,7 @@ import java.util.List;
*/
@Schema(description = "RPC 服务 - 微信小程序订阅消息 Request DTO")
@Data
@Builder
public class SubscribeMessageReqDTO {
@Schema(description = "接收者(用户)的 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "o3bwX6Yw1bvbMAV-jUNjHrbrJu0I")
@ -39,4 +42,8 @@ public class SubscribeMessageReqDTO {
public void addData(MsgData data) {
this.data.add(data);
}
@Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1:小程序模版2公众号模版")
@Builder.Default
private String minOrMpType = "1" ;
}

View File

@ -7,10 +7,13 @@ import cn.iocoder.yudao.module.system.api.subscribe.dto.SubscribeMessageReqDTO;
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -32,14 +35,26 @@ public class SubscribeMessageSendApiImpl implements SubscribeMessageSendApi {
@SneakyThrows
@Override
public CommonResult<Long> sendApprovalResultNotification(SubscribeMessageReqDTO reqDTO) {
socialClientService.getWxMaService().getMsgService().sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
//发送审批结果通知
String type = reqDTO.getMinOrMpType() ;
if( type == null || type.equals("1") ) {
socialClientService.getWxMpService().getTemplateMsgService().sendTemplateMsg(initWxMpSubscribeMessage(reqDTO)) ;
} else {
socialClientService.getWxMaService().getMsgService().sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
}
return success(1L);
}
@SneakyThrows
@Override
public CommonResult<Long> sendProcessToDoReminder(SubscribeMessageReqDTO reqDTO) {
socialClientService.getWxMaService().getMsgService().sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
//发送OA流程待办提醒
String type = reqDTO.getMinOrMpType() ;
if( type == null || type.equals("1") ) {
socialClientService.getWxMpService().getTemplateMsgService().sendTemplateMsg(initWxMpSubscribeMessage(reqDTO)) ;
} else {
socialClientService.getWxMaService().getMsgService().sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
}
return success(1L);
}
@ -84,4 +99,21 @@ public class SubscribeMessageSendApiImpl implements SubscribeMessageSendApi {
return message;
}
private WxMpTemplateMessage initWxMpSubscribeMessage(SubscribeMessageReqDTO reqDTO){
List<MsgData> dataList = reqDTO.getData();
List<WxMpTemplateData> data = new ArrayList<>();
for (MsgData msgData : dataList) {
WxMpTemplateData wxMpTemplateData = new WxMpTemplateData();
wxMpTemplateData.setName(msgData.getName());
wxMpTemplateData.setValue(msgData.getValue());
data.add(wxMpTemplateData) ;
}
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(reqDTO.getToUser())
.templateId(reqDTO.getTemplateId())
.data(data)
.build();
return templateMessage ;
}
}

View File

@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import com.xingyuv.jushauth.model.AuthUser;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.mp.api.WxMpService;
import javax.validation.Valid;
@ -52,6 +53,12 @@ public interface SocialClientService {
*/
WxJsapiSignature createWxMpJsapiSignature(Integer userType, String url);
/**
* 获取WxMpService
* @return
*/
WxMpService getWxMpService() ;
// =================== 微信小程序独有 ===================
/**

View File

@ -68,6 +68,11 @@ public class SocialClientServiceImpl implements SocialClientService {
private WxMpProperties wxMpProperties;
@Resource
private StringRedisTemplate stringRedisTemplate; // WxMpService 需要使用到所以在 Service 注入了它
@Override
public WxMpService getWxMpService() {
return getWxMpService(2) ;
}
/**
* 缓存 WxMpService 对象
*

View File

@ -127,8 +127,8 @@ wx:
mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
# app-id: wx041349c6f39b268b
# secret: 5abee519483bc9f8cb37ce280e814bd0
app-id: wx5b23ba7a5589ecbb # 测试号
secret: 2a7b3b20c537e52e74afd395eb85f61f
app-id: wx9943f95048ba8472
secret: f1f5625f210142b6ae31a06c699826df
# 存储配置,解决 AccessToken 的跨节点的共享
config-storage:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis会自动从 Spring 中获取

View File

@ -140,8 +140,8 @@ wx:
mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
# app-id: wx041349c6f39b268b
# secret: 5abee519483bc9f8cb37ce280e814bd0
app-id: wx5b23ba7a5589ecbb # 测试号
secret: 2a7b3b20c537e52e74afd395eb85f61f
app-id: wx9943f95048ba8472
secret: f1f5625f210142b6ae31a06c699826df
# 存储配置,解决 AccessToken 的跨节点的共享
config-storage:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis会自动从 Spring 中获取