laravel-notification-channels / africastalking
此包使您能够通过AfricasTalking轻松使用Laravel发送通知
Requires
- php: >=7.2.5
- africastalking/africastalking: ^3.0
- guzzlehttp/guzzle: ^6.2 || ^7.0
- illuminate/notifications: 5.5 - 11.0
- illuminate/support: 5.5 - 11.0
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ~5.0 || ^6.0 || ^7.0 || ^8.0
- phpunit/phpunit: ^7.5 || ^8.5.21 || ^9.0
This package is auto-updated.
Last update: 2024-09-13 14:21:34 UTC
README
此包使您能够使用AfricasTalking通过Laravel轻松发送通知。
内容
关于
此包是Laravel Notification Channels项目的一部分。它为Laravel本身提供的通知通道提供了额外的Laravel通知通道。
AfricasTalking通道使您能够通过AfricasTalking API将Laravel通知作为SMS
发送出去。
安装
您可以通过composer安装此包
composer require laravel-notification-channels/africastalking
服务提供者会自动加载。
设置AfricasTalking服务
您需要注册,然后转到您的沙箱应用 转到沙箱应用。 点击设置 在此页面,您将生成您的用户名和密钥
。将它们放置在您的.env
文件中。请记住添加您将用于发送消息的发送者ID。
请注意,如果您没有有效的发送者ID,请从您的.env中删除"AT_FROM",或者将其留为""
AT_USERNAME="" AT_KEY="" AT_FROM="" // please note if you do not have a valid sender_ID remove this or leave it as ""
要加载它们,请将此添加到您的config/services.php
。这将从.env
文件中加载AfricasTalking数据。
'africastalking' => [ 'username' => env('AT_USERNAME'), 'key' => env('AT_KEY'), 'from' => env('AT_FROM'), ]
在您的可通知模型上添加routeNotifcationForAfricasTalking
方法。如果未添加此方法,则将自动使用phone_number
字段。
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * Route notifications for the Africas Talking channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForAfricasTalking($notification) { return $this->phone_number; } }
使用
要使用此包,您需要在您的Laravel应用程序中创建一个通知类,例如下面的NewsWasPublished
,请确保查看Laravel文档了解此过程。
<?php use NotificationChannels\AfricasTalking\AfricasTalkingChannel; use NotificationChannels\AfricasTalking\AfricasTalkingMessage; class NewsWasPublished extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [AfricasTalkingChannel::class]; } public function toAfricasTalking($notifiable) { return (new AfricasTalkingMessage()) ->content('Your SMS message content'); } }
您还可以修改通知(SMS)的发送者,这将覆盖您的.env中的AT_FROM= 请仅在您有有效的发送者ID的情况下这样做
return (new AfricasTalkingMessage()) ->content("Your SMS message content") ->from("set any sender id/name here");
您还可以修改通知(SMS)的接收者(收件人)
return (new AfricasTalkingMessage()) ->content("Your SMS message content") ->to("put the recipient phone number here"); //eg ->to(1111111111)
了解接收者电话号码的顺序很重要,该顺序将用于发送通知(SMS)
-
如果您在可通知类(例如User.php)上定义了routeNotificationForAfricasTalking()方法并返回了有效的电话号码,则将使用该号码。
-
如果您未在可通知类(例如User.php)上定义routeNotificationForAfricasTalking()方法,则将使用用户的phone_number属性($user->phone_number)。
-
最后,如果使用->to(1111111)设置了接收者电话号码,则将覆盖1或2中提供的电话号码。
return (new AfricasTalkingMessage()) ->content("Your SMS message content") ->to("put the recipient phone number here"); //eg ->to(11111111)
测试
$ composer test
安全
如果您发现任何安全问题,请通过osaigbovoemmanuel1@gmail.com而不是使用问题跟踪器发送电子邮件。
贡献
请参阅CONTRIBUTING获取详细信息。
鸣谢
许可证
MIT许可(MIT)。请参阅许可文件获取更多信息。
我该如何表达感谢呢?
请买我一杯咖啡https://www.paypal.com/paypalme/osaigbovoemmanuel,留下星标并关注我的Twitter。