laravel-notification-channels / jet-sms
使用JetSms API发送短信
4.0.0
2020-03-07 01:00 UTC
Requires
- php: >=7.2
- erdemkeren/jet-sms-php: ^1.0
- illuminate/notifications: ^6.0 || ^7.0
- illuminate/queue: ^6.0 || ^7.0
- illuminate/support: ^6.0 || ^7.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-07 10:51:45 UTC
README
本包使用JetSms在Laravel 5.5+、6.x和7.x中发送通知变得简单。
内容
安装
您可以通过Composer安装此包
composer require laravel-notification-channels/jet-sms
配置JetSms服务
将您想要的客户端、用户名、密码、发送者(发件箱名称、发送者名称)和请求超时配置添加到您的 config/services.php
文件中
... 'JetSms' => [ 'client' => 'http', // or xml 'http' => [ 'endpoint' => 'https://service.jetsms.com.tr/SMS-Web/HttpSmsSend', ], 'xml' => [ 'endpoint' => 'www.biotekno.biz:8080/SMS-Web/xmlsms', ], 'username' => '', 'password' => '', 'originator' => "", // Sender name. 'timeout' => 60, ], ...
用法
现在您可以在通知中的via()方法中使用该通道
use NotificationChannels\JetSms\JetSmsChannel; use NotificationChannels\JetSms\JetSmsMessage; class ResetPasswordWasRequested extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [JetSmsChannel::class]; } /** * Get the JetSms representation of the notification. * * @param mixed $notifiable * @return string|\NotificationChannels\JetSms\JetSmsMessage */ public function toJetSms($notifiable) { return "Test notification"; // Or return new ShortMessage($notifiable->phone_number, 'Test notification'); } }
别忘了在您的notifiables(例如User)中放置JetSms的专用方法。
class User extends Authenticatable { use Notifiable; public function routeNotificationForJetSms() { return "905123456789"; } }
可用方法
JetSms也可以直接用于发送短信。
示例
JetSms::sendShortMessage($to, $message); JetSms::sendShortMessages([[ 'recipient' => $to, 'message' => $message, ], [ 'recipient' => $anotherTo, 'message' => $anotherMessage, ]]);
请参阅jet-sms-php 文档以获取更多信息。
可用事件
JetSms通知通道提供了方便的事件,这些事件提供了关于短信消息所需的信息。
- 消息已发送 (
NotificationChannels\JetSms\Events\MessageWasSent
) - 消息已发送 (
NotificationChannels\JetSms\Events\MessageWasSent
) - 正在发送消息 (
NotificationChannels\JetSms\Events\SendingMessage
) - 正在发送消息 (
NotificationChannels\JetSms\Events\SendingMessages
)
示例
namespace App\Listeners; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use NotificationChannels\JetSms\Events\MessageWasSent; class SentMessageHandler { /** * Handle the event. * * @param MessageWasSent $event * @return void */ public function handle(MessageWasSent $event) { $response = $event->response; $message = $event->message; } }
备注
$response->groupId() 如果客户端设置为 'http',将抛出 BadMethodCallException。 $response->messageReportIdentifiers() 如果客户端设置为 'xml',将抛出 BadMethodCallException。
请谨慎更改客户端配置。
变更日志
有关最近更改的详细信息,请参阅CHANGELOG。
测试
$ composer test
安全性
如果您发现任何安全问题,请通过电子邮件erdemkeren@gmail.com 而不是使用问题跟踪器。
贡献
有关详细信息,请参阅CONTRIBUTING。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。