dmitrakovich / smstraffic-for-laravel
Laravel的SmsTraffic客户端
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.5
- illuminate/notifications: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
README
详细信息
受Laravel Vonage Notification Channel启发。
注意
此库实现的功能有限。
文档
在Laravel中发送短信通知由SMS Traffic提供支持。在您可以通过SMS Traffic发送通知之前,您需要安装dmitrakovich/smstraffic-for-laravel
和guzzlehttp/guzzle
包。
composer require dmitrakovich/smstraffic-for-laravel guzzlehttp/guzzle
该包包含一个配置文件。然而,您不需要将此配置文件导出到自己的应用程序中。您可以直接使用环境变量。
SMSTRAFFIC_SMS_FROM= SMSTRAFFIC_LOGIN= SMSTRAFFIC_PASSWORD= SMSTRAFFIC_ROUTE=
短信通知格式化
如果通知支持作为短信发送,您应该在通知类上定义一个toSmsTraffic
方法。此方法将接收一个$notifiable
实体,并应返回一个Illuminate\Notifications\Messages\SmsTrafficMessage
实例。
/** * Get the SmsTraffic / SMS representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\SmsTrafficMessage */ public function toSmsTraffic($notifiable) { return (new SmsTrafficMessage) ->content('Your SMS message content'); }
通知路由
如果您想将一些通知发送到与您的SMSTRAFFIC_ROUTE
环境变量指定的路由不同的路由,您可以在SmsTrafficMessage
实例上调用route
方法。
/** * Get the SmsTraffic / SMS representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\SmsTrafficMessage */ public function toSmsTraffic($notifiable) { return (new SmsTrafficMessage) ->content('Your unicode message') ->route('whatsapp(180)-sms'); }
自定义“来自”号码
如果您想从与您的SMSTRAFFIC_SMS_FROM
环境变量指定的号码不同的号码发送一些通知,您可以在SmsTrafficMessage
实例上调用from
方法。
/** * Get the SmsTraffic / SMS representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\SmsTrafficMessage */ public function toSmsTraffic($notifiable) { return (new SmsTrafficMessage) ->content('Your SMS message content') ->from('15554443333'); }
路由短信通知
要将SmsTraffic通知路由到正确的电话号码,请在您的notifiable实体上定义一个routeNotificationForSmsTraffic
方法。
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; /** * Route notifications for the SmsTraffic channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForSmsTraffic($notification) { return $this->phone_number; } }
使用SmsTraffic外观
或者,您也可以通过\Illuminate\Notifications\Facades\SmsTraffic
外观发送通知。
SmsTraffic::send($phones, $message);
官方文档
有关Laravel Vonage通知通道的文档可以在Laravel网站上找到。
贡献
感谢您考虑为SmsTraffic for Laravel做出贡献!
行为准则
为了确保Laravel社区对所有成员都友好,请查阅并遵守行为准则。
许可
Laravel Vonage通知通道是开源软件,许可协议为MIT许可。