运行php程序向iPhone发送推送通知时,是否需要包含来自gomoob:php pushwooshto的任何文件?
我想通过编写PHP代码向iPhone设备发送推送通知 gomoob:php-pushwoosh是一个php库,可以轻松使用pushwoosh REST Web服务 根据说明,我已在本地机器上使用Composer在'/var/www/gomoob-php-pushwoosh'位置安装了gomoob:php-pushwoosh运行php程序向iPhone发送推送通知时,是否需要包含来自gomoob:php pushwooshto的任何文件?,php,push-notification,require,pushwoosh,php-include,Php,Push Notification,Require,Pushwoosh,Php Include,我想通过编写PHP代码向iPhone设备发送推送通知 gomoob:php-pushwoosh是一个php库,可以轻松使用pushwoosh REST Web服务 根据说明,我已在本地机器上使用Composer在'/var/www/gomoob-php-pushwoosh'位置安装了gomoob:php-pushwoosh <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_repo
<?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();
}
?>
我在一个名为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();
}
?>
目前,他们还没有提到代码中需要包含任何文件。他们只编写了示例代码程序。我已经按原样使用了那个程序,但结果却出错了
有人能帮我运行这个程序吗?您想要的类驻留在名称空间中,因此您需要指示PHP从那里“导入”它(和其他类);将以下内容添加到脚本的开头:
use Gomoob\Pushwoosh\Client\Pushwoosh;
use Gomoob\Pushwoosh\Model\Request\CreateMessageRequest;
use Gomoob\Pushwoosh\Model\Notification\Notification;
require __DIR__.'/vendor/autoload.php';