PHP*_*Fan 2 php require push-notification php-include pushwoosh
我想通过为它编写PHP代码来向iPhone设备发送推送通知.
gomoob:php-pushwoosh是一个可以轻松使用pushwoosh REST Web服务的PHP库.
根据说明,我在我的本地机器上使用Composer在位置'/ var/www/gomoob-php-pushwoosh'上安装了gomoob:php-pushwoosh
我在一个名为"/var/www/gomoob-php-pushwoosh/sample_1.php"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();
}
?>
Run Code Online (Sandbox Code Playgroud)
但是我得到了以下错误:
Fatal error: Class 'Pushwoosh' not found in /var/www/gomoob-php-pushwoosh/sample_1.php on line 9
Run Code Online (Sandbox Code Playgroud)
在链接他们没有提到任何文件需要包含在代码中.他们只编写了示例代码程序.我已经使用了该程序,但却因此而出现错误.
那么有人可以帮我运行这个程序吗?
您想要的类位于命名空间中,因此您需要指示PHP从那里"导入"它(以及其他类); 将其添加到脚本的开头:
use Gomoob\Pushwoosh\Client\Pushwoosh;
use Gomoob\Pushwoosh\Model\Request\CreateMessageRequest;
use Gomoob\Pushwoosh\Model\Notification\Notification;
require __DIR__.'/vendor/autoload.php';
Run Code Online (Sandbox Code Playgroud)