sicaboy / pushok
PHP客户端,用于Apple Push Notification Service (APNs) - 使用基于token(JWT与p8私钥)或证书的认证,通过新的APNs HTTP/2协议发送iOS推送通知
1.0.0
2021-08-01 08:02 UTC
Requires
- php: ^7.2|^8.0
- ext-curl: *
- ext-intl: *
- ext-json: *
- ext-openssl: *
- ext-xml: *
- lib-curl: >=7.46.0
- lib-openssl: >=1.0.2.5
- web-token/jwt-key-mgmt: ^2.0
- web-token/jwt-signature-algorithm-ecdsa: ^2.0
Requires (Dev)
- ext-xdebug: *
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^8.4
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-09-29 06:20:04 UTC
README
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)。请参阅许可证文件获取更多信息。