flickerleap / clickatell
Clickatell 的 Laravel 通知集成
1.0.5
2023-04-13 07:49 UTC
Requires
- arcturial/clickatell: ^3.0
This package is not auto-updated.
Last update: 2024-09-29 04:37:15 UTC
README
此包实现了 Clickatell 作为 Laravel 通知通道。
我们从 laravel-notification-channels/clickatell 中汲取了大量灵感。
内容
安装
composer require flickerleap/clickatell
.env
CLICKATELL_TOKEN=
发布
php artisan vendor:publish --provider="FlickerLeap\Clickatell\ClickatellServiceProvider"
配置
默认为
CLICKATELL_FIELD=
CLICKATELL_FIELD- 如果在可通知类上未实现routeNotificationForClickatell()方法,则用于to的默认字段。
跟踪
可选跟踪记录 Clickatell 的发送状态。启用后需要运行一次 php artisan migrate。
CLICKATELL_TRACK= CLICKATELL_TRACKING_TABLE=
CLICKATELL_TRACK- 跟踪为真或假。CLICKATELL_TRACKING_TABLE- 可选跟踪的表名。
回调
可选,启用投递通知后,在此处设置凭据和 URL。需要启用跟踪。值为 /clickatellCallback 将在 https://mysite.com/clickatellCallback 访问。
CLICKATELL_CALLBACK_URL= CLICKATELL_USERNAME= CLICKATELL_PASSWORD=
CLICKATELL_CALLBACK_URL- 消息投递更新回调 URL。CLICKATELL_USERNAME- 回调凭据。CLICKATELL_PASSWORD- 回调凭据。
使用
可通知
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; class User extends Model { use Notifiable; /** * Route notifications for the clickatell channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForClickatell($notification) { return $this->mobile; }
通知
<?php namespace App\Notifications; use FlickerLeap\Clickatell\ClickatellChannel; use FlickerLeap\Clickatell\ClickatellMessage; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; class SMSUser extends Notification implements ShouldQueue { use Queueable; /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [ClickatellChannel::class]; } /** * @param $notifiable * @return \FlickerLeap\Clickatell\ClickatellMessage */ public function toClickatell($notifiable) { $content = 'My message.'; return (new ClickatellMessage())->content($content); } }
到
可选,to 字段可以通过指定 ->to() 在每次调用中动态更改。
/** * @param $notifiable * @return \FlickerLeap\Clickatell\ClickatellMessage */ public function toClickatell($notifiable) { $content = 'My message.'; return (new ClickatellMessage())->to($notifiable->beneficiary_number) ->content($content); }
呼叫
$user->notify(new SMSUser());
测试
如果 APP_ENV 设置为本地,则将创建 Laravel 日志条目。
测试
待办事项