定制 dru1x/expo-server-sdk-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dru1x/expo-server-sdk-php

Composer 安装命令:

composer require dru1x/expo-server-sdk-php

包简介

Server-side library for working with the Expo push notification service using PHP 8.2+

README 文档

README

Test Workflow Status

Server-side library for working with the Expo Push service using PHP 8.2+

⚙ Installation

Requirements

Instructions

Install the library with composer:

composer require dru1x/expo-server-sdk-php 

🚀 Usage

First, instantiate the ExpoPush service:

use Dru1x\ExpoPush\ExpoPush;

$expoPush = new ExpoPush();

If additional security is being used, the access token can be supplied as an argument to the constructor:

use Dru1x\ExpoPush\ExpoPush;

$accessToken = 'NTLyMHB2vtZ1lWhgP0sjWJTOCed9zspT';
$expoPush    = new ExpoPush($accessToken);

Sending Push Notifications

Push notifications can be sent by supplying a PushMessageCollection, or an array of PushMessage objects, to the sendNotifications() method. This automatically chunks the given push messages into an appropriate number of requests and sends them concurrently to Expo's Push API. The max request size, concurrency limit and rate limit are applied as set out in Expo's Push API documentation. Therefore, the maximum throughput of this method is 600 notifications per second.

use Dru1x\ExpoPush\PushError\PushErrorCollection;
use Dru1x\ExpoPush\PushMessage\PushMessageCollection;
use Dru1x\ExpoPush\PushMessage\PushMessage;
use Dru1x\ExpoPush\PushTicket\PushTicketCollection;
use Dru1x\ExpoPush\PushToken\PushToken;

// This could also be an array of PushMessage objects
$messages = new PushMessageCollection(
    new PushMessage(
        to: new PushToken('ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]'),
        title: 'Hello',
        body: 'This is a push notification' 
    )
);

$result = $expoPush->sendNotifications($messages);

/** @var PushTicketCollection $tickets */
$tickets = $result->tickets;

/** @var PushErrorCollection|null $errors */
$errors = $result->errors;

The SendNotificationsResult object returned by sendNotifications() contains a collection of all the resulting PushTicket objects, as well as a collection of PushError objects representing any request-level errors encountered while sending the given batch of notifications.

The PushTicketCollection is ordered according to the order of the PushMessage objects passed in to sendNotifications(). Each PushTicket will either be a SuccessfulPushTicket or a FailedPushTicket, the latter representing a ticket that was returned with a status of "error".

If errors were encountered, they will be present in the PushErrorCollection, and the PushTicketCollection will have a gap in its keys that corresponds to the failed chunk of notifications. Inspect the errors to find out what went wrong.

Checking Tickets

Once notifications have been sent, Expo recommends that notification outcomes are checked. This is done by fetching PushReceipt objects, each identified by an ID included in a previously returned PushTicket.

Receipts can be fetched by supplying a PushReceiptIdCollection, or an array of push receipt ID strings, to the getReceipts() method. This also automatically chunks the given receipt IDs into an appropriate number of requests and sends them concurrently to the Expo Push API.

Expo recommends that this is done between 15 minutes and 24 hours after notifications were sent.

use Dru1x\ExpoPush\PushError\PushErrorCollection;
use Dru1x\ExpoPush\PushReceipt\PushReceiptIdCollection;
use Dru1x\ExpoPush\PushReceipt\PushReceiptCollection;

// This could also be an array of receipt ID strings
$receiptIds = new PushReceiptIdCollection(
    'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
    'YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY',
);

$result = $expoPush->getReceipts($receiptIds);

/** @var PushReceiptCollection $receipts */
$receipts = $result->receipts;

/** @var PushErrorCollection|null $errors */
$errors = $result->errors;

The GetReceiptsResult object returned by getReceipts() contains a collection of the resulting PushReceipt objects, as well as a collection of PushError objects representing any request-level errors encountered while getting the given batch of receipts.

The PushReceiptCollection respects the order of receipts returned by the Expo Push API. To find a specific receipt in the collection, the getById() method can be used. Each PushReceipt with either be a SuccessfulPushReceipt or a FailedPushReceipt, the latter representing a receipt that was returned with a status of "error".

If errors were encountered, they will be present in the PushErrorCollection, and the PushReceiptCollection will have a gap in its keys that corresponds to the failed chunk of notifications. Inspect the errors to find out what went wrong.

Further Information

More detailed information about Expo's Push API can be found on their documentation website.

💬 Support

Please report any problems by submitting an issue. Ensure that the problem is well-described and can be replicated by others. All issues will be reviewed as soon as is reasonably possible.

🤝 Contributing

Thank you for considering contributing! Please open a pull request, ensuring that test coverage is maintained or increased with any proposed changes. All pull requests will be reviewed as soon as is reasonably possible.

📄 License

Expo Push Server SDK (PHP) is open-sourced software licensed under the MIT licence.

dru1x/expo-server-sdk-php 适用场景与选型建议

dru1x/expo-server-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.8k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 05 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dru1x/expo-server-sdk-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-31