【发布时间】:2017-07-24 11:09:26
【问题描述】:
我想在 PHP 中创建一个网络推送通知,但我没有确切的程序。以下是我找到的代码,但它不起作用。
<?php
require __DIR__ . '/../vendor/autoload.php';
use Minishlink\WebPush\WebPush;
$subscription = json_decode(file_get_contents('php://input'), true);
$auth = array(
'VAPID' => array(
'subject' => '`enter code here`',
'publicKey' => '**********',
'privateKey' => '***********',
),
);
$webPush = new WebPush($auth);
$res = $webPush->sendNotification(
$subscription['endpoint'],
"Hello!",
$subscription['key'],
$subscription['token'],
true
);
请提出正确的步骤。
【问题讨论】:
-
什么不起作用?你有任何错误吗?
-
可能是gist.github.com/prime31/5675017对你有帮助
-
是的,有一些内部服务器错误 n 它没有发出通知。
-
很难说仅仅一个代码 sn-p 有什么问题 - 网络推送可能非常困难。你试过服务吗?例如 Pushpad 有一个 PHP 库:github.com/pushpad/pushpad-php
-
PHP 警告:需要(/home/ambu/web-push-php-example/src/../vendor/autoload.php):无法打开流:/ 中没有这样的文件或目录home/ambu/web-push-php-example/src/send_push_notification.php 在第 2 行 [2017 年 7 月 26 日星期三 16:31:16] PHP 致命错误:require():打开失败需要 '/home/ambu/web- push-php-example/src/../vendor/autoload.php' (include_path='.:/usr/share/php') 在 /home/abc/web-push-php-example/src/send_push_notification.php .这是我在 cammand 提示符中遇到的错误
标签: php push-notification web-push