在 PHP 中编写的将推送通知发送到 iPhone 的代码有什么错误?

What's the mistake in a code written in PHP for push notification to be sent to iPhone?

我已经使用 composer 在本地计算机的以下位置安装了 php-pushwoosh :

/var/www/gomoob-php-pushwoosh

现在我想通过PHP代码向iPhone发送推送通知。

因此,我自己尝试并在位于 /var/www/gomoob-php-pushwoosh/sample.php 的名为 sample.php 的文件中编写了 PHP 代码。以下是文件 sample.php

中的 PHP 代码

代码参考 Link : You can get the code reference here

php-pushwoosh 安装参考 Link : php-pushwossh installation reference link

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);

require __DIR__.'/vendor/autoload.php';

define('PW_AUTH', 'API TOKEN');
define('PW_APPLICATION', 'APPLICATION CODE');
define('PW_DEBUG', true);

function pwCall($method, $data) { 
    $url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
    $request = json_encode(['request' = $data]);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    if (defined('PW_DEBUG') && PW_DEBUG) {
        print "[PW] request: $request\n";
        print "[PW] response: $response\n";
        print "[PW] info: " . print_r($info, true);
    }
}

pwCall('createMessage', array(
    'application' => PW_APPLICATION,
    'auth' => PW_AUTH,
    'notifications' => array(
            array(
                'send_date' => 'now',
                'content' => 'test',
                'data' => array('custom' => 'json data'),
                'link' => 'http://pushwoosh.com/'
            )
        )
    )
);
?>

通过点击 URL localhost/gomoob-php-pushwoosh/sample.php 在浏览器中执行此代码后,我只看到空白页面,没有错误,没有警告,没有通知。

为什么会这样?有人可以通过提供适当的解释来纠正我在代码中犯的错误并使我的代码可行吗?

如果您需要有关我所面临问题的任何进一步信息,请告诉我。

如果您有任何建议、评论、回答、批评等,都非常欢迎。任何形式的帮助将不胜感激。

谢谢。

在这一行:

$request = json_encode(['request' = $data]);
                                  ^

显然应该是:

$request = json_encode(['request' => $data]);

您没有看到任何通知,因为必须在脚本外部设置 display_errors 设置才能捕获诸如此类的解析错误。