123
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -43,7 +43,7 @@ public class YunxinWsService {
|
||||
public void sendToCallNotifyAsync(Long toUid, Long fromUid, CallNoticeEnum status, Long calltime){
|
||||
YunExecutor.YUN_EXECUTOR.execute(() -> {
|
||||
ImDataRes imDataRes = ImMsgGen.callNotice(status, fromUid, toUid, calltime);
|
||||
YxDataR<SendMsgResp> r = yunxin.sendTo(toUid, fromUid, imDataRes);
|
||||
YxDataR<SendMsgResp> r = yunxin.sendToNotice(toUid, fromUid, imDataRes);
|
||||
if(r == null || !r.isSuccess()){
|
||||
log.error("云信发送失败【sendCallAsync】r={}", JSON.toJSONString(r));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user