minishlink / web-push-bundle
基于 WebPush 库的 Symfony 扩展包
v6.1.0
2024-05-04 10:24 UTC
Requires
- php: ^7.2 || ^8.0
- minishlink/web-push: ^6.0|^7.0|^8.0
Requires (Dev)
- matthiasnoback/symfony-dependency-injection-test: ^3.0
- phpunit/phpunit: ^7.1
- symfony/framework-bundle: ^4.2|^5.0
- symfony/phpunit-bridge: ^5.0
README
本扩展包提供了对 WebPush 库 的简单集成。
用法
Web Push 通过端点发送通知,这些端点服务器按照 Web Push API 规范 描述的方式提供 Web Push 通知。
<?php /** @var \Minishlink\WebPush\WebPush */ $webPush = $this->container->get('minishlink_web_push');
该扩展包提供了一个新的 minishlink_web_push
服务,它返回一个 Minishlink\WebPush\WebPush
的实例。
有关如何使用 $webPush
的更多信息,请查看 Minishlink/web-push。
安装
composer require minishlink/web-push-bundle
- 在您的
app/AppKernel.php
中启用扩展包。
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Minishlink\Bundle\WebPushBundle\MinishlinkWebPushBundle(), // ... ); }
配置
以下是默认配置,您可以在您的 app/config/config.yml
中修改它。
minishlink_web_push: VAPID: subject: https://yoursite.com # can be an URL or a mailto: publicKey: ~88 chars # uncompressed public key P-256 encoded in Base64-URL privateKey: ~44 chars # the secret multiplier of the private key encoded in Base64-URL pemFile: path/to/pem # if you have a PEM file and can link to it on your filesystem pem: pemFileContent # if you have a PEM file and want to hardcode its content ttl: 2419200 # Time to Live of notifications in seconds urgency: ~ # can be very-low / low / normal / high topic: ~ # default identifier for your notifications timeout: 30 # Timeout of each request in seconds automatic_padding: true # pad messages automatically for better security (against more bandwith usage)