承接 ladumor/one-signal 相关项目开发

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

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

ladumor/one-signal

Composer 安装命令:

composer require ladumor/one-signal

包简介

Laravel Wrapper for OneSignal.

README 文档

README

Laravel One Signal is Laravel Wrapper for One Signal. One Signal is a great platform for send a push notification to your users. This package mentions in One Signal's official Document. you can see here

Total Downloads Daily Downloads Monthly Downloads License

Buy Me A Coffee

Give a Star if this package realy usefull to you. it's free 😆

🎞️ here are video tutorials

How to install and how to implement notifications and devices APIs.

how to implement Segment and Apps APIs.

Requirements.

v2.0.0 is released with new features and new APIs with latest version of one signal. this version is supported in laravel 8 and more. if you want to use this package in laravel 7 or lower version than you can use v1.0.0.

Contents

Watch Other Lavavel tutorial here

)

Installation

Install the package by the following command

composer require ladumor/one-signal:2.0.2

Publish the config file

Run the following command to publish config file,

php artisan vendor:publish --provider="Ladumor\OneSignal\OneSignalServiceProvider"

Add Provider

Add the provider to your config/app.php into provider section if using lower version of laravel,

Ladumor\OneSignal\OneSignalServiceProvider::class,

Add Facade

Add the Facade to your config/app.php into aliases section,

'OneSignal' => \Ladumor\OneSignal\OneSignal::class,

Add ENV data

Add your api keys and OneSignal app id to your .env,

ONE_SIGNAL_APP_ID=XXXXXX-XXXXXX-XXXXXX-XXXXXX  (YOUR APP ID)
ONE_SIGNAL_AUTHORIZE=XXXXXX                    (REST API KEY)
ONE_SIGNAL_AUTH_KEY=XXXXXXX                    (YOUR USER AUTH KEY)

You can call them into your code with,

Usage

Send Notification

Push

For send push notification, use the sendPush method by calling, you can refer this docs for more fields details.

$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
$message = 'hey!! this is test push.!'   

OneSignal::sendPush($fields, $message);

Optionally, you can obtain the id of the notification like this,

$notificationID = OneSignal::sendPush($fields, $message);
echo $notificationID["id"];

SMS

For send SMS notification, use the sendSMS method by calling,

$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
OR
$fields['include_phone_numbers'] = ['+15558675310'];

$fields['sms_from']= "+15558675309";

$message = 'hey!! this is test SMS.!'   

OneSignal::sendSMS($fields, $message);

EMAIL

Ensure your Email setup is complete. For send Email notification, use the sendEmail method by calling, see more payload param here

$fields = [
   'email_from_name' => 'Shailesh',
   'email_from_address' => "sml@gmail.com",
   'email_reply_to_address' => "reply@gmail.com",
   'email_subject' => "Welcome to Cat Facts",
   'email_body' => "html>Welcome to Cat Facts</html>",
   'disable_email_click_tracking' => true,
   'include_unsubscribed' => true
];

$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
OR
$fields['include_email_tokens'] = ['sample@gmail.com'];

OneSignal::sendEmail($fields);

Customise Contents

You can customise a contents and pass it in fields. message does not required when you pass contents

