微信小程序订阅消息模版
This commit is contained in:
parent
c8747df502
commit
e78e8531bc
@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
|
||||
@ -14,6 +15,7 @@ import javax.validation.constraints.NotNull;
|
||||
@ConfigurationProperties(prefix = "yudao.web")
|
||||
@Validated
|
||||
@Data
|
||||
@Component
|
||||
public class WebProperties {
|
||||
|
||||
@NotNull(message = "APP API 不能为空")
|
||||
|
@ -114,6 +114,12 @@
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-flowable</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java-miniapp-spring-boot-starter</artifactId> <!-- 微信登录(小程序) -->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<!-- 设置构建的 jar 包名 -->
|
||||
|
@ -1,11 +1,17 @@
|
||||
package cn.iocoder.yudao.module.bpm.convert.message;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.send.SmsSendSingleToUserReqDTO;
|
||||
import org.flowable.bpmn.model.UserTask;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
@ -23,4 +29,95 @@ public interface BpmMessageConvert {
|
||||
@Mapping(source = "templateCode", target = "templateCode")
|
||||
@Mapping(source = "templateParams", target = "templateParams")
|
||||
NotifySendSingleToUserReqDTO convert1(Long userId, String templateCode, Map<String, Object> templateParams);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param openId 微信小程序唯一id
|
||||
* @param processInstanceName 流程名称
|
||||
* @param result 审批结果
|
||||
* @param reason 审批原因
|
||||
* @param miniProgramState 小程序的状态
|
||||
* @return
|
||||
*/
|
||||
default WxMaSubscribeMessage convertApprovalResultNotification(String openId, String processInstanceName, String time, String result, String reason, String miniProgramState) {
|
||||
WxMaSubscribeMessage message = new WxMaSubscribeMessage() ;
|
||||
message.setToUser(openId) ;
|
||||
message.setTemplateId("OnJjp5pdjG1PHMoELYaqp3Xq8jWZ5E6ndO0clEIQ4tk") ;
|
||||
//审批类型
|
||||
WxMaSubscribeMessage.MsgData processType = new WxMaSubscribeMessage.MsgData();
|
||||
processType.setName("thing1") ;
|
||||
processType.setValue(processInstanceName) ;
|
||||
message.addData(processType);
|
||||
|
||||
//发起时间
|
||||
WxMaSubscribeMessage.MsgData createTime = new WxMaSubscribeMessage.MsgData();
|
||||
createTime.setName("time2") ;
|
||||
createTime.setValue(time) ;
|
||||
message.addData(createTime);
|
||||
|
||||
//审批时间
|
||||
WxMaSubscribeMessage.MsgData approvalTime = new WxMaSubscribeMessage.MsgData();
|
||||
approvalTime.setName("time7") ;
|
||||
approvalTime.setValue(DateUtils.dateFormat(new Date(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)) ;
|
||||
message.addData(approvalTime);
|
||||
|
||||
//审批结果
|
||||
WxMaSubscribeMessage.MsgData approvalResult = new WxMaSubscribeMessage.MsgData();
|
||||
approvalResult.setName("phrase3") ;
|
||||
approvalResult.setValue(result) ;
|
||||
message.addData(approvalResult);
|
||||
|
||||
if(reason != null ) {
|
||||
WxMaSubscribeMessage.MsgData approvalReason = new WxMaSubscribeMessage.MsgData();
|
||||
approvalReason.setName("thing12") ;
|
||||
approvalReason.setValue(reason) ;
|
||||
message.addData(approvalReason);
|
||||
}
|
||||
|
||||
message.setMiniprogramState(miniProgramState) ;
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param openId 微信小程序唯一id
|
||||
* @param processInstanceName 流程名称
|
||||
* @param startUserNickname 申请人
|
||||
* @param time 申请时间
|
||||
* @param schedule 流程进度
|
||||
* @param miniProgramState 小程序的状态
|
||||
* @return
|
||||
*/
|
||||
default WxMaSubscribeMessage convertProcessToDoReminder(String openId, String processInstanceName,String startUserNickname, String time, String schedule, String miniProgramState) {
|
||||
WxMaSubscribeMessage message = new WxMaSubscribeMessage() ;
|
||||
message.setToUser(openId) ;
|
||||
message.setTemplateId("3cP4btlFSSiZk65qVewN_WoT_bh0OfUkYzzTsADOrR4") ;
|
||||
//待办标题
|
||||
WxMaSubscribeMessage.MsgData processType = new WxMaSubscribeMessage.MsgData();
|
||||
processType.setName("thing1") ;
|
||||
processType.setValue("您收到了一条新的待办任务:"+processInstanceName) ;
|
||||
message.addData(processType);
|
||||
|
||||
//申请人
|
||||
WxMaSubscribeMessage.MsgData applicant = new WxMaSubscribeMessage.MsgData();
|
||||
applicant.setName("thing4") ;
|
||||
applicant.setValue(startUserNickname) ;
|
||||
message.addData(applicant);
|
||||
|
||||
//申请时间
|
||||
WxMaSubscribeMessage.MsgData createTime = new WxMaSubscribeMessage.MsgData();
|
||||
createTime.setName("time5") ;
|
||||
createTime.setValue(time) ;
|
||||
message.addData(createTime);
|
||||
|
||||
//当前进度
|
||||
WxMaSubscribeMessage.MsgData currentSchedule = new WxMaSubscribeMessage.MsgData();
|
||||
currentSchedule.setName("thing6") ;
|
||||
currentSchedule.setValue(schedule) ;
|
||||
message.addData(currentSchedule);
|
||||
|
||||
message.setMiniprogramState(miniProgramState) ;
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,14 @@ import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
|
||||
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
|
||||
import cn.iocoder.yudao.module.system.api.sms.SmsSendApi;
|
||||
import cn.iocoder.yudao.module.system.api.subscribe.SubscribeMessageSendApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableFeignClients(clients = {FileApi.class,RoleApi.class, DeptApi.class, PostApi.class, AdminUserApi.class, SmsSendApi.class, DictDataApi.class, NotifyMessageSendApi.class})
|
||||
@EnableFeignClients(clients = {FileApi.class,RoleApi.class, DeptApi.class, PostApi.class, AdminUserApi.class, SmsSendApi.class, DictDataApi.class, NotifyMessageSendApi.class,
|
||||
// SubscribeMessageSendApi.class
|
||||
})
|
||||
public class RpcConfiguration {
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.message;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.framework.web.config.WebProperties;
|
||||
import cn.iocoder.yudao.module.bpm.convert.message.BpmMessageConvert;
|
||||
@ -11,13 +14,15 @@ import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCre
|
||||
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
|
||||
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.SmsSendApi;
|
||||
import cn.iocoder.yudao.module.system.api.subscribe.SubscribeMessageSendApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* BPM 消息 Service 实现类
|
||||
@ -35,11 +40,15 @@ public class BpmMessageServiceImpl implements BpmMessageService {
|
||||
@Resource
|
||||
private NotifyMessageSendApi notifyMessageSendApi;
|
||||
|
||||
@Resource
|
||||
private SubscribeMessageSendApi subscribeMessageSendApi ;
|
||||
|
||||
@Resource
|
||||
private WebProperties webProperties;
|
||||
|
||||
@Override
|
||||
public void sendMessageWhenProcessInstanceApprove(BpmMessageSendWhenProcessInstanceApproveReqDTO reqDTO) {
|
||||
//审批通过
|
||||
Map<String, Object> templateParams = new HashMap<>();
|
||||
templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
|
||||
templateParams.put("detailUrl", getProcessInstanceDetailUrl(reqDTO.getProcessInstanceId()));
|
||||
@ -47,10 +56,23 @@ public class BpmMessageServiceImpl implements BpmMessageService {
|
||||
// BpmMessageEnum.PROCESS_INSTANCE_APPROVE.getSmsTemplateCode(), templateParams));
|
||||
notifyMessageSendApi.sendSingleMessageToAdmin(BpmMessageConvert.INSTANCE.convert1(reqDTO.getStartUserId(),
|
||||
BpmMessageEnum.PROCESS_INSTANCE_APPROVE.getSmsTemplateCode(), templateParams));
|
||||
|
||||
//发送审批结果通知
|
||||
String openId = getUserOpenId(reqDTO.getStartUserId()) ;
|
||||
if(openId != null ) {
|
||||
// subscribeMessageSendApi.sendApprovalResultNotification(
|
||||
// BpmMessageConvert.INSTANCE.convertApprovalResultNotification(
|
||||
// openId,reqDTO.getProcessInstanceName(), "","通过", null,
|
||||
// /**
|
||||
// * 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||||
// */
|
||||
// WxMaConstants.MiniProgramState.DEVELOPER) ) ;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessageWhenProcessInstanceReject(BpmMessageSendWhenProcessInstanceRejectReqDTO reqDTO) {
|
||||
//审批不通过
|
||||
Map<String, Object> templateParams = new HashMap<>();
|
||||
templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
|
||||
templateParams.put("reason", reqDTO.getReason());
|
||||
@ -59,10 +81,24 @@ public class BpmMessageServiceImpl implements BpmMessageService {
|
||||
// BpmMessageEnum.PROCESS_INSTANCE_REJECT.getSmsTemplateCode(), templateParams));
|
||||
notifyMessageSendApi.sendSingleMessageToAdmin(BpmMessageConvert.INSTANCE.convert1(
|
||||
reqDTO.getStartUserId(), BpmMessageEnum.PROCESS_INSTANCE_REJECT.getSmsTemplateCode(), templateParams));
|
||||
|
||||
//发送审批结果通知
|
||||
String openId = getUserOpenId(reqDTO.getStartUserId()) ;
|
||||
if(openId != null ) {
|
||||
// subscribeMessageSendApi.sendApprovalResultNotification(
|
||||
// BpmMessageConvert.INSTANCE.convertApprovalResultNotification(
|
||||
// openId,reqDTO.getProcessInstanceName(),"","不通过", reqDTO.getReason(),
|
||||
// /**
|
||||
// * 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||||
// */
|
||||
// WxMaConstants.MiniProgramState.DEVELOPER) ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessageWhenTaskAssigned(BpmMessageSendWhenTaskCreatedReqDTO reqDTO) {
|
||||
//任务分配
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId() ;
|
||||
Long startUserId = reqDTO.getStartUserId();
|
||||
//如果发起人和接受人是同一个人,那么不发送站内信,否则就发送
|
||||
@ -76,6 +112,17 @@ public class BpmMessageServiceImpl implements BpmMessageService {
|
||||
// BpmMessageEnum.TASK_ASSIGNED.getSmsTemplateCode(), templateParams));
|
||||
notifyMessageSendApi.sendSingleMessageToAdmin(BpmMessageConvert.INSTANCE.convert1(
|
||||
reqDTO.getAssigneeUserId(), BpmMessageEnum.TASK_ASSIGNED.getSmsTemplateCode(), templateParams));
|
||||
|
||||
//发送OA流程待办提醒
|
||||
String openId = getUserOpenId(reqDTO.getStartUserId()) ;
|
||||
if(openId != null ) {
|
||||
|
||||
// subscribeMessageSendApi.sendProcessToDoReminder( BpmMessageConvert.INSTANCE.convertProcessToDoReminder(
|
||||
// openId, reqDTO.getProcessInstanceName(), reqDTO.getStartUserNickname(),"","",
|
||||
// WxMaConstants.MiniProgramState.DEVELOPER ) ) ;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,4 +131,11 @@ public class BpmMessageServiceImpl implements BpmMessageService {
|
||||
return webProperties.getAdminUi().getUrl() + "/process-instance/detail?id=" + taskId;
|
||||
}
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi ;
|
||||
private String getUserOpenId(Long userId) {
|
||||
AdminUserRespDTO adminUserRespDTO = adminUserApi.getUser(userId).getData();
|
||||
String openId = adminUserRespDTO.getOpenId() ;
|
||||
return openId ;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.system.api.subscribe.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 功能描述
|
||||
*
|
||||
* @author: yj
|
||||
* @date: 2024年02月25日 15:58
|
||||
*/
|
||||
@Data
|
||||
public class MsgData {
|
||||
|
||||
@Schema(description = "模版消息字段名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "thing1")
|
||||
@NotNull(message = "模板消息的名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "模版消息字段值", requiredMode = Schema.RequiredMode.REQUIRED, example = "OnJjp5pdjG1PHMoELYaqp3Xq8jWZ5E6ndO0clEIQ4tk")
|
||||
@NotNull(message = "模板消息的value不能为空")
|
||||
private String value;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.module.system.api.subscribe.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 功能描述
|
||||
*
|
||||
* @author: yj
|
||||
* @date: 2024年02月25日 15:50
|
||||
*/
|
||||
@Schema(description = "RPC 服务 - 微信小程序订阅消息 Request DTO")
|
||||
@Data
|
||||
public class SubscribeMessageReqDTO {
|
||||
|
||||
@Schema(description = "接收者(用户)的 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "o3bwX6Yw1bvbMAV-jUNjHrbrJu0I")
|
||||
@NotNull(message = "openid不能为空")
|
||||
private String toUser;
|
||||
|
||||
@Schema(description = "所需下发的模板消息的id", requiredMode = Schema.RequiredMode.REQUIRED, example = "OnJjp5pdjG1PHMoELYaqp3Xq8jWZ5E6ndO0clEIQ4tk")
|
||||
@NotNull(message = "模板消息的id不能为空")
|
||||
private String templateId;
|
||||
|
||||
@Schema(description = "所需下发的模板消息的属性集合", requiredMode = Schema.RequiredMode.REQUIRED, example = "OnJjp5pdjG1PHMoELYaqp3Xq8jWZ5E6ndO0clEIQ4tk")
|
||||
private List<MsgData> data;
|
||||
|
||||
@Schema(description = "跳转小程序类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "developer为开发版;trial为体验版;formal为正式版;默认为正式版")
|
||||
@NotNull(message = "跳转小程序类型不能为空")
|
||||
private String miniprogramState = "formal" ;
|
||||
|
||||
}
|
@ -27,4 +27,6 @@ public class AdminUserRespDTO {
|
||||
@Schema(description = "手机号码", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "微信小程序用户opneId", requiredMode = Schema.RequiredMode.REQUIRED, example = "o3bwX6Yw1bvbMAV-jUNjHrbrJu0I")
|
||||
private String openId;
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package cn.iocoder.yudao.module.system.api.subscribe;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.system.api.subscribe.dto.MsgData;
|
||||
import cn.iocoder.yudao.module.system.api.subscribe.dto.SubscribeMessageReqDTO;
|
||||
import lombok.SneakyThrows;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 功能描述 微信小程序发送订阅消息
|
||||
*
|
||||
* @author: yj
|
||||
* @date: 2024年02月25日 11:35
|
||||
*/
|
||||
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||
@Validated
|
||||
public class SubscribeMessageSendApiImpl implements SubscribeMessageSendApi{
|
||||
@Resource
|
||||
private WxMaSubscribeService wxMaSubscribeService ;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public CommonResult<Long> sendApprovalResultNotification(SubscribeMessageReqDTO reqDTO) {
|
||||
wxMaSubscribeService.sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
|
||||
return success(1L);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public CommonResult<Long> sendProcessToDoReminder(SubscribeMessageReqDTO reqDTO) {
|
||||
wxMaSubscribeService.sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
|
||||
return success(1L);
|
||||
}
|
||||
|
||||
private WxMaSubscribeMessage initWxMaSubscribeMessage( SubscribeMessageReqDTO reqDTO ) {
|
||||
WxMaSubscribeMessage message = new WxMaSubscribeMessage() ;
|
||||
message.setToUser(reqDTO.getToUser()) ;
|
||||
message.setTemplateId(reqDTO.getTemplateId());
|
||||
message.setMiniprogramState(reqDTO.getMiniprogramState());
|
||||
List<MsgData> dataList = reqDTO.getData() ;
|
||||
for (MsgData msgData : dataList) {
|
||||
WxMaSubscribeMessage.MsgData wxMsgData = new WxMaSubscribeMessage.MsgData() ;
|
||||
wxMsgData.setName(msgData.getName()) ;
|
||||
wxMsgData.setValue(msgData.getValue()) ;
|
||||
message.addData(wxMsgData) ;
|
||||
}
|
||||
return message ;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user