ol-zamovshafu / devinotelecom-laravel
使用 Devinotelecom API 发送短信
Requires
- php: >=5.6.4
- illuminate/notifications: ^5.7
- illuminate/queue: ^5.7
- illuminate/support: ^5.7
- ol-zamovshafu/devinotelecom-php: ^1.3
Requires (Dev)
- mockery/mockery: ^0.9.5
- phpunit/phpunit: >=6.5
This package is not auto-updated.
Last update: 2024-09-30 21:23:51 UTC
README
此包使得在 Laravel 5.7 中使用 Devinotelecom 发送通知变得容易。
内容
安装
您可以通过 composer 安装此包。
composer require ol-zamovshafu/devinotelecom-laravel
接下来,将服务提供者添加到您的 config/app.php
文件中。
/* * Package Service Providers... */ NotificationChannels\Devinotelecom\DevinotelecomSmsServiceProvider::class,
将 DevinotelecomSms 别名注册到您的应用程序中。此注册不是可选的,因为该通道本身使用此别名。
'DevinotelecomSms' => NotificationChannels\Devinotelecom\DevinotelecomSms::class,
设置 DevinotelecomSms 服务
将您所需的客户端、登录、密码、发件人(出站名称、发送者名称)和请求超时配置添加到您的 config/services.php
文件中
... 'DevinotelecomSms' => [ 'client' => 'http', 'http' => [ 'endpoint' => 'https://integrationapi.net/rest/', ], 'login' => '', 'password' => '', 'originator' => '', // Sender name. 'timeout' => 60, ], ...
用法
现在您可以在通知中的 via() 方法中使用此通道。
use NotificationChannels\Devinotelecom\DevinotelecomSmsChannel; use Zamovshafu\Devinotelecom\ShortMessage; class ResetPasswordWasRequested extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [DevinotelecomSmsChannel::class]; } /** * Get the DevinotelecomSms representation of the notification. * * @param mixed $notifiable * @return string|\Zamovshafu\Devinotelecom\ShortMessage */ public function toDevinotelecomSms($notifiable) { return "Test notification"; // Or return new ShortMessage($notifiable->phone_number, 'Test notification'); } }
别忘了在您的 notifiables 中放置用于 DevinotelecomSms 的专用方法。(例如 User)
class User extends Authenticatable { use Notifiable; public function routeNotificationForDevinotelecomSms() { return "905123456789"; } }
可用方法
DevinotelecomSms 也可以直接用于发送短信。
示例
DevinotelecomSms::sendShortMessage($to, $message);
更多信息请参阅 devinotelecom-php 文档。
可用事件
DevinotelecomSms 通知通道附带方便的事件,提供了有关短信消息所需的信息。
- 消息已发送 (
NotificationChannels\Devinotelecom\Events\MessageWasSent
) - 发送消息 (
NotificationChannels\Devinotelecom\Events\SendingMessage
)
示例
namespace App\Listeners; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use NotificationChannels\Devinotelecom\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。
请谨慎更改客户端配置。
变更日志
有关最近更改的信息,请参阅 CHANGELOG。
测试
$ composer test
安全
如果您发现任何安全问题,请通过电子邮件 oleg.lobanov@zamovshafu.com.ua 而不是使用问题跟踪器。
贡献
有关详细信息,请参阅 CONTRIBUTING。
致谢
许可
版权所有 (c) Hilmi Erdem KEREN erdemkeren@gmail.com
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。