推送消息
产品服务,推送一个消息,前端给出提示
推送实例代码
public class BadgeRpcServiceImpl {
@Autowired
private SocketPushMessageRpcService socketPushMessageRpcService;
/**
* 发送一个系统消息
*/
public void pushSystemMessage() {
//业务type
String busType = "badge";
//消息内容(前端根据业务type去解析消息内容做相应的业务处理)
String content = "";
PushSystemMessage pushSystemMessage = new PushSystemMessage(busType, content);
//收件人
String toUserId = "";
//发送人
String sourceUserId = "";
pushSystemMessage.setTargetUserIds(Lists.newArrayList(toUserId));
pushSystemMessage.setSourceUserId(sourceUserId);
socketPushMessageRpcService.sendMessage(pushSystemMessage);
}
/**
* 发送脚本消息
*/
public void pushScriptMessage() {
//业务type
String busType = "badge";
//js脚本(具体格式,需要去看前端代码)
String content = "";
PushScriptMessage pushScriptMessage = new PushScriptMessage(busType, content);
//收件人
String toUserId = "";
//发送人
String sourceUserId = "";
pushScriptMessage.setTargetUserIds(Lists.newArrayList(toUserId));
pushScriptMessage.setSourceUserId(sourceUserId);
socketPushMessageRpcService.sendMessage(pushScriptMessage);
}
/**
* 发送通知消息(右下角弹出,不带按钮)
*/
public void pushNoticeMessage() {
//业务type
String busType = "badge";
//这里以流程提交弹出消息为示例
Notice notice = new Notice();
notice.setTitle("流程提醒");
String content = String.format("由【管理员】在【xxx】给您提交了【xxx】任务, 执行操作:【xxx】,执行意见:【xxx】");
notice.setContent(content);
notice.setPlayAudio(true);
PushNoticeMessage pushScriptMessage = new PushNoticeMessage(busType, notice);
//收件人
String toUserId = "";
//发送人
String sourceUserId = "";
pushScriptMessage.setTargetUserIds(Lists.newArrayList(toUserId));
pushScriptMessage.setSourceUserId(sourceUserId);
socketPushMessageRpcService.sendMessage(pushScriptMessage);
}
/**
* 发送通知消息(右下角弹出,带按钮,点击打开功能表单)
*/
public void pushNoticeMessage2() {
//业务主键
String beanId = "";
//功能code
String funcCode = "";
//业务type
String busType = "badge";
//这里以流程提交弹出消息为示例
Notice notice = new Notice();
notice.setTitle("流程提醒");
String content = String.format("由【管理员】在【xxx】给您提交了【xxx】任务, 执行操作:【xxx】,执行意见:【xxx】");
notice.setContent(content);
notice.setPlayAudio(true);
//收件人
String toUserId = "";
socketPushMessageRpcService.sendNoticeOpenFuncFormMsgToUser(toUserId, funcCode,
busType, notice, beanId);
}
}
右上角铃铛和消息列表,参考message项目实现
备注:目前message项目没有提供rpc方法,需要自己实现rpc方法持久化
最后编辑: 呼丽华 文档更新时间: 2024-11-08 17:00 作者:于春辉