zerifas/pushover

Pushover 通知

0.0.1 2014-07-03 00:03 UTC

This package is auto-updated.

Last update: 2024-08-29 03:56:20 UTC


README

Pushover 使得您可以在 Android 设备、iPhone、iPad 和桌面电脑上轻松获取实时通知。

这个简单的 PHP 库允许您从 PHP 代码中使用 Pushover。

功能

  • 支持完整的 API 功能集(包括通知优先级)。
  • 仅需要 curl 扩展。
  • 遵循 PSR-2 标准。

要求

  • PHP ~5.3
  • curl 扩展

使用方法

最简单的方法是创建一个连接,并传递通知对象和用户令牌

$pushover = new Zerifas\Pushover\Connection($applicationToken);
$notification = new Zerifas\Pushover\Notification('Hello, world!');
$success = $pushover->notifyUser($notification, $userToken);

如果您只向一个用户发送通知,也可以省略传递给 notifyUser 的用户令牌

$pushover = new Zerifas\Pushover\Connection($applicationToken, $userToken);
$notification = new Zerifas\Pushover\Notification('Hello, world!');
$success = $pushover->notifyUser($notification);

Notification 类支持在 API 中定义的所有选项,并具有流畅的接口。

$pushover = new Zerifas\Pushover\Connection($applicationToken, $userToken);

$notification = new Zerifas\Pushover\Notification('Hello, world!');
$notification->setTitle('Title')
    ->setUrl('http://www.pushover.net/')
    ->setUrlTitle('Pushover')
    ->setPriority(Zerifas\Pushover\Notification::PRIORITY_QUIET)
    ->setTimestamp(time())
    ->setSound('cosmic')
;
$success = $pushover->notifyUser($notification);

如果需要,您还可以获取状态码和响应作为数组

$pushover = new Zerifas\Pushover\Connection($applicationToken, $userToken);
$notification = new Zerifas\Pushover\Notification('Hello, world!');
$success = $pushover->notifyUser($notification);
$statusCode = $pushover->getLastStatusCode();
$response = $pushover->getLastResponse();
$requestId = $response['request'];
$errors = $response['errors'];