johnturingan / route-mobile-laravel-notifications
为 Laravel 的 RouteMobile 通知通道。
1.0.3
2022-08-13 17:38 UTC
Requires
- php: ^7.1.3|^8.0
- guzzlehttp/guzzle: ^6.0|^7.0
- illuminate/notifications: ~5.8.0|^6.0|^7.0|^8.0|^9.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.0|^8.0|^9.0
This package is not auto-updated.
Last update: 2024-09-22 03:22:29 UTC
README
A laravel package for sending notifications via route-mobile service.
安装 🚥
将包添加到您的 composer.json 文件中
"require": {
...
"johnturingan/route-mobile-laravel-notifications": "{version}"
},
或者直接运行 composer require
$ composer require johnturingan/route-mobile-laravel-notifications
配置 📄
要使用此插件,您需要将以下配置添加到您的 config/services.php 文件中
'route-mobile-notifications' => [
'host' => 'https://apis.rmlconnect.net',
'gateway' => \Snp\Notifications\Rml\Services\RouteMobileGateway::class,
'username' => 'username',
'password' => 'password',
'cache' => false // Set to true if you want to cache login response
]
用法 ✅
有关完整文档,请参阅 Laravel 通知文档
发送通知
要发送通知,您可以使用 Laravel 通知外观并将 Viber 手机号码作为第一个参数传递
public function send ()
{
Notification::send('639057654321', new LeadAddedNotification());
Notification::send(['639067654321', '639077654321'], new LeadAddedNotification());
}
Viber 通知格式化
如果通知支持作为 Routemobile Viber 消息发送,您应该在通知类中定义一个 toRMLViber 方法。此方法将接收一个 $notifiable 实体,并应返回一个 Snp\Notifications\Rml\Messages\ViberMessage 实例。让我们看看一个基本的 toRMLViber 示例
use Snp\Notifications\Rml\Constants\MessagingMethod;
use Snp\Notifications\Rml\Constants\MessagingType;
use Snp\Notifications\Rml\Messages\ViberMessage;
...
/**
* Get the Viber representation of the notification.
*
* @param mixed $notifiable
* @return Snp\Notifications\Rml\Messages\ViberMessage
*/
public function toRMLViber($notifiable)
{
return (new ViberMessage('This is a viber message from Laravel'))
->setRecipient($recipient)
->setType(MessagingType::SINGLE_TEXT)
->setMethod(MessagingMethod::ONE_WAY)
;
}
注意
如果您发现任何错误或您有一些想法可以使这个项目变得更好,请毫不犹豫地创建一个 pull request。
如果您发现此包很有用,一个简单的 star 就非常感谢。
MIT 许可证
版权 © 2022 Scripts and Pixels.