robustack/sms
Composer 安装命令:
composer require robustack/sms
包简介
Laravel-ready SMS manager and routing package with pluggable senders.
README 文档
README
Laravel-ready SMS routing with prioritized senders and simple configuration. Register any number of sender classes, route by country or dialing prefix, and the package picks the best available sender with automatic fallback.
Features
- Pluggable senders via a tiny contract
- Priority-aware routing
- by_country (ISO alpha-2, requires
giggsey/libphonenumber-for-php) - by_prefix (digits only, longest match wins)
- default sender, then implicit 'log' fallback
- by_country (ISO alpha-2, requires
- Central manager for registration and dispatch
- Factory to choose and send via the best sender
- Laravel service provider, facade, publishable config
- Auto-merge per-sender config into
$configpassed to send()
Installation
composer require robustack/sms
php artisan vendor:publish --provider="Robustack\\Sms\\Providers\\SmsServiceProvider" --tag=config
Optional for better region detection (enables by_country):
composer require giggsey/libphonenumber-for-php
Configure
config/sms.php
return [ 'default_sender' => 'log', 'senders' => [ 'log' => [ 'class' => \Robustack\Sms\Senders\LogSender::class, 'config' => [], ], // 'twilio' => [ // 'class' => \App\Sms\TwilioSender::class, // 'config' => ['from' => env('TWILIO_FROM')], // ], ], 'routing' => [ 'default' => 'log', 'by_country' => [ 'US' => ['twilio', 'log'], ], 'by_prefix' => [ '1' => ['twilio', 'log'], '20' => ['vonage', 'log'], ], ], ];
Notes
- Each sender's
configis automatically merged into the$configargument passed at runtime; runtime values override file config. - The container resolves sender dependencies; type-hint what you need in the constructor.
Usage
// Choose and send via the best sender app(\Robustack\Sms\SmsFactory::class)->send('+14155550100', 'Hello', ['from' => '+11234567890']); // Facade \Robustack\Sms\Facades\Sms::send('+201234567890', 'مرحبا'); // Inspect routing decision $name = \Robustack\Sms\Facades\Sms::chooseSenderName('+201234567890');
Implement a sender
Implement Robustack\Sms\Contracts\SmsSenderContract:
namespace App\Sms; use Robustack\Sms\Contracts\SmsSenderContract; class TwilioSender implements SmsSenderContract { public function __construct(private \Twilio\Rest\Client $client) {} public function send(string $to, string $message, array $config = []): bool { $from = $config['from'] ?? env('TWILIO_FROM'); $this->client->messages->create($to, ['from' => $from, 'body' => $message]); return true; } }
Register in config only (no manual registration needed):
'senders' => [ 'twilio' => [ 'class' => \App\Sms\TwilioSender::class, 'config' => [ 'from' => env('TWILIO_FROM'), ], ], ],
The package resolves Twilio\Rest\Client from the container and merges senders.twilio.config into $config when calling send().
Priority and fallback
Order of selection:
by_countrymatch (if libphonenumber installed)by_prefixmatch (longest match first)routing.default- Implicit
'log'sender if registered
If a sender throws or returns false, the next candidate is tried automatically.
Advanced
- Dynamic registration
app(\Robustack\Sms\SmsManager::class)->register('custom', new CustomSender(...));
- Per-request overrides
\Robustack\Sms\Facades\Sms::send('+14155550100', 'Hello', ['from' => '+10987654321']);
Testing
composer install
composer test
CI
GitHub Actions workflow in .github/workflows/ci.yml runs tests on PHP 8.0–8.2.
Suggested provider SDKs
composer require twilio/sdk composer require vonage/client-core vonage/client
robustack/sms 适用场景与选型建议
robustack/sms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 robustack/sms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robustack/sms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-19