skvn/pushok

Apple Push Notification Service (APNs) 的 PHP 客户端 - 使用基于 token(JWT 与 p8 私钥)或证书的认证方式,通过新的 APNs HTTP/2 协议发送 iOS 推送通知

维护者

详细信息

github.com/skvn/pushok

主页

源代码

安装: 12

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 120

0.2.2 2017-01-20 14:35 UTC

This package is auto-updated.

Last update: 2024-08-29 04:31:17 UTC


README

PHP >= 7.0 Build Status Latest Version on Packagist Total Downloads Coverage Status Quality Score Software License

注意: 此库正在开发中

Pushok 是一个简单的 PHP 库,用于向 APNs 发送推送通知。

特性

  • 使用新的 Apple APNs HTTP/2 连接
  • 支持基于 JWT 的认证
  • 支持新的 iOS 10 特性,如 Collapse IDs、Subtitles 和 Mutable Notifications
  • 使用对 APNs 的并发请求
  • 已在 APNs 生产环境中测试并运行
  • 支持基于证书的认证

要求

  • PHP >= 7.0
  • lib-curl >= 7.46.0(需启用 http/2 支持)
  • lib-openssl >= 1.0.2e

满足要求的 Docker 镜像可以在这里找到。

安装

通过 Composer

$ composer require edamov/pushok

入门

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

use Pushok\AuthProvider;
use Pushok\Client;
use Pushok\Notification;
use Pushok\Payload;
use Pushok\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
];

$authProvider = AuthProvider\Token::create($options);

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

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

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

//add custom value to your notification, needs to be customized
$payload = $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) {
    $response->getApnsId();
    $response->getStatusCode();
    $response->getReasonPhrase();
    $response->getErrorReason();
    $response->getErrorDescription();
}

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件edamov@gmail.com报告,而不是使用问题跟踪器。

致谢

许可协议

MIT 许可协议(MIT)。请参阅许可文件获取更多信息。