sicaboy/pushok

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

维护者

详细信息

github.com/sicaboy/pushok

主页

源码

安装: 27

依赖: 0

推荐者: 0

安全: 0

星标: 0

关注者: 1

分支: 120

1.0.0 2021-08-01 08:02 UTC

README

PHP >= 7.2 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.2
  • lib-curl >= 7.46.0(启用http/2支持)
  • lib-openssl >= 1.0.2e

满足要求的Docker镜像可以在这里找到。或者你可以遵循这个教程来创建自己的具有HTTP/2支持的curl 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->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) {
    $response->getApnsId();
    $response->getStatusCode();
    $response->getReasonPhrase();
    $response->getErrorReason();
    $response->getErrorDescription();
}

测试

$ composer test

安全

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

致谢

许可证

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