uzinfo/ntfy-laravel
Composer 安装命令:
composer require uzinfo/ntfy-laravel
包简介
Laravel broadcaster implementation for ntfy.sh notification service
README 文档
README
Laravel package for integrating with ntfy.sh notification service. This package provides a broadcaster implementation for Laravel Broadcasting and a notification channel for Laravel Notifications.
Features
- Laravel Broadcasting driver for ntfy
- Laravel Notification channel for ntfy
- Support for all ntfy features (priority, tags, attachments, actions, etc.)
- Multiple authentication methods (Bearer, Basic, Digest, API Key)
- Configurable SSL verification
- Rate limiting support
- Helper methods for common use cases
Installation
Install the package via Composer:
composer require uzinfo/ntfy-laravel
The service provider will be automatically registered.
Configuration
Environment Variables
Add the following variables to your .env file:
# Basic ntfy configuration NTFY_BASE_URL=https://ntfy.sh NTFY_TOKEN=your-token-here NTFY_KEY=your-key-here NTFY_AUTH=bearer NTFY_VERIFY=true # For broadcasting BROADCAST_DRIVER=ntfy
Publishing Configuration
Publish the configuration files:
# Publish ntfy configuration php artisan vendor:publish --tag=ntfy-config # Publish broadcasting configuration (optional) php artisan vendor:publish --tag=ntfy-broadcasting
Usage
Broadcasting Events
Create a broadcastable event:
<?php namespace App\Events; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class NotificationEvent implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; public function __construct( public string $message, public int $userId, public ?string $title = null ) {} public function broadcastOn() { return new Channel('user.' . $this->userId); } public function broadcastWith() { return [ 'message' => $this->message, 'title' => $this->title, 'priority' => 4, 'tags' => ['notification', 'alert'], ]; } }
Dispatch the event:
event(new NotificationEvent('Hello World!', 123, 'Important Message'));
Direct Ntfy Usage
Use the Ntfy class directly:
use UzInfo\NtfyLaravel\Ntfy; $ntfy = new Ntfy(); // Simple notification $ntfy->send('my-topic', 'Hello World!'); // With options $ntfy->send('my-topic', 'Hello World!', [ 'title' => 'Important', 'priority' => 5, 'tags' => ['warning', 'urgent'], 'click' => 'https://example.com', 'icon' => 'https://example.com/icon.png' ]); // Helper methods $ntfy->urgent('my-topic', 'Critical alert!'); $ntfy->low('my-topic', 'Minor update'); $ntfy->markdown('my-topic', '**Bold** and *italic* text'); $ntfy->attach('my-topic', 'Check this file', 'https://example.com/file.pdf');
Laravel Notifications
Create a notification:
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use UzInfo\NtfyLaravel\NtfyChannel; use UzInfo\NtfyLaravel\NtfyMessage; class OrderShipped extends Notification { public function via($notifiable) { return [NtfyChannel::class]; } public function toNtfy($notifiable) { return NtfyMessage::create('Your order has been shipped!') ->title('Order Update') ->priority(4) ->tags(['package', 'shipped']) ->click('https://example.com/track/123') ->icon('📦'); } }
Add to your notifiable model:
class User extends Model { public function routeNotificationForNtfy() { return 'user-' . $this->id; } }
Send the notification:
$user->notify(new OrderShipped());
Authentication Methods
The package supports multiple authentication methods:
Bearer Token
NTFY_AUTH=bearer NTFY_TOKEN=your-bearer-token
Basic Authentication
NTFY_AUTH=basic NTFY_KEY=username NTFY_TOKEN=password
Digest Authentication
NTFY_AUTH=digest NTFY_KEY=username NTFY_TOKEN=password
API Key
NTFY_AUTH=key NTFY_KEY=your-api-key
No Authentication
NTFY_AUTH=null
Configuration Options
Priority Levels
- 1: Min priority
- 2: Low priority
- 3: Default priority (default)
- 4: High priority
- 5: Max/Urgent priority
Common Tags
You can use emoji shortcodes or custom strings:
warning,alert,firepoint_right,tada,package- Custom strings like
urgent,system
Actions
$actions = [ [ 'action' => 'view', 'label' => 'Open App', 'url' => 'https://example.com' ], [ 'action' => 'http', 'label' => 'Update Status', 'url' => 'https://api.example.com/update', 'method' => 'POST' ] ]; $ntfy->actions('my-topic', 'Message with actions', $actions);
Rate Limiting
The package includes built-in rate limiting configuration:
// config/ntfy.php 'rate_limit' => [ 'enabled' => true, 'max_requests' => 60, 'per_minutes' => 1, ],
Testing
The package includes comprehensive tests. Run them with:
composer test
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This package is open-sourced software licensed under the MIT license.
Credits
Support
If you discover any security vulnerabilities, please email security@example.com instead of using the issue tracker.
For bugs and feature requests, please use the GitHub issues.
uzinfo/ntfy-laravel 适用场景与选型建议
uzinfo/ntfy-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「laravel」 「push」 「Broadcasting」 「Ntfy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 uzinfo/ntfy-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 uzinfo/ntfy-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 uzinfo/ntfy-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Apple Push Notification & Feedback Provider
Laravel package to send push notifications to mobile devices (apns, gcm)
Captures outgoing SMS notifications
Send push notification to android|ios devices , support APNs, FCM
Alfabank REST API integration
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-07