princeton255 / laravel-notifications-infobip
此包已被弃用,不再维护。未建议替代包。
Infobip SMS API的自定义Laravel通知通道
1.2.0
2020-04-07 16:16 UTC
Requires
- php: >=7.1
- infobip/infobip-api-php-client: ^2.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- illuminate/events: ^7.0@dev
- illuminate/notifications: ^7.0@dev
- illuminate/queue: ^7.0@dev
- illuminate/support: ^7.0@dev
- phpunit/phpunit: ^8.5@dev
This package is auto-updated.
Last update: 2022-10-11 12:45:41 UTC
README
此包简化了使用Infobip服务发送短信通知的过程,适用于Laravel 5.5及以上版本。
内容
安装
您可以通过Composer安装此包
composer require princeton255/laravel-notifications-infobip
设置您的Infobip账户
将您的Infobip账户用户名、密码和发送号码添加到config/services.php
// config/services.php ... 'infobip' => [ 'username' => env('INFOBIP_USERNAME'), 'password' => env('INFOBIP_PASSWORD'), 'from' => env('INFOBIP_FROM', 'IBTEST'), ], ...
要更改基础URL
以供个人使用,请参阅此链接(更多信息)
... 'infobip' => [ ... 'baseUrl' => env('INFOBIP_BASE_URL', null), ], ...
使用方法
现在您可以在通知中的via()
方法中使用此通道
use NotificationChannels\Infobip\InfobipChannel; use NotificationChannels\Infobip\InfobipMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [InfobipChannel::class]; } public function toInfobip($notifiable) { return (new InfobipMessage()) ->content("Your {$notifiable->service} account was approved!"); } }
为了使通知知道您要发送到哪个电话,通道将查找可通知模型中的phone_number
属性。如果您想覆盖此行为,请将routeNotificationForInfobip
方法添加到您的可通知模型中。
public function routeNotificationForInfobip() { return '+1234567890'; }
可用的消息方法
InfobipMessage
from('')
: 接受一个电话作为通知发送者。content('')
: 接受一个字符串值作为通知正文。
示例
派发通知
A. 使用Laravel的通知外观
use App\Notifications\ExampleInfobipNotification; use Illuminate\Support\Facades\Notification; Notification::send($user, new ExampleInfobipNotification()); // where $user implements `Illuminate\Notifications\Notifiable` trait
B. 使用Notifiable
特性中的notify()
方法
use App\Notifications\ExampleInfobipNotification; $user->notify(new ExampleInfobipNotification($invoice));
示例通知类
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use NotificationChannels\Infobip\InfobipChannel; use NotificationChannels\Infobip\InfobipMessage; class ExampleInfobipNotification extends Notification { public function via($notifiable) { return [InfobipChannel::class]; } public function toInfobip($notifiable) { return (new InfobipMessage()) // Customize your msg content here ->content("Your {$notifiable->service} account was approved!"); } }
示例可通知类
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; }
更多详细信息,请参阅Laravel文档中的此链接
测试
$ ./vendor/bin/phpunit
安全
如果您发现任何安全相关的问题,请通过电子邮件princeton.mosha@gmail.com联系,而不是使用问题跟踪器。
致谢
- 基于 Twilio SMS 通知通道 的 Laravel
- 此项目使用 Infobip 客户端库,并在 Laravel 中进行封装以实现平滑使用
许可证
MIT 许可证 (MIT)。