alhaji-aki / laravel-textcus
Laravel 对 textcus 短信 API 的封装
1.0.4
2021-03-10 18:07 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^7.0.1
- illuminate/notifications: ~6.0 || ~7.0 || ~8.0
- illuminate/support: ~6.0 || ~7.0 || ~8.0
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ^5.0|^6.0
- phpunit/phpunit: ^9.1
README
此包可轻松使用 Laravel 6.x、7.x 和 8.x 通过 textcus 发送通知。
内容
安装
您可以通过 composer 安装此包
composer require alhaji-aki/laravel-textcus
设置 textcus 服务
将您的 Textcus 发送者 ID 和 API 密钥添加到您的 config/services.php
// config/services.php ... 'textcus' => [ 'api_key' => env('TEXTCUS_API_KEY'), 'sender_id' => env('TEXTCUS_SENDER_ID'), ], ...
使用
为了将 Textcus 通知路由到正确的电话号码,在您的可通知实体上定义一个 routeNotificationForTextcus
方法
class User extends Authenticatable { use Notifiable; /** * Route notifications for the Textcus channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForTextcus() { // NOTE: this is because you have to remove the + sign infront of the number in international formt return substr($this->mobile, 1); } }
您可以在通知中的 via()
方法内使用该通道
use Illuminate\Notifications\Notification; use AlhajiAki\Textcus\Messages\TextcusMessage; class AccountApproved extends Notification { public function via($notifiable) { return ['textcus']; } public function toTextcus($notifiable) { return (new TextcusMessage()) ->content("Your {$notifiable->service} account was approved!"); } }
测试
vendor/bin/phpunit
贡献
有关详细信息,请参阅 CONTRIBUTING
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件