sub100/notifications

Sub100 通知 Laravel SDK

dev-master 2021-02-03 14:02 UTC

This package is auto-updated.

Last update: 2024-09-29 05:42:53 UTC


README

此包使用 Sub100 通知 API 来发送电子邮件、短信和 WhatsApp 通知。

在您的 Laravel 项目中作为 composer 包的使用

通过 composer 安装

composer req sub100/notifications

发布配置

php artisan vendor:publish --provider="sub100\Notifications\Sub100NotificationServiceProvider"

配置 .env 文件

NOTIFICATION_URL=https://path-to-notification/api/
<?php

$message = new Message();
$message->subject('Subject');
$message->mailTemplate('notification.template.dir.filename');
$message->mailVariables(['name' => 'User']);
$message->addEmail('test@example.com.br');

Notification::notify($message);

在其他项目中使用

通过 composer 安装

composer req sub100/notifications
<?php

$authToken = '';

$message = new Message();
$message->message('Message text');
$message->addWhatsapp('+55 (44) 91234-5678');

$notification = new Notification('http://notification-api.example.com');

$notification->notify($message, $authToken);

其他示例

发送 Twilio WhatsApp 消息

<?php

$authToken = '';

$message = new Message();
$message->message('Message text');
$message->addWhatsapp('+55 (44) 91234-5678');
$message->senderServiceType('twilio');
$message->senderServiceCredentials([
    "twilio_auth_token"   => "8b74ff6655248c86fe0813e07d0f58a8",
    "twilio_account_sid"  => "AC16909ae3f38b03c7495d7dfbfd9dcbb4",
    "twilio_from"         => "whatsapp:+14155238886"
]);

$notification = new Notification('http://notification-api.example.com');

$notification->notify($message, $authToken);

使用预定义邮件正文发送电子邮件

<?php

$authToken = '';

$message = new Message();
$message->mailBody('<p>Message text</p>');
$message->addEmail('test@example.com.br');

$notification = new Notification('http://notification-api.example.com');

$notification->notify($message, $authToken);

获取通知历史

$authToken = '';

$originId = '';

$clientIds = ['',];

$notificationIds = ['',];

$notification = new Notification('http://notification-api.example.com');

$notification->historyByOrigin($originId, $authToken)

$notification->historyByClientAndOrigin($clientIds, $originId, $authToken);

$notification->historyByNotificationAndOrigin($notificationIds, $originId, $authToken)