zing / laravel-sms
为Laravel提供短信通知通道。
6.4.0
2024-03-18 14:54 UTC
Requires
- php: ^8.0
- ext-json: *
- graham-campbell/manager: ^4.3 || ^5.0
- illuminate/console: ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/notifications: ^8.0 || ^9.0 || ^10.0 || ^11.0
- overtrue/easy-sms: ^2.4.2
Requires (Dev)
- composer/class-map-generator: ^1.0
- mockery/mockery: ~1.3.3 || ^1.4.2
- nunomaduro/larastan: ^1.0 || ^2.0
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpstan/phpstan-mockery: ^1.0
- phpunit/phpunit: ^9.3.3 || ^10.0
- zing/coding-standard: ^6.4 || ^7.0
- 6.x-dev
- dev-master / 6.x-dev
- 6.4.0
- 6.3.1
- 6.3.0
- 6.2.0
- 6.1.0
- 6.0.0
- 5.x-dev
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.x-dev
- 4.3.1
- 4.3.0
- 4.2.1
- 4.2.0
- 4.1.0
- 4.0.0
- 3.x-dev
- 3.6.1
- 3.6.0
- 3.5.8
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 3.0.0-alpha.5
- 3.0.0-alpha.4
- 3.0.0-alpha.3
- 3.0.0-alpha.2
- 3.0.0-alpha.1
- 2.x-dev
- 2.3.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-alpha.2
- 2.0.0-alpha.1
- 1.x-dev
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-deepsource-config-dcd3b523
- dev-fix-cs
- dev-pest
This package is auto-updated.
Last update: 2024-09-22 08:43:39 UTC
README
Laravel Sms用于通过短信进行通知和发送消息。
感谢
非常感谢
-
JetBrains提供的优秀PhpStorm IDE,并为我提供开源许可证,以加速项目开发。
要求
安装
Composer
执行以下命令以获取软件包的最新版本
composer require zing/laravel-sms
Laravel
发布配置
php artisan vendor:publish --provider "Zing\LaravelSms\SmsServiceProvider"
添加连接
此包基于overtrue/easy-sms,驱动程序是网关。
用法
通道
创建通知
use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; class Verification extends Notification implements ShouldQueue { use Queueable; protected $code; /** * Verification constructor. * * @param $code */ public function __construct($code) { $this->code = $code; } public function via() { return ['sms']; } public function toSms($notifiable) { return "验证码 {$this->code},您正在进行身份验证,打死也不要告诉别人哦!"; } }
为短信添加通知路由到你的可通知对象
use Illuminate\Notifications\Notifiable; class User { use Notifiable; public function routeNotificationForSms($notification) { return $this->phone; } }
发送通知
use Illuminate\Support\Facades\Notification; $user = new User(); // use Notifiable Trait $user->notify(new Verification('1111')); // use Notification Facade Notification::send($user, new Verification('1111'));
发送到匿名可通知对象
use Illuminate\Support\Facades\Notification; use Zing\LaravelSms\SmsNumber; use Zing\LaravelSms\Channels\SmsChannel; // use channel class name Notification::route(SmsChannel::class, new SmsNumber(18188888888, 86))->notify(new Verification('1111')); // use channel alias Notification::route('sms', new SmsNumber(18188888888, 86))->notify(new Verification('1111'));
外观
发送消息
use Zing\LaravelSms\Facades\Sms; // use default connection Sms::send(18188888888, 'test message.'); // use specific connection Sms::connection('null')->send(18188888888, 'test message.'); // or Sms::via('null')->send(18188888888, 'test message.');
具体用法
为通知使用特定连接
注意:仅支持Zing\LaravelSms\SmsMessage
use Zing\LaravelSms\SmsMessage; public function toSms($notifiable) { return (new SmsMessage())->onConnection('log'); }
使电话号码成为可通知对象
注意:仅支持Zing\LaravelSms\SmsNumber
use Zing\LaravelSms\SmsNumber; (new SmsNumber(18188888888))->notify(new Verification('1111'));
许可证
Laravel Sms是开源软件,受MIT许可证许可。