企业微信小程序消息卡片
This commit is contained in:
+44
-5
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.farm.annotation;
|
|||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO;
|
import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO;
|
||||||
@@ -19,20 +20,25 @@ import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO;
|
|||||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper;
|
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper;
|
||||||
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
|
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import me.chanjar.weixin.cp.api.WxCpMessageService;
|
import me.chanjar.weixin.cp.api.WxCpMessageService;
|
||||||
import me.chanjar.weixin.cp.api.WxCpService;
|
import me.chanjar.weixin.cp.api.WxCpService;
|
||||||
|
import me.chanjar.weixin.cp.bean.message.WxCpAppChatMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
||||||
|
import me.chanjar.weixin.cp.bean.messagebuilder.MiniProgramNoticeMsgBuilder;
|
||||||
|
import me.chanjar.weixin.cp.tp.message.WxCpTpMessageHandler;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.*;
|
import org.aspectj.lang.annotation.*;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
@@ -61,6 +67,9 @@ public class FarmMsgAspect {
|
|||||||
@Resource
|
@Resource
|
||||||
private WxCpService wxCpService;
|
private WxCpService wxCpService;
|
||||||
|
|
||||||
|
@Value("${wxma.app_id}")
|
||||||
|
private String appid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义切入点 @PointCut
|
* 定义切入点 @PointCut
|
||||||
* 使用了@FarmMsg注解的地方切入
|
* 使用了@FarmMsg注解的地方切入
|
||||||
@@ -111,8 +120,10 @@ public class FarmMsgAspect {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
if (!farmMsgDTO.getNoSendMsg()){
|
if (!farmMsgDTO.getNoSendMsg()){
|
||||||
//发送信息
|
//企业微信内部发送信息
|
||||||
this.sendCpMsg(description.toString(), toUserStr);
|
//this.sendCpMsg(description.toString(), toUserStr);
|
||||||
|
//企业微信小程序通知消息
|
||||||
|
this.sendMiniMsg(user, farmMsgDTO, toUserStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +166,34 @@ public class FarmMsgAspect {
|
|||||||
log.info("企业微信消息发送结果:{}",result);
|
log.info("企业微信消息发送结果:{}",result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//发送小程序通知消息
|
||||||
|
public void sendMiniMsg(CpUserDO createUser, FarmMsgDTO farmMsgDTO, String toUserStr) throws WxErrorException {
|
||||||
|
// 发小程序
|
||||||
|
WxCpMessageService wxCpMessageService = wxCpService.getMessageService();
|
||||||
|
// 构造一个企业推送消息
|
||||||
|
WxCpMessage message = new WxCpMessage();
|
||||||
|
|
||||||
|
//接受者
|
||||||
|
message.setToUser(toUserStr);
|
||||||
|
//消息类型
|
||||||
|
message.setMsgType("miniprogram_notice");
|
||||||
|
|
||||||
|
message.setAppId(appid);
|
||||||
|
message.setTitle(farmMsgDTO.getType().getDesc() + farmMsgDTO.getOperation().getDesc() + "通知");
|
||||||
|
message.setDescription(LocalDateTimeUtil.formatNormal(LocalDateTime.now()));
|
||||||
|
|
||||||
|
Map<String, String> map2 = new HashMap<>();
|
||||||
|
map2.put("发起人", createUser.getName());
|
||||||
|
map2.put("内容", ObjectUtil.isEmpty(farmMsgDTO.getMsg()) ? farmMsgDTO.getTitle() : farmMsgDTO.getMsg());
|
||||||
|
message.setContentItems(map2);
|
||||||
|
|
||||||
|
|
||||||
|
log.info("企业微信小程序通知消息发送内容:{}", message);
|
||||||
|
WxCpMessageSendResult result = wxCpMessageService.send(message);
|
||||||
|
log.info("企业微信小程序通知消息发送结果:{}",result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description 获取需要接受信息的成员
|
* @Description 获取需要接受信息的成员
|
||||||
* @param id 可能是 projectId taskId 或 discussId
|
* @param id 可能是 projectId taskId 或 discussId
|
||||||
|
|||||||
Reference in New Issue
Block a user