asanbarco/notifier

该软件包最新版本(3.3.2)没有可用的许可信息。

3.3.2 2019-11-20 12:35 UTC

README

Notifier是一个通知服务软件包,用于处理发送各种推送、短信、电子邮件和其他通知类型的过程。它基于Laravel 5.5,并通过Redis代理上的Laravel队列管理器异步发送所有通知。

安装

通过Packagist安装该软件包

composer require asanbarco/notifier

配置

将Notifier配置文件发布到您的应用程序中,并填写您想要使用的服务的配置

php artisan vendor:publish

运行迁移命令以创建notifiers架构

php artisan migrate

将以下环境添加到您的应用程序的.env文件中,以逗号分隔,以便在通知作业中设置提供者的优先级

SMS_PROVIDERS_PRIORITY=sms0098,smsir

SMS0098_FROM=YOUR-NUMBER
SMS0098_USERNAME=YOUR-USERNAME
SMS0098_PASSWORD=YOUR-PASSWORD

SMSIR_URI=http://restfulsms.com/api/MessageSend
SMSIR_TOKEN=http://restfulsms.com/api/Token
SMSIR_API_KEY=YOUR-API-KEY
SMSIR_SECRET_KEY=YOUR-SECRET-KEY
SMSIR_LINE_NUMBER=YOUR-NUMBER

PUSH_PROVIDERS_PRIORITY=chabok,onesignal

CHABOK_URI_DEV=https://sandbox.push.adpdigital.com/api/
CHABOK_APP_ID_DEV=YOUR-ID
CHABOK_ACCESS_TOKEN_DEV=YOUR-TOKEN

CHABOK_URI=https://YOUR-ID.push.adpdigital.com/api/
CHABOK_APP_ID=YOUR-ID
CHABOK_ACCESS_TOKEN=YOUR-TOKEN

请记住,在服务器上运行队列 artisan 命令

php artisan queue:work

将您的应用程序的.envQUEUE_DRIVER设置为redis以异步运行作业

如何使用

在您的应用程序中使用Asanbar\Notifier\Notifier接口,以下方法可用:sendPushsendSms

public function sendSMS(array $numbers, string $txt)
{
    Notifier::onQueue('sms'); //if you do not set queue name it run send immediately and return result
    return Notifier::sendSMS($txt, $numbers);
}

public function sendPush(array $tokens, string $title, string $txt, ?array $data = [])
{
    Notifier::onQueue('push');
    return Notifier::sendPush($title, $txt, $tokens, $data);
}

设置用户已阅读通知

Notifier::read($id);

读取数据

您可以使用基于状态和类型的通知数量

Notifier::getCounts();
Notifier::getCounts($userId); // with user iddentifier (id or mobile ...)

获取已读或未读通知

Notifier::getUnReads(); // or getReads()
Notifier::getUnReads($identifier, $type, $limit); // all parameters are optional. If set limit it make paginator

开发者

Mehrad Aladini

重构: Mehrdad Dadkhah

许可

AsanBar.