承接 shokme/laravel-onesignal 相关项目开发

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

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

shokme/laravel-onesignal

Composer 安装命令:

composer require shokme/laravel-onesignal

包简介

Laravel OneSignal Notification

README 文档

README

The shokme/laravel-onesignal package provides easy to use facade to send notification to your users via onesignal. It uses the latest functionality of PHP8.1.

Here's a demo of how you can use it:

$response = OneSignal::make()
    ->subject('Notification Title')
    ->contents(['en' => 'Notification Body', 'es' => 'Translated Notification Body'])
    ->url('en.myapp.service://')
    ->sendTo(SignalType::Users, [1, 2, 3]);

Find below the documentation of all available methods.

Installation

You can install the package via composer:

composer require shokme/laravel-onesignal

define environment variables:

ONESIGNAL_APP_ID=your-app-id
ONESIGNAL_REST_API_KEY=your-api-key

You may want to publish the config file to update http timeout and retry:

php artisan vendor:publish --provider="Shokme\OneSignal\OneSignalServiceProvider" --tag="config"

Documentation

Message

You can use a string or array of language to set the message(title,subtitle,contents). If you set a string, it will be set to 'en' for default language.

OneSignal::subject('Notification Title'); // ['en' => 'Notification Title']
OneSignal::subject(['en' => 'Notification Title', 'nl' => 'Translated Notification Title']);

Url

You can set the url to open when user click the notification.

OneSignal::url('https://example.com');

Buttons

Mobile

OneSignal::buttons(ButtonType::Mobile, [
    ['id' => 'action-1', 'text' => 'Action To Trigger'],
    ...
]);

Web

OneSignal::buttons(ButtonType::Web, [
    ['id' => 'action-1', 'text' => 'Action To Trigger', 'url' => 'https://app.com'],
    ...
]);

Additional Parameters

If you have to use some parameters that are not supported by the package, you can set them using this method:

OneSignal::parameters(['template_id' => 'be4a8044-bbd6-11e4-a581-000c2940e62c'])

Schedule and Delay

You can read the OneSignal documentation for more information.

Schedule

is equal to send_after parameter.

OneSignal::schedule(Carbon::parse('17 april 2022')->timezone('GMT+3'));

Delay

is equal to delayed_option parameter, if timezone is set you need to set the second arguments($time).

$lastActive = OneSignal::delay(Delay::LastActive);
$timezone = OneSignal::delay(Delay::Timezone, '9:00AM');

Channels

When using only one channel.

OneSignal::channel(Channel::Sms);

When using multiple channel.

OneSignal::channels([Channel::Sms, Channel::Push]);

Filters

You can see Available Filters.
If you want to know how to Format Filters.

OneSignal::filters([
    ['field' => 'tag', 'key' => 'test', 'relation' => '=', 'value' => 'test'],
    ['field' => 'tag', 'key' => 'test2', 'relation' => '>=', 'value' => 'test2'],
])

or you can chain filter, watch out in some case you may need to combine with filters() because some fields aren't supported at the moment.

OneSignal::filter('tag', 'level', 10)
    ->filter('amount_spent', '>', 0)
    ->filter('session_count', 5);

//[
//    ['field' => 'tag', 'key' => 'test', 'relation' => '=', 'value' => 10],
//    ['field' => 'amount_spent', 'relation' => '>=', 'value' => '0'],
//    ['field' => 'session_count', 'relation' => '=', 'value' => '5'],
//]

Sending Notification

You can send multiple kind of notification. By default, the notification use the push channel.

$response = OneSignal::sendTo(SignalType::All);
$response = OneSignal::sendTo(SignalType::Users, [1,2,3]);
$response = OneSignal::channel(Channel::Sms)->sendTo(SignalType::Players, ['player_id-1', 'player_id-2']);
$response = OneSignal::sendTo(SignalType::Segments, ['Active Users', 'Inactive Users']);
$response = OneSignal::filters([...])->sendTo(SignalType::Filters);

Notifications

Retrieve all

You can retrieve all notifications using:

$response = OneSignal::getNotifications();
// Dashboard, Api or Automated
$response = OneSignal::getNotifications(Kind::Dashboard);

Retrieve one

You can add a second argument to specify your $outcomes. Check the OneSignal outcomes documentation.

$response = OneSignal::getNotification('notification_id');

Cancel

$response = OneSignal::cancel('notification_id');

Player

OneSignal Device documentation

Add

All device type can be found in Shokme\OneSignal\Enum\DeviceType.php.

$response = OneSignal::addPlayer(DeviceType::Android, 'push-token-from-google', 'Australia/Sydney', [
    'device_model' => 'Nexus 5X',
]);

Edit

$response = OneSignal::editPlayer('push-token-from-google', timezone: 'Europe/Brussels');

Contribution

This package might not be complete as it is made for personal use. If you want to contribute, please feel free to open an issue or pull request.

shokme/laravel-onesignal 适用场景与选型建议

shokme/laravel-onesignal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.94k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 shokme/laravel-onesignal 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-18