luisdalmolin / laravel-zenvia-channel
使用 Zenvia 发送短信
1.1.0
2020-12-12 10:59 UTC
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ^6.2|^7.0
Requires (Dev)
- illuminate/notifications: ^5.3
- illuminate/support: ^5.1|^5.2|^5.3|^5.4|^5.5|^5.6|^5.7|^5.8|^6.0|^7.0
- mockery/mockery: ^0.9.5
- phpunit/phpunit: 4.*
README
此包简化了使用 Laravel 5 通过 Zenvia API 发送短信的过程。
内容
安装
您可以通过 composer 安装此包。
composer require luisdalmolin/laravel-zenvia-channel
您必须安装服务提供者。
// config/app.php 'providers' => [ ... NotificationChannels\Zenvia\ZenviaServiceProvider::class, ],
配置
配置您的凭证。
// config/services.php ... 'zenvia' => [ 'from' => env('ZENVIA_FROM', 'Laravel Notification Channels'), 'pretend' => env('ZENVIA_PRETEND', false), 'conta' => env('ZENVIA_CONTA', 'YOUR ACCOUNT'), 'senha' => env('ZENVIA_SENHA', 'YOUR PASSWORD') ], ...
使用
现在您可以在 Notification 类的 via()
方法中使用该通道。
use NotificationChannels\Zenvia\ZenviaChannel; use NotificationChannels\Zenvia\ZenviaMessage; use Illuminate\Notifications\Notification; class InvoicePaid extends Notification { public function via($notifiable) { return [ZenviaChannel::class]; } public function toZenvia($notifiable) { return ZenviaMessage::create() ->from('Laravel') // optional ->to($notifiable->phone) // your user phone ->content('Your invoice has been paid') ->id('your-sms-id'); } }
消息路由
您可以通过提供接收者的聊天 ID 来发送通知,如下例所示,或者在你的可通知模型中添加 routeNotificationForZenvia()
方法。
... /** * Route notifications for the Telegram channel. * * @return int */ public function routeNotificationForZenvia() { return $this->phone; } ...
可用消息方法
to($phone)
: (integer) 接收者电话。content('message')
: (string) 短信内容。from('Sender')
: (string) 发送者名称。id('sms-id')
: (string) 短信 ID。
更新日志
有关最近更改的更多信息,请参阅 更新日志。
测试
$ composer test
安全性
如果您发现任何安全问题,请通过电子邮件 luis.nh@gmail.com 而不是使用问题跟踪器来报告。
贡献
有关详细信息,请参阅 贡献。
感谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。