php - 是否需要包含来自 gomoob :php-pushwooshto to run a PHP program to send push notifications to iPhone? 的任何文件

标签 php push-notification require pushwoosh php-include

我想通过编写 PHP 代码向 iPhone 设备发送推送通知。

gomoob:php-pushwoosh 是一个 PHP 库,可以轻松地与 pushwoosh REST Web 服务配合使用。

This is the URL for gomoob:php-pushwoosh

按照说明,我在本地计算机上使用 Composer 安装了 gomoob:php-pushwoosh,位置为 '/var/www/gomoob-php -pushwoosh'

我在名为 sample_1.php 的文件中编写了以下代码,该文件位于 '/var/www/gomoob-php-pushwoosh/sample_1.php'

<?php

ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);

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


// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
    ->setApplication('XXXX-XXX')
    ->setAuth('xxxxxxxx');

// Create a request for the '/createMessage' Web Service
$request = CreateMessageRequest::create()
    ->addNotification(Notification::create()->setContent('Hello Jean !'));

// Call the REST Web Service
$response = $pushwoosh->createMessage($request);

// Check if its ok
if($response->isOk()) {
    print 'Great, my message has been sent !';
} else {
    print 'Oups, the sent failed :-('; 
    print 'Status code : ' . $response->getStatusCode();
    print 'Status message : ' . $response->getStatusMessage();
}
?>

但我收到以下错误:

Fatal error: Class 'Pushwoosh' not found in /var/www/gomoob-php-pushwoosh/sample_1.php on line 9

Link他们没有提到代码中需要包含任何文件。他们只编写了示例代码程序。我按原样使用了该程序,但出现错误。

有人可以帮我运行这个程序吗?

最佳答案

您想要的类驻留在命名空间中,因此您需要指示 PHP 从那里“导入”它(和其他类);将此添加到脚本的开头:

    use Gomoob\Pushwoosh\Client\Pushwoosh;
    use Gomoob\Pushwoosh\Model\Request\CreateMessageRequest;
    use Gomoob\Pushwoosh\Model\Notification\Notification;

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

关于php - 是否需要包含来自 gomoob :php-pushwooshto to run a PHP program to send push notifications to iPhone? 的任何文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30590074/

相关文章:

windows-phone-7 - 可本地化的推送通知

javascript - 动态要求和取消要求文件

php - 过滤和排序具有多个值的多维数组

iphone - 如何检测我的应用程序已从游戏中心推送通知启动

php - 停止SQL添加多行相同信息

iOS 11.2.5 - didRegisterForRemoteNotificationWithDeviceToken - 无响应

ruby - 如何在 IRB 中要求 ActiveRecord

php - 在 PHP 或 Wildcard 中包含整个目录以便在 PHP Include 中使用?

php - 如何附加数据库中已存在的序列化字符串

php - heroku 调度程序的一些问题