承接 dutchie027/apnpush 相关项目开发

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

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

dutchie027/apnpush

Composer 安装命令:

composer require dutchie027/apnpush

包简介

PHP client for Apple Push Notification Service (APNs)

README 文档

README

Software License

Apnpush is a simple PHP library for sending push notifications via Apple's APN Service.

Features

  • Uses new Apple APNs HTTP/2 connection
  • Supports JWT-based authentication
  • Supports Certificate-based authentication
  • Supports new iOS features such as Collapse IDs, Subtitles and Mutable Notifications
  • Uses concurrent requests to APNs
  • Tested and working in APNs production environment

Requirements

  • PHP 7.4+
  • lib-curl >= 7.46.0 (with http/2 support enabled)
  • lib-openssl >= 1.0.2e

Install

Via Composer

$ composer require dutchie027/apnpush

Getting Started

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

use Apnpush\Client;
use Apnpush\Notification;
use Apnpush\Payload;
use Apnpush\Payload\Alert;

$options = [
    'key_id' => 'AAAABBBBCC', // The Key ID obtained from Apple developer account
    'team_id' => 'DDDDEEEEFF', // The Team ID obtained from Apple developer account
    'app_bundle_id' => 'com.app.Test', // The bundle ID for app obtained from Apple developer account
    'private_key_path' => __DIR__ . '/private_key.p8', // Path to private key
    'private_key_secret' => null // Private key secret
];

// Be aware of thing that Token will stale after one hour, so you should generate it again.
// Can be useful when trying to send pushes during long-running tasks
$authProvider = Apnpush\AuthProvider\Token::create($options);

$alert = Alert::create()->setTitle('Hello!')->setBody('First push notification');

$payload = Payload::create()->setAlert($alert);

//set notification sound to default
$payload->setSound('default');

//add custom value to your notification, needs to be customized
$payload->setCustomValue('key', 'value');

$deviceTokens = ['<device_token_1>', '<device_token_2>', '<device_token_3>'];

$notifications = [];
foreach ($deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload,$deviceToken);
}

$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);

$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

foreach ($responses as $response) {
    // The device token
    $response->getDeviceToken();
    // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0
    $response->getApnsId();
    
    // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.)
    $response->getStatusCode();
    // E.g. The device token is no longer active for the topic.
    $response->getReasonPhrase();
    // E.g. Unregistered
    $response->getErrorReason();
    // E.g. The device token is inactive for the specified topic.
    $response->getErrorDescription();
    $response->get410Timestamp();
}

Using Certificate (.pem). Only the initilization differs from JWT code (above). Remember to include the rest of the code by yourself.

<?php

$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);


// Set the number of concurrent requests sent through the multiplexed connections. Default : 20
$client->setNbConcurrentRequests( 40 );

// Set the number of maximum concurrent connections established to the APNS servers. Default : 1
$client->setMaxConcurrentConnections( 5 );

$responses = $client->push();

Testing

# run php fixer
$ composer fix

# run phpstan
$ compser stan

# run phpunit tests
$ composer test

# run all three above test in sequence
$ composer runall

To-Do

  • Fix the tests
    • Ensure they all port/move ok (pslam)
    • Check to see if http/2 is installed
  • Clean up the documentation
  • Other things

Code of Conduct

This project adheres to a code of conduct. By participating in this project and its community, you are expected to uphold this code.

License

Apnpush is released under the MIT License. See LICENSE for details.

Versioning

This code uses Semver. This means that versions are tagged with MAJOR.MINOR.PATCH. Only a new major version will be allowed to break backward compatibility (BC).

Classes marked as @experimental or @internal are not included in our backward compatibility promise. You are also not guaranteed that the value returned from a method is always the same. You are guaranteed that the data type will not change.

Contributing

Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.

Credits

dutchie027/apnpush 适用场景与选型建议

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

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

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

围绕 dutchie027/apnpush 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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