微信公众号配置、OA审批通知、待办提醒底层消息推送代码。
This commit is contained in:
parent
4a3d32c0a4
commit
a68f23c844
@ -1,6 +1,8 @@
|
|||||||
package cn.iocoder.yudao.module.system.api.subscribe.dto;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
@ -15,6 +17,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Schema(description = "RPC 服务 - 微信小程序订阅消息 Request DTO")
|
@Schema(description = "RPC 服务 - 微信小程序订阅消息 Request DTO")
|
||||||
@Data
|
@Data
|
||||||
|
@Builder
|
||||||
public class SubscribeMessageReqDTO {
|
public class SubscribeMessageReqDTO {
|
||||||
|
|
||||||
@Schema(description = "接收者(用户)的 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "o3bwX6Yw1bvbMAV-jUNjHrbrJu0I")
|
@Schema(description = "接收者(用户)的 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "o3bwX6Yw1bvbMAV-jUNjHrbrJu0I")
|
||||||
@ -39,4 +42,8 @@ public class SubscribeMessageReqDTO {
|
|||||||
public void addData(MsgData data) {
|
public void addData(MsgData data) {
|
||||||
this.data.add(data);
|
this.data.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1:小程序模版:2:公众号模版")
|
||||||
|
@Builder.Default
|
||||||
|
private String minOrMpType = "1" ;
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,13 @@ import cn.iocoder.yudao.module.system.api.subscribe.dto.SubscribeMessageReqDTO;
|
|||||||
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
|
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
@ -32,14 +35,26 @@ public class SubscribeMessageSendApiImpl implements SubscribeMessageSendApi {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Long> sendApprovalResultNotification(SubscribeMessageReqDTO reqDTO) {
|
public CommonResult<Long> sendApprovalResultNotification(SubscribeMessageReqDTO reqDTO) {
|
||||||
|
//发送审批结果通知
|
||||||
|
String type = reqDTO.getMinOrMpType() ;
|
||||||
|
if( type == null || type.equals("1") ) {
|
||||||
|
socialClientService.getWxMpService().getTemplateMsgService().sendTemplateMsg(initWxMpSubscribeMessage(reqDTO)) ;
|
||||||
|
} else {
|
||||||
socialClientService.getWxMaService().getMsgService().sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
|
socialClientService.getWxMaService().getMsgService().sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
|
||||||
|
}
|
||||||
return success(1L);
|
return success(1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Long> sendProcessToDoReminder(SubscribeMessageReqDTO reqDTO) {
|
public CommonResult<Long> sendProcessToDoReminder(SubscribeMessageReqDTO 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));
|
socialClientService.getWxMaService().getMsgService().sendSubscribeMsg(initWxMaSubscribeMessage(reqDTO));
|
||||||
|
}
|
||||||
return success(1L);
|
return success(1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,4 +99,21 @@ public class SubscribeMessageSendApiImpl implements SubscribeMessageSendApi {
|
|||||||
return message;
|
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 ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
|||||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||||
import com.xingyuv.jushauth.model.AuthUser;
|
import com.xingyuv.jushauth.model.AuthUser;
|
||||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
@ -52,6 +53,12 @@ public interface SocialClientService {
|
|||||||
*/
|
*/
|
||||||
WxJsapiSignature createWxMpJsapiSignature(Integer userType, String url);
|
WxJsapiSignature createWxMpJsapiSignature(Integer userType, String url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取WxMpService
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
WxMpService getWxMpService() ;
|
||||||
|
|
||||||
// =================== 微信小程序独有 ===================
|
// =================== 微信小程序独有 ===================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,6 +68,11 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||||||
private WxMpProperties wxMpProperties;
|
private WxMpProperties wxMpProperties;
|
||||||
@Resource
|
@Resource
|
||||||
private StringRedisTemplate stringRedisTemplate; // WxMpService 需要使用到,所以在 Service 注入了它
|
private StringRedisTemplate stringRedisTemplate; // WxMpService 需要使用到,所以在 Service 注入了它
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxMpService getWxMpService() {
|
||||||
|
return getWxMpService(2) ;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 缓存 WxMpService 对象
|
* 缓存 WxMpService 对象
|
||||||
*
|
*
|
||||||
|
@ -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 文档
|
mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
|
||||||
# app-id: wx041349c6f39b268b
|
# app-id: wx041349c6f39b268b
|
||||||
# secret: 5abee519483bc9f8cb37ce280e814bd0
|
# secret: 5abee519483bc9f8cb37ce280e814bd0
|
||||||
app-id: wx5b23ba7a5589ecbb # 测试号
|
app-id: wx9943f95048ba8472
|
||||||
secret: 2a7b3b20c537e52e74afd395eb85f61f
|
secret: f1f5625f210142b6ae31a06c699826df
|
||||||
# 存储配置,解决 AccessToken 的跨节点的共享
|
# 存储配置,解决 AccessToken 的跨节点的共享
|
||||||
config-storage:
|
config-storage:
|
||||||
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
|
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
|
||||||
|
@ -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 文档
|
mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
|
||||||
# app-id: wx041349c6f39b268b
|
# app-id: wx041349c6f39b268b
|
||||||
# secret: 5abee519483bc9f8cb37ce280e814bd0
|
# secret: 5abee519483bc9f8cb37ce280e814bd0
|
||||||
app-id: wx5b23ba7a5589ecbb # 测试号
|
app-id: wx9943f95048ba8472
|
||||||
secret: 2a7b3b20c537e52e74afd395eb85f61f
|
secret: f1f5625f210142b6ae31a06c699826df
|
||||||
# 存储配置,解决 AccessToken 的跨节点的共享
|
# 存储配置,解决 AccessToken 的跨节点的共享
|
||||||
config-storage:
|
config-storage:
|
||||||
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
|
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
|
||||||
|
Loading…
Reference in New Issue
Block a user