romanstruk / smsnotify
发送短信
v0.0.3-alpha
2021-12-26 16:44 UTC
Requires
- php: ^7.3|^8.0
- ext-json: *
- giggsey/libphonenumber-for-php: ^8.12
- guzzlehttp/guzzle: ^7.0.1
Requires (Dev)
- orchestra/testbench: 6.x
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2024-09-27 01:46:13 UTC
README
Laravel 的库,实现通过一个 API 使用不同客户端发送短信消息。支持以下第三方服务:
- Viber UA
- MTS Communicator BY
- TurboSMS UA
安装
推荐通过 Composer 安装 SmsNotify。
composer require romanstruk/smsnotify
兼容性
目前仅在 Laravel 8.x 上进行了测试
配置
php artisan vendor:publish RomanStruk\SmsNotify\SmsNotifyServiceProvider
之后,请使用您的配置更新 config/smsnotify.php
。
使用方法
要使用 SmsNotify 库,您可以使用门面或从服务容器获取实例
SmsNotifyFacade::to(new PhoneNumber('0666000000', 'UA')) ->send(new SmsMessage('Some sms text'));
或者
$smsNotify = app(SmsNotifyInterface::class); $smsNotify->to(new PhoneNumber('0666000000', 'UA')) ->send(new SmsMessage('Some sms text'));
如果需要在执行时动态更改短信发送服务,可以使用 Closure
方法 clientMap(Closure $func)
,结果将是一个与配置文件中关联的客户端的键
SmsNotifyFacade::clientMap(function (){ return 'ua'; }) ->to(new PhoneNumber('0666000000', 'UA')) ->send(new SmsMessage('Some text'));
配置文件 config/smsnotify.php
... 'map' => [ 'ua' => 'log', 'by' => 'mts-communicator' ] ...