cmnty / push
此包已被废弃,不再维护。未建议替代包。
PHP Web 推送库
0.0.1
2016-09-07 08:18 UTC
Requires
- php: ~5.6|~7.0
- ext-crypto: *
- guzzlehttp/guzzle: ~6.2.1
- mdanter/ecc: ~0.4.0
- spomky-labs/base64url: ~1.0
This package is not auto-updated.
Last update: 2022-04-30 06:25:12 UTC
README
PHP Web 推送库
安装
使用 composer 安装库
composer require cmnty/push
此库支持 ext-crypto
和 lib-openssl
用于加密需求。虽然可以通过 spomky-labs/php-aes-gcm
提供 php 回退,但建议仅作为最后的选择。
使用
<?php use Cmnty\Push\AggregatePushService; use Cmnty\Push\Client; use Cmnty\Push\Crypto\AuthenticationSecret; use Cmnty\Push\Crypto\PublicKey; use Cmnty\Push\EndPoint; use Cmnty\Push\GooglePushService; use Cmnty\Push\MozillaPushService; use Cmnty\Push\Notification; use Cmnty\Push\PushServiceRegistry; use Cmnty\Push\Subscription; $notification = new Notification('Hello', 'World!'); $subscription = new Subscription( new Endpoint('...'), new PublicKey::createFromBase64UrlEncodedString('...'), new AuthenticationSecret::createFromBase64UrlEncodedString('...') ); $pushServiceRegistry = new PushServiceRegistry(); $pushServiceRegistry->addPushService(new GooglePushService('API Key')); $pushServiceRegistry->addPushService(new MozillaPushService()); $pushService = new AggregatePushService($pushServiceRegistry); $client = new Client($pushService); $client->pushNotification($notification, $subscription);
默认情况下,使用 Cmnty\Push\Crypto\AggregateCrypt
类来加密通知。此类会尝试以下顺序使用第三方库或扩展来加密通知
- 使用
ext-crypto
(由Cmnty\Push\Crypto\ExtCryptoCrypt
实现)进行加密 - 使用
lib-openssl
(由Cmnty\Push\Crypto\OpenSSLCrypt
实现)进行加密 - 使用原生 php (由
Cmnty\Push\Crypto\SpomkyLabsCrypt
实现,使用spomky-labs/php-aes-gcm
)进行加密
您也可以通过传递给 PushClient 来强制使用某个库或扩展
<?php use Cmnty\Push\Client; use Cmnty\Push\Crypto\Cryptograph; use Cmnty\Push\Crypto\ExtCryptoCrypt; $pushService = ...; $cryptograph = new Cryptograph(new ExtCryptoCrypt()); $client = new Client($pushService, null, $cryptograph);
如果需要,您还可以通过实现 Cmnty\Push\Crypto\Crypt
接口来提供自己的实现。
框架集成
- Symfony: cmnty/push-bundle
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。