消息通知
本文档介绍如何使用消息通知功能。
功能介绍
支持多种消息通知方式:
- 📧 邮件通知
- 📱 短信通知
- 🔔 站内信通知
- 📲 推送通知
邮件通知
配置
yaml
spring:
mail:
host: smtp.qq.com
port: 587
username: your-email@qq.com
password: your-password
properties:
mail:
smtp:
auth: true
starttls:
enable: true使用
java
@Autowired
private MailService mailService;
public void sendEmail() {
mailService.sendSimpleMail(
"recipient@example.com",
"邮件主题",
"邮件内容"
);
}短信通知
配置
yaml
sms:
provider: aliyun
access-key-id: your-access-key-id
access-key-secret: your-access-key-secret
sign-name: 您的签名
template-code: SMS_123456789使用
java
@Autowired
private SmsService smsService;
public void sendSms() {
smsService.sendSms(
"13800138000",
"SMS_123456789",
Map.of("code", "123456")
);
}站内信通知
使用
java
@Autowired
private NotificationService notificationService;
public void sendNotification() {
notificationService.send(
userId,
"通知标题",
"通知内容"
);
}WebSocket 推送
使用
java
@Autowired
private WebSocketServer webSocketServer;
public void pushMessage() {
WebSocketServer.sendToUser(
userId,
"推送消息内容"
);
}批量通知
java
public void batchNotify() {
List<String> userIds = Arrays.asList("1", "2", "3");
notificationService.batchSend(
userIds,
"通知标题",
"通知内容"
);
}