junityco / laravel-nowsms
此包已废弃,不再维护。未建议替代包。
为 Laravel 提供的 NowSMS 服务提供商
1.1
2018-02-06 13:07 UTC
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ^6.2
- illuminate/notifications: 5.3.* || 5.4.* || 5.5.*
- illuminate/support: 5.3.* || 5.4.* || 5.5.*
- nesbot/carbon: ^1.18
This package is not auto-updated.
Last update: 2023-03-26 01:14:13 UTC
README
此包可以轻松使用 Laravel 发送 NowSMS 通知。
安装
使用 Composer 在项目的根目录中要求此包。
$ composer require junityco/laravel-nowsms
将服务提供商添加到 config/app.php 中的 providers 数组。
Junity\NowSms\NowSmsServiceProvider::class
如果您想使用 facade,可以将引用添加到 config/app.php 中的别名数组。
'NowSms' => Junity\NowSms\Facades\NowSms::class
您还需要安装 guzzlehttp/guzzle http 客户端来发送请求。
设置您的 NowSMS 账户
将您的 NowSMS URL、用户名和密码添加到 config/services.php
// config/services.php ... 'nowsms' => [ 'url' => 'http://127.0.0.1:8800', 'username' => '', 'password' => '', ], ...
使用
现在您可以在通知中的 via() 方法中使用此通道
use Junity\NowSms\Messages\SmsMessage; use Junity\NowSms\Channels\NowSmsChannel; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [NowSmsChannel::class]; } public function toNowSms($notifiable) { return (new SmsMessage) ->from("SenderID") ->content("Your account was approved!"); } }
为了使您的通知知道您正在发送/呼叫哪个电话,通道将查找 Notifiable 模型的 phone_number 属性。如果您想覆盖此行为,请将 routeNotificationForNowsms 方法添加到您的 Notifiable 模型。
public function routeNotificationForNowsms() { return '+1234567890'; }
使用代码示例
use Junity\NowSms\Facades\NowSms; NowSms::send([ 'Text' => 'Some text', 'Sender' => 'MyApp', ], '+1234567890');