$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
or
$fields['include_aliases']['external_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];

$fields['contents'] = array(
                          "en" => 'English Message',
                          "es" => 'Spanish Message',
                      );
OneSignal::sendPush($fields);

Get Single Notification

For retrieve single notification, use the viewMessage method with id param by calling,

OneSignal::viewMessage($notificationId);    

You can check here return response format.

Get All Notifications

For retrieve all notifications, use the viewMessages method by calling,

OneSignal::viewMessages();

Cancel Notification

To cancel a notification, use the cancelNotification method by calling,

$notificationID = 'xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy';

OneSignal::cancelNotification($notificationID);

Notification History

For retrieve notification History, use the getMessageHistory method by calling,

$notificationID = 'xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy';
$params = [
    'events' => 'sent', // required
    'email' => 'sample@gmail.com', // optional, he email address in which to deliver the report.
];

OneSignal::getMessageHistory($notificationID, $params);

Start Live Activity

This API lets you start a Live Activity by sending a Push Notification., use the startLiveActivity method by calling, See for more params here

$params = [
    'activity_id' => '217aae2b-42ee-4097-bc3f-b7a6e9d15b9b'
];

OneSignal::startLiveActivity($activityType, $params);

Update Live Activity

Make updates and terminate running Live Activities, use the updateLiveActivity method by calling, See for more params here

    $params = [
        'event' => 'update'
    ];

    OneSignal::updateLiveActivity($params);

Create User

For register a new user in OneSignal’s system, use the createUser method by calling,


$params = [
        'properties' => [
            "tags" => [
                "foo"  => "bar",
                "this" => "that"
            ],
            "language"     =>  "en",
            "timezone_id"  =>  "America/Los_Angeles",
            "lat"          =>  37.7749,
            "long"         =>  -122.4194,
            "country"      =>  "US",
            "first_active" =>  1589788800,
            "last_active"  =>  1589788800,
            "purchases"    =>  0,
            "ip"           =>  3232235777
        ],
        'identity' = [
            "external_id"    => "An ID, defined by you, to refer to this user in the future",
            "facebook_id"    =>  "user_facebook_id",
            "amplitude_id"   =>  "user_amplitude_id",
            "mixpanel_id"    => "user_mixpanel_id",
            "custom_alias_N" =>  "An alternative ID you'll want for retrieving this user's profile data and tags"
        ],
        'subscriptions' => [
            [
                "type" => "Email",
                "token" =>  "sample@email.com",
                "enabled" => true,
            ],
            [
                "type" => "SMS",
                "token" =>  "phone_number_in_E.164_format",
                "enabled" => true,
            ],
            [
                 "type"=>  "iOSPush",
                 "token"=>  "20bdb8fb3bdadc1bef037eefcaeb56ad6e57f3241c99e734062b6ee829271b71",
                 "enabled"=>  true,
                 "notification_types"=>  1,
                 "session_time"=> 98,
                 "session_count"=> 6,
                 "sdk"=>  "",
                 "device_model"=>  "iPhone 14",
                 "device_os"=> "18.0",
                 "rooted"=>  false,
                 "test_type"=>  1,
                 "app_version"=>  "5.1.7",
                 "web_auth"=>  "",
                 "web_p256"=> : ""
            ]
        ];
    
    OneSignal::createUser($params);

View User

For retrieve a user including aliases, properties, and subscriptions, use the viewUser method by calling,

    OneSignal::viewUser($onesignalId, $aliasId);

Update User

For update a user’s properties, tags, and subscriptions, use the updateUser method by calling, You can refer here for more detail about $params

    OneSignal::updateUser($onesignalId, $aliasId, $params);

Delete User

Delete a user including all associated properties, subscriptions, and identity. use the deleteUser method by calling,

    OneSignal::deleteUser($onesignalId, $aliasId);

View User Identity

Retrieve a user’s identity, use the viewUserIdentity method by calling,

    OneSignal::viewUserIdentity($onesignalId, $aliasId);

View User Identity By Sponsorship

Retrieve a user’s identity by subscription, use the viewUserIdentityBySubscription method by calling,

    OneSignal::viewUserIdentityBySubscription($subscriptionId);

Create Alias

Create an alias for a user, use the createAlias method by calling, Refer docs here for more details

    $params = [
        'external_id'  => "",
        'onesignal_id' => "",
    ];
    
    OneSignal::createAlias($onesignalId, $aliasId, $params);

Create Alias by subscription

Create an alias for a user by subscription, use the createAliasBySubscription method by calling, Refer docs here for more details

    $params = [
        'external_id'  => "",
        'onesignal_id' => "",
    ];
    
    OneSignal::createAliasBySubscription($subscriptionId, $params);

Delete Alias

Delete an alias for a user, use the deleteAlias method by calling, Refer docs here for more details

    OneSignal::deleteAlias($onesignalId, $aliasId, $aliasLabelToDelete);

Create Subscription

Add a new subscription to your user. use the createSubscription method by calling, Refer docs here for more body params

    $fields = [
        'subscription'  => [],
    ];
    
    OneSignal::createSubscription($fields);

Update Subscription

Update an existing subscription, use the updateSubscription method by calling, Refer docs here for more details

     $fields = [
        'subscription'  => [],
    ];
    
    OneSignal::updateSubscription($subscriptionId, $fields);

Delete Subscription

Delete an existing subscription, use the deleteSubscription method by calling, Refer docs here for more details

    OneSignal::deleteSubscription($subscriptionId);

Transfer Subscription

Transfer a subscription to a different user, use the transferSubscription method by calling, Refer docs here for more details

    $fields = [
        'identity'  => [],
    ];
    
    OneSignal::transferSubscription($subscriptionId, $fields);

Unsubscribe Notification

Unsubscribe a user from a notification, use the unsubscribeNotification method by calling, Refer docs here for more details

    OneSignal::unsubscribeNotification($notificationId, $token);

Create Template

Create a template for push, email and sms, use the createTemplate method by calling, Refer docs here for push, email and sms template

    $fields = [
        'name'  => "",
        'content' => [
            "en": "English Message" 
        ],
        "sms_from"=>"+1234567890",
         "isSMS"=> true,
    ];
    
    OneSignal::createTemplate($fields);

Update Template

update a template for push, email and sms, use the updateTemplate method by calling, Refer docs here for push, email and sms template

    $fields = [
        'name'  => "",
        'content' => [
            "en": "English Message" 
        ],
        "sms_from"=>"+1234567890",
        "isSMS"=> true,
    ];
    
    OneSignal::updateTemplate($templateId, $fields);

View Template

For retrieve a template, use the viewTemplate method by calling,

    OneSignal::viewTemplate($templateId);

View Templates

For retrieve all templates, use the viewTemplates method by calling,

    $params = [
        'limit' => 10,
        'offset' => 0,
        'channel' => 'push',
     ];
     
    OneSignal::viewTemplates($params);

Delete Template

For delete a template, use the deleteTemplate method by calling,

    OneSignal::deleteTemplate($templateId);

Copy Template

For transfer a template, use the copyTemplate method by calling,

    $fields = [
        'target_app_id' => "",
    ];
    
    OneSignal::copyTemplate($templateId, $fields);

Create Segment

For add a new segment in your application, use the createSegment method by calling,

 $fields = [
         'name' => 'iOS, Android, Web',
         "filters" => array("field" => "device_type", "relation" => "=", "value" => "Android"),
     ];

return OneSignal::createSegment($fields); 

You can check here supported parameters and guide.

OneSignal::deleteSegment('YOUR_SEGMENT_ID')

Delete Segment

You can check here for more guide.

Apps

Note*: Auth key must be set in one-signal.php how to get auth_key?

View Apps

View the details of all of your current OneSignal apps

 $apps = OneSignal::getApps();

You can check here api response.

View App

View the details of single of your current OneSignal app or other app by passing app id.

 // It's return default site which is configured in config.
 $app = OneSignal::getApp();
 
 // you can specify app id as wel but it's optional
 $app = OneSignal::getApp('YOUR_APP_ID');

You can check here api response.

Create App

Creates a new OneSignal app.

 $fields = array(
        'name' => "TestByMe"
    );

 OneSignal::createApp($fields);

You can check here supported parameters and guide.

Update App

Update a new OneSignal app.

 $fields = array(
        'name' => "TestByMe"
    );

 OneSignal::updateApp($fields);
 // you can pass second param as a appId if you want to update other app.. default take from config.

You can check here supported parameters and guide.

View Outcomes

View the details of all the outcomes associated with your app.

 $fields = array(
        'outcome_names'       => "os__click.count",
        'outcome_time_range'  => '1h',
        'outcome_platform'    => 0,
        'outcome_attribution' => 'direct'
    );

 OneSignal::getOutcomes($fields);   // with params
 OneSignal::getOutcomes();  // without any params
 // you can pass params in this method, it's optional.

You can check here supported parameters and guide.

User Device

You can generate a User Device APIs with just one command,

php artisan one-signal.userDevice:publish

this command generate following files,

  • UserDeviceAPIController
  • UserDeviceAPIRepository
  • UserDevice (model)
  • Migration

Also, do not forget to add following routes in to the api.php file.

use App\Http\Controllers\API\UserDeviceAPIController;
  Route::post('user-device/register', [UserDeviceAPIController::class, 'registerDevice']);
  Route::get('user-device/{playerId}/update-status', [UserDeviceAPIController::class, 'updateNotificationStatus']);

Change Log

Please see Change Log here

License

The MIT License (MIT). Please see License File for more information

ladumor/one-signal 适用场景与选型建议

ladumor/one-signal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 347.91k 次下载、GitHub Stars 达 124, 最近一次更新时间为 2020 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「notification」 「laravel」 「push」 「one-signal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ladumor/one-signal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ladumor/one-signal 我们能提供哪些服务?
定制开发 / 二次开发

基于 ladumor/one-signal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 124
  • Watchers: 1
  • Forks: 24
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-28