This commit is contained in:
张良(004796)
2024-01-26 18:41:28 +08:00
parent 36eee916b1
commit 97ba46f6e4
16 changed files with 187 additions and 59 deletions

View File

@@ -2,7 +2,6 @@ package com.ruoyi.yunxin;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.yunxin.client.ImMessageClient;
import com.ruoyi.yunxin.config.YunxinExecutorConstant;
import com.ruoyi.yunxin.config.YunxinProperties;
import com.ruoyi.yunxin.req.Option;
import com.ruoyi.yunxin.req.SendAttachMsgReq;
@@ -22,21 +21,22 @@ import java.util.stream.Collectors;
@Component
public class Yunxin {
private final static String SYS_NOTICE_ID = "2";
@Autowired
private YunxinProperties yunxinProperties;
@Resource
private ImMessageClient messageClient;
/**
*
* 发送系统消息
* @param toUid 接收者ID
* @param fromUid 发送者ID
* @param data 数据
* @return
*/
public YxDataR<SendMsgResp> sendTo(Long toUid,Long fromUid,Object data){
public YxDataR<SendMsgResp> sendToNotice(Long toUid, Object data){
SendMsgReq req = new SendMsgReq();
req.setFrom(fromUid == null ? yunxinProperties.getDefaultFromUid() : fromUid+"");
req.setFrom(SYS_NOTICE_ID);
req.setTo(toUid+"");
req.setBody(JSON.toJSONString(data));
req.setOption(JSON.toJSONString(new Option()));
@@ -44,6 +44,34 @@ public class Yunxin {
return messageClient.sendMsg(req);
}
/**
* 批量发送 系统消息
* @param toUid
* @return
*/
public YxDataR<YxCommonR> batchSendToNotice(List<Long> toUid, Object data){
SendBatchMsgReq req = new SendBatchMsgReq();
req.setFromAccid(SYS_NOTICE_ID);
req.setToAccids(toUid.stream().map(i -> String.valueOf(toUid)).collect(Collectors.toList()));
req.setBody(JSON.toJSONString(data));
req.setOption(JSON.toJSONString(new Option()));
req.setType(100);
return messageClient.sendBatchMsg(req);
}
/**
* 指定用户的自定义消息
*/
public YxDataR<SendMsgResp> sendToUserNotice(Long toUid, Long fromUid, Object data){
SendMsgReq req = new SendMsgReq();
req.setFrom(fromUid+"");
req.setTo(toUid+"");
req.setBody(JSON.toJSONString(data));
req.setOption(JSON.toJSONString(new Option()));
return messageClient.sendMsg(req);
}
public YxDataR<YxCommonR> batchSendToTextMessage(Long fromUid, List<Long> toUid, String data){
SendBatchMsgReq req = new SendBatchMsgReq();