donatj / pushover
简单的 Pushover.net 客户端
v3.1.0
2024-02-05 03:38 UTC
Requires
- php: >=7.3
- ext-json: *
Requires (Dev)
- corpus/coding-standard: ^0.6.0
- donatj/drop: ^1.1
- donatj/mock-webserver: ^2.6
- friendsofphp/php-cs-fixer: ^3.4
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-09-05 05:00:45 UTC
README
Pushover PHP 是为 PHP 编写的 Pushover API 的一个非常轻量级的简单 API 封装。
需求
- php: >=7.3
- ext-json: *
安装
使用以下命令安装最新版本
composer require 'donatj/pushover'
用法
<?php require __DIR__ . '/../vendor/autoload.php'; use donatj\Pushover\Exceptions\ResponseException; use donatj\Pushover\Options; use donatj\Pushover\Priority; use donatj\Pushover\Pushover; use donatj\Pushover\Sounds; $po = new Pushover('{my_apikey}', '{my_userkey}'); try { // Simplest example $po->send('Hello World'); // With Options: $po->send('Awesome website, great job!', [ Options::TITLE => 'New Comment!', Options::URL => 'https://donatstudios.com/CsvToMarkdownTable', Options::PRIORITY => Priority::HIGH, Options::SOUND => Sounds::ALIEN, ]); }catch( ResponseException $e ) { // Handle exception }
文档
有关协议特定的文档,请参阅官方的 Pushover API 文档。
在 成功 的情况下,Pushover->send
返回一个类似 truth-y 的数组
[ 'status' => '1', 'request' => '2f4e9c7140df52d7d8b16ffb8adf1c2a', ]
在 失败 的情况下,Pushover->send
返回 false,这允许简单的
if( !$po->send('Hello World!') ) { die('oh no!'); }
类: \donatj\Pushover\Exceptions\ResponseException
<?php namespace donatj\Pushover\Exceptions; class ResponseException { public const ERROR_CONNECTION_FAILED = 100; public const ERROR_DECODE_FAILED = 200; public const ERROR_UNEXPECTED = 300; public const ERROR_API = 400; }
类: \donatj\Pushover\Options
包含 Pushover API 的可用选项键
<?php namespace donatj\Pushover; class Options { /** * The Application API token. * * Defaults to the token \donatj\Pushover\Pushover was constructed with. */ public const TOKEN = 'token'; /** * The User Key. * * Defaults to the user key \donatj\Pushover\Pushover was constructed with. */ public const USER = 'user'; /** To enable HTML formatting, include HTML parameter set to 1. May not be used if monospace is used. */ public const HTML = 'html'; /** To enable Monospace formatting, include HTML parameter set to 1. May not be used if html is used. */ public const MONOSPACE = 'monospace'; /** * The optional devices name for the message to be pushed to. * * If unspecified, your message will be pushed to all devices. */ public const DEVICE = 'device'; /** The optional message title */ public const TITLE = 'title'; /** The optional message url */ public const URL = 'url'; /** The optional message url title. Must specify a URL as well. */ public const URL_TITLE = 'url_title'; /** The priority of the message being sent. */ public const PRIORITY = 'priority'; /** An optional UNIX timestamp for your message. Otherwise the current time is used. */ public const TIMESTAMP = 'timestamp'; /** The sound to play on receiving the pushover message. */ public const SOUND = 'sound'; /** A number of seconds that the message will live, before being deleted automatically */ public const TTL = 'ttl'; }
类: \donatj\Pushover\Priority
包含 'priority' 的所有合法值
<?php namespace donatj\Pushover; class Priority { public const LOWEST = -2; public const LOW = -1; public const NORMAL = 0; public const HIGH = 1; public const EMERGENCY = 2; }
类: \donatj\Pushover\Pushover
Pushover 消息的简单 API 接口
<?php namespace donatj\Pushover; class Pushover { public const API_URL = 'https://api.pushover.net/1/messages.json'; }
方法: Pushover->__construct
function __construct(string $token, string $user [, string $apiUrl = self::API_URL])
创建一个 Pushover 对象
参数
- 字符串
$token
- 应用程序的 API 令牌 - 字符串
$user
- 您的用户密钥 - 字符串
$apiUrl
- 可选地更改 API URL
方法: Pushover->send
function send(string $message [, array $options = []]) : array
发送 Pushover 消息
参数
- 字符串
$message
- 要发送的消息 - 数组<字符串,混合>
$options
- 可选的配置设置
抛出: \donatj\Pushover\Exceptions\ResponseException
- 在连接失败或解码响应失败时
返回
- 数组 - 解码后的 JSON 响应作为关联数组
类: \donatj\Pushover\Sounds
包含 'sound' 的合法值
<?php namespace donatj\Pushover; class Sounds { /** Pushover (default) */ public const PUSHOVER = 'pushover'; /** Bike */ public const BIKE = 'bike'; /** Bugle */ public const BUGLE = 'bugle'; /** Cash Register */ public const CASH_REGISTER = 'cashregister'; /** Classical */ public const CLASSICAL = 'classical'; /** Cosmic */ public const COSMIC = 'cosmic'; /** Falling */ public const FALLING = 'falling'; /** Gamelan */ public const GAMELAN = 'gamelan'; /** Incoming */ public const INCOMING = 'incoming'; /** Intermission */ public const INTERMISSION = 'intermission'; /** Magic */ public const MAGIC = 'magic'; /** Mechanical */ public const MECHANICAL = 'mechanical'; /** Piano Bar */ public const PIANO_BAR = 'pianobar'; /** Siren */ public const SIREN = 'siren'; /** Space Alarm */ public const SPACE_ALARM = 'spacealarm'; /** Tug Boat */ public const TUGBOAT = 'tugboat'; /** Alien Alarm (long) */ public const ALIEN = 'alien'; /** Climb (long) */ public const CLIMB = 'climb'; /** Persistent (long) */ public const PERSISTENT = 'persistent'; /** Pushover Echo (long) */ public const PUSHOVER_ECHO = 'echo'; /** Up Down (long) */ public const UP_DOWN = 'updown'; /** Vibrate Only */ public const VIBRATE = 'vibrate'; /** None (silent) */ public const NONE = 'none'; }