|
|
7 месяцев назад | |
|---|---|---|
| .. | ||
| HookManager.php | 7 месяцев назад | |
| NotificationService.php | 7 месяцев назад | |
| README.md | 7 месяцев назад | |
本目录包含通知模块的所有服务类,负责处理通知的发送、模板管理等功能。
通知核心服务类,负责通知的发送、批量发送和重试等功能。
发送单个通知
参数说明:
$data = [
'template_id' => int, // 模板ID
'user_id' => int, // 用户ID
'data' => array, // 模板变量数据
'priority' => int, // 优先级(可选)
'channel' => string // 通知渠道(可选)
];
返回值:
[
'success' => bool, // 是否成功
'message' => string, // 提示信息
'notification_id' => int // 通知ID
]
批量发送通知
参数说明:
$data = [
[
'template_id' => int,
'user_id' => int,
'data' => array,
'priority' => int,
'channel' => string
],
// ... 更多通知
];
返回值:
[
'success' => bool,
'message' => string,
'total' => int, // 总数
'success_count' => int, // 成功数
'fail_count' => int // 失败数
]
重试失败的通知
参数说明:
返回值:
[
'success' => bool,
'message' => string
]
邮件服务类,负责邮件通知的发送。
发送邮件通知
参数说明:
$data = [
'to' => string, // 收件人邮箱
'subject' => string, // 邮件主题
'content' => string, // 邮件内容
'template' => string, // 邮件模板(可选)
'data' => array // 模板变量数据(可选)
];
返回值:
[
'success' => bool,
'message' => string
]
短信服务类,负责短信通知的发送。
发送短信通知
参数说明:
$data = [
'phone' => string, // 手机号
'content' => string, // 短信内容
'template_id' => string, // 短信模板ID(可选)
'data' => array // 模板变量数据(可选)
];
返回值:
[
'success' => bool,
'message' => string,
'request_id' => string // 短信请求ID
]
推送服务类,负责手机推送通知的发送。
发送推送通知
参数说明:
$data = [
'device_token' => string, // 设备令牌
'title' => string, // 推送标题
'content' => string, // 推送内容
'data' => array, // 额外数据(可选)
'sound' => string, // 提示音(可选)
'badge' => int // 角标数(可选)
];
返回值:
[
'success' => bool,
'message' => string,
'message_id' => string // 推送消息ID
]
$notificationService = new NotificationService();
$result = $notificationService->send([
'template_id' => 1,
'user_id' => 1,
'data' => [
'name' => '张三',
'amount' => 100
],
'priority' => NotificationPriority::HIGH
]);
$mailService = new MailService();
$result = $mailService->send([
'to' => 'example@example.com',
'subject' => '测试邮件',
'content' => '这是一封测试邮件',
'template' => 'emails.test',
'data' => [
'name' => '张三'
]
]);
$smsService = new SmsService();
$result = $smsService->send([
'phone' => '13800138000',
'content' => '您的验证码是:123456',
'template_id' => 'SMS_123456789',
'data' => [
'code' => '123456'
]
]);
$pushService = new PushService();
$result = $pushService->send([
'device_token' => 'device_token_123',
'title' => '测试推送',
'content' => '这是一条测试推送',
'data' => [
'type' => 'test'
],
'sound' => 'default',
'badge' => 1
]);