承接 karunais13/multiple-notification-provider 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

karunais13/multiple-notification-provider

最新稳定版本:v3.3.0

Composer 安装命令:

composer require karunais13/multiple-notification-provider

包简介

Multiple Notification

README 文档

README

Build Status Latest Stable Version PHP version License

Laravel has some pretty sweet functions for sending notification. Due to business nature, certain helper by laravel need to modify. Thus, this package is created to handle the business nature.

This package allows us send push and email notification to all device (iOS, Android, Web) using 3rd party such as OneSignal and Firebase.

Installation

Install the usual composer way.

Run this command at root directory of your project
"composer require karunais13/multiple-notification-provider"

For Laravel 5.5 and below add provider in config file like below :

app/config/app.php
	...
	
	'providers' => array(
		...
		Karu\NpNotification\NpNotificationProvider::class,
	],
	
	...

        'aliases' => [
            ...
            NotificationHelper: Karu\NpNotification\Facade\NotificationFacade::class
        ]

Configure

Copy the packages config and routes files to respective folder.

 php artisan vendor:publish --provider=Karu\NpNotification\NpNotificationProvider
app/config/notification.php
<?php

return [
    /*
     * The 3rd party service use to send notification .
     * Supported for now : web -> onesignal  email -> default (Will add in more service in feature)
     */
    'service' => [
        'web'    => 'onesignal',
        'email'  => 'default',
        'mobile' => 'onesignal'
    ],

    /*
     * Array contain template for all the notification.
     */
    'template' => [
        /*
         * Unique template code for notification helper to choose form the view folder.
         */
        '{templateCode}' => [
            'web_push'  => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ],
            'mobile_push' => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ],
            'email' => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ],
            'sms'   => [
                'subject' => '', //subject
                'content' => '' //view location Ex : notification.%s.{templateCode}.pic.email_subject (%s -> country_code)
            ]
        ]
    ],

    /*
     * Method used to get user information.
     * This method must be added to respective modal class
     */
    'user_info_method' => 'getNotificationUserInfo',

    /*
     * Table names
     */
    'tables' => [
        'notification_store' => 'notification',
        'notification_token' => 'notification_token',
    ],

    /*
     * User Type
     */
    'user_type' => [
        'd' => \App\Models\Sample::class, // Sample
        'c' => \App\Models\Sample2::class, // Sample
    ],


    /*
     * Store/Log Notification on database
     */
    'log_notification' => true
];
    
app/routes/notification.php
<?php
/*
|--------------------------------------------------------------------------
| Notification
|--------------------------------------------------------------------------
|
*/
Route::group(['prefix'=> 'notification'], function(){
    /*
    |
    | User Class -> set in the notification config with type as key
    |
    */
    Route::put('token/{user_class}/{user_id}', 'NotificationTokenController@update')
        ->name('noti.update-installation');
    Route::put('/{notification_id}', 'NotificationController@update')
        ->name('noti.update');
});

Usage

Type of Notification Constant

    NOTIFICATION_TYPE_EMAIL 
    NOTIFICATION_TYPE_WEB_PUSH    
    NOTIFICATION_TYPE_NATIVE_PUSH 
    NOTIFICATION_TYPE_SMS          

Set Config(Optional)

 //Default Setting
 $notiSetting = [
    'email' => true,
    'notification' => true, //Web & Mobile
    'sms' => false
 ];

 $noti = NotificationHelper::setConfig($notiSetting)->sendNotificationToUser($user, $templateCode, $extraParam);

Send Notification

 $noti = NotificationHelper::sendNotificationToUser($user, $templateCode, $extraParam);

Get Notification List

    /**
     * @param $userId
     * @param $userType (User class name)
     * @param $notiType (NOTIFICATION_TYPE_EMAIL | NOTIFICATION_TYPE_WEB_PUSH | NOTIFICATION_TYPE_NATIVE_PUSH | NOTIFICATION_TYPE_SMS)
     * @param  int  $pastDay (For all record send 0) 
     *
     * @return collection
     */
 $notiList = NotificationHelper::getUnReadUserNotificationList($userId, $userType, $notiType, $pastDay);

Unsubscribe User from notification

    /**
     * @param $userId
     * @param $userClassType (from notification config user type) 
     * @param $token
     *
     * @return bool
     */
 $notiList = NotificationHelper::unsubscribeUser($userId, $userClassType, $token);

Licence

View the licence in this repo.

统计信息

  • 总下载量: 481
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固