承接 norkunas/onesignal-php-api 相关项目开发

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

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

norkunas/onesignal-php-api

Composer 安装命令:

composer require norkunas/onesignal-php-api

包简介

OneSignal API for PHP

README 文档

README

Latest Stable Version Scrutinizer Code Quality Total Downloads GitHub Workflow Status Software License

Install

Note: All examples are for v2, if you are using PHP <7.3 please read v1 documentation.

This packages requires a PSR-18 HTTP client and PSR-17 HTTP factories to work. You can choose any from psr/http-client-implementation and psr/http-factory-implementation

Example with Symfony HttpClient and nyholm/psr7 http factories, install it with Composer:

composer require symfony/http-client nyholm/psr7 norkunas/onesignal-php-api

And now configure the OneSignal api client:

<?php

declare(strict_types=1);

use OneSignal\Config;
use OneSignal\OneSignal;
use Symfony\Component\HttpClient\Psr18Client;
use Nyholm\Psr7\Factory\Psr17Factory;

require __DIR__ . '/vendor/autoload.php';

$config = new Config('your_application_id', 'your_application_auth_key', 'your_auth_key');
$httpClient = new Psr18Client();
$requestFactory = $streamFactory = new Psr17Factory();

$oneSignal = new OneSignal($config, $httpClient, $requestFactory, $streamFactory);

How to use this library

Applications API

View the details of all of your current OneSignal applications (official documentation):

$myApps = $oneSignal->apps()->getAll();

View the details of a single OneSignal application (official documentation):

$myApp = $oneSignal->apps()->getOne('application_id');

Create a new OneSignal app (official documentation):

$newApp = $oneSignal->apps()->add([
    'name' => 'app name',
    'gcm_key' => 'key'
]);

Update the name or configuration settings of OneSignal application (official documentation):

$oneSignal->apps()->update('application_id', [
    'name' => 'new app name'
]);

Create Segments (official documentation):

$oneSignal->apps()->createSegment('application_id', [
    'name' => 'Segment Name',
    'filters' => [
        ['field' => 'session_count', 'relation' => '>', 'value' => 1],
        ['operator' => 'AND'],
        ['field' => 'tag', 'relation' => '!=', 'key' => 'tag_key', 'value' => '1'],
        ['operator' => 'OR'],
        ['field' => 'last_session', 'relation' => '<', 'value' => '30,'],
    ],
]);

Delete Segments (official documentation):

$oneSignal->apps()->deleteSegment('application_id', 'segment_id');

View the details of all the outcomes associated with your app (official documentation):

use OneSignal\Apps;
use OneSignal\Devices;

$outcomes = $oneSignal->apps()->outcomes('application_id', [
    'outcome_names' => [
        'os__session_duration.count',
        'os__click.count',
        'Sales, Purchase.sum',
    ],
    'outcome_time_range' => Apps::OUTCOME_TIME_RANGE_MONTH,
    'outcome_platforms' => [Devices::IOS, Devices::ANDROID],
    'outcome_attribution' => Apps::OUTCOME_ATTRIBUTION_DIRECT,
]);

Devices API

View the details of multiple devices in one of your OneSignal apps (official documentation):

$devices = $oneSignal->devices()->getAll();

View the details of an existing device in your configured OneSignal application (official documentation):

$device = $oneSignal->devices()->getOne('device_id');

Register a new device to your configured OneSignal application (official documentation):

use OneSignal\Devices;

$newDevice = $oneSignal->devices()->add([
    'device_type' => Devices::ANDROID,
    'identifier' => 'abcdefghijklmn',
]);

Update an existing device in your configured OneSignal application (official documentation):

$oneSignal->devices()->update('device_id', [
    'session_count' => 2,
    'ip' => '127.0.0.1', // Optional. New IP Address of your device
]);

Update an existing device's tags in one of your OneSignal apps using the External User ID (official documentation):

$externalUserId = '12345';
$response = $oneSignal->devices()->editTags($externalUserId, [
    'tags' => [
        'a' => '1',
        'foo' => '',
    ],
]);

Notifications API

View the details of multiple notifications (official documentation):

$notifications = $oneSignal->notifications()->getAll();

Get the details of a single notification (official documentation):

$notification = $oneSignal->notifications()->getOne('notification_id');

Create and send notifications or emails to a segment or individual users. You may target users in one of three ways using this method: by Segment, by Filter, or by Device (at least one targeting parameter must be specified) (official documentation):

$oneSignal->notifications()->add([
    'contents' => [
        'en' => 'Notification message'
    ],
    'included_segments' => ['All'],
    'data' => ['foo' => 'bar'],
    'isChrome' => true,
    'send_after' => new \DateTime('1 hour'),
    'filters' => [
        [
            'field' => 'tag',
            'key' => 'is_vip',
            'relation' => '!=',
            'value' => 'true',
        ],
        [
            'operator' => 'OR',
        ],
        [
            'field' => 'tag',
            'key' => 'is_admin',
            'relation' => '=',
            'value' => 'true',
        ],
    ],
    // ..other options
]);

Mark notification as opened (official documentation):

$oneSignal->notifications()->open('notification_id');

Stop a scheduled or currently outgoing notification (official documentation):

$oneSignal->notifications()->cancel('notification_id');

Notification History (official documentation):

$oneSignal->notifications()->history('notification_id', [
    'events' => 'clicked', // or 'sent'
    'email' => 'your_email@email.com',
]);

Questions?

If you have any questions please open a discussion.

License

This library is released under the MIT License. See the bundled LICENSE file for details.

norkunas/onesignal-php-api 适用场景与选型建议

norkunas/onesignal-php-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.81M 次下载、GitHub Stars 达 236, 最近一次更新时间为 2015 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.81M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 244
  • 点击次数: 32
  • 依赖项目数: 19
  • 推荐数: 1

GitHub 信息

  • Stars: 236
  • Watchers: 13
  • Forks: 82
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-22