midnite81/ prowl
PHP包装器,用于Prowl,支持Laravel集成
Requires
- php: >=5.5.9
- midnite81/xml2array: ^1.0
- nesbot/carbon: ^1.3|^2.0
- php-http/client-implementation: ^1
- php-http/discovery: ^1.2.1
- php-http/guzzle6-adapter: ^1.1
- php-http/message: ^1.5
Requires (Dev)
- mockery/mockery: ^1.1
- phpunit/phpunit: ^6|^7
- satooshi/php-coveralls: 1.0.*
- symfony/finder: ^3.4|^4.1
README
PHP包装器,用于使用Prowl API,提供Laravel 5服务提供者以集成Laravel。请注意,您不需要安装Laravel即可使用此包。
安装
此包需要PHP 5.6+,并包含Laravel服务提供者和外观以实现Laravel集成。请注意,您不需要安装laravel即可使用此包。
要通过composer安装,请将包包含在您的composer.json
中。
"midnite81/prowl": "^2.0.0"
运行composer install
或composer update
以下载依赖项,或者您可以运行composer require midnite81/prowl
。
HTTP标准
为了遵循更好的标准,此包使用流行的强大PHP-HTTP库来发起HTTP请求。默认情况下,当使用midnite81\prowl
时需要Guzzle适配器。这允许您使用自己的HTTP客户端而不是Guzzle。有关PHP-HTTP的更多信息,请访问php-http.org
版本控制
Laravel 5集成
如果您想使用此包与Laravel一起使用,请访问laravel特定README。
标准(非Laravel)实现
要开始使用此Prowl包装器,您需要实例化prowl类。Prowl对象的构造函数需要一个数组进行配置。如果您不提供,它将使用默认值。以下是一个示例配置。
<?php use Midnite81\Prowl\Prowl; include __DIR__ . '../vendor/autoload.php'; /** * By default, the package will use Guzzle to process our HTTP requests, but you can use anything that * implements the PHP-HTTP standard */ $prowl = Prowl::create(['apiUrl' => 'https://api.prowlapp.com/publicapi']);
Prowl类上有四个主要方法,分别对应您可以做出的四个主要API调用。
要了解这些API调用各自的作用,请查看https://www.prowlapp.com/api.php上的文档。
为了向链接到Prowl的设备发送通知,您需要创建一个Notification
对象。有两种方法可以实现这一点。您可以实例化一个新的Notification
对象,或者从Prowl对象调用它。如果您从Prowl对象调用它,Prowl对象将被发送给它,以便您可以通过链式调用调用send方法。如果愿意,您还可以使用Notification
对象的几个工厂方法。
<?php use Midnite81\Prowl\Services\Notification; $notification = new Notification(); // or $notification = $prowl->createNotification(); // Using this method you can chain through to send the message directly. $prowl = new Prowl($config); $prowl->createMessage() ->setApiKeys($apiKey) ->setDescription('This is the description') ->setEvent('This is the event') ->setPriority(\Midnite81\Prowl\Services\Priority::NORMAL) ->setMessage('This is the message') ->setApplication('Application') ->send();
一旦创建了notification
对象,您就可以调用方法来添加到对象中。例如;
$notification->setApiKeys($myKey) ->setPriority(0) ->setEvent('The Event') ->setDescription('The Description') ->setApplication('The Application') ->setMessage('The Message');
一旦通知有了所有需要的参数,您就可以将其传递给add方法以触发推送通知。
$pushNotification = $prowl->add($notification);
除非抛出任何异常,否则您将收到一个Response
对象。有关响应对象的更多信息,请查看readme-response.md