sqmk/pushy
Composer 安装命令:
composer require sqmk/pushy
包简介
A PHP client for Pushover.net
README 文档
README
Introduction
Pushy is a PHP client that makes communicating with Pushover.net's API simple.
Pushy makes full use of Pushover's API. This includes sending messages, validating users, and retrieving message statuses.
Interested in sending real-time mobile notifications to your iOS or Android device(s) from your web app? Take a look at Pushover.net. API usage is free, and extremely easy to use with Pushy!
Requirements
- PHP 5.4+
- cURL extension
Installation
You can install Pushy by using composer. Simply add the dependency to your composer.json configuration:
{
"require": {
"sqmk/pushy": "dev-master"
}
}
See composer and packagist for more information.
Usage
Assuming your composer generated or custom autoloader can load Pushy files properly, using it is simple!
For those interested in the complete API, you can check out the auto-generated documentation at GitApiDoc.
Initializing client
In order to send a message, verify a user, or get a message status, you'll first need an application API key. You can get an API key by registering a new application on Pushover.net.
Once you acquire your application key, you can now instantiate a Pushy Client object.
// Instantiate a client object with application key $pushy = new Pushy\Client('KzGDORePK8gMaC0QOYAMyEEuzJnyUi');
Sending messages
You have a client instantiated, now you can send a message. But first, you want to build a user object for the receiving user.
You'll need to get your user identifier (or user key) at Pushover.net. You'll also want a registered device name if you want to send a message to a single device. You can now create a user object with these details.
// Instantiate a user object (targets all devices) $user = new Pushy\User('pQiRzpo4DXghDmr9QzzfQu27cmVRsG'); // Alternatively, instantiate a user object with a targeted device $user = new Pushy\User('pQiRzpo4DXghDmr9QzzfQu27cmVRsG', 'droid2'); // Setting properties by chaining is also possible $user = (new Pushy\User('pQiRzpo4DXghDmr9QzzfQu27cmVRsG')) ->setDeviceName('droid2');
After creating a user, you have enough to start creating a message.
// Instantiate a message object with a message body $message = new Pushy\Message('Your message body'); // Set the recipient of the message $message->setUser($user); // Set the title $message->setTitle('You message title'); // Set a priority (defaults to NormalPriority) $message->setPriority( new Pushy\Priority\LowPriority ); // Set a sound (defaults to PushoverSound) $message->setSound( new Pushy\Sound\AlienSound ); // Set a supplementary URL and title $message->setUrl( 'http://example.org' ); $message->setUrlTitle( 'Example.org' ); // Set a custom sent timestamp $message->setTimestamp(1369111110); // All methods above are chainable $message = (new Pushy\Message) ->setMessage('Your message body') ->setTitle('Your message title') ->setUser($user);
To send the message, pass the message object to the client.
// Send the previous created message $pushy->sendMessage($message);
If no exceptions are thrown, the message was sent successfully. No data is returned by the sendMessage method unless the message has an emergency priority.
Emergency priority messages
You can send a message with an emergency priority and get a receipt id. Emergency priorities also have additional options.
// Create a message with emergency priority $message = (new Pushy\Message) ->setMessage('Important message') ->setTitle('Important subject') ->setUser($user) ->setPriority( (new Pushy\Priority\EmergencyPriority) // Resend message to user every X seconds ->setRetry(30) // Expire message after X seconds ->setExpire(3600) // Set callback URL to hit when user acknowledges message ->setCallback('http://example.org/api') ); // Send message and get receipt id $receiptId = $pushy->sendMessage($message);
With a receipt Id, you can cancel messages with an emergency priority:
$pushy->cancelEmergency($receiptId);
Priorities
The list of available priorities in Pushy\Priority:
- LowestPriority
- LowPriority
- NormalPriority (default)
- HighPriority
- EmergencyPriority
Sounds
The list of available sounds in Pushy\Sound:
- AlienSound
- BikeSound
- BugleSound
- CashregisterSound
- ClassicalSound
- ClimbSound
- CosmicSound
- EchoSound
- FallingSound
- GamelanSound
- IncomingSound
- IntermissionSound
- MagicSound
- MechanicalSound
- NoSound
- PersistentSound
- PianobarSound
- PushoverSound (default)
- SirenSound
- TugboatSound
- UpdownSound
Verifying a user
A user object can be verified with Pushover prior to sending out messages.
// Pass previous instantiated user object to the client try { $pushy->verifyUser($user); echo 'User is valid'; } catch (Pushy\Transport\Exception\ApiException $e) { echo 'User is not valid'; }
Getting message status
When using an emergency priority with a message, you get a receipt code after sending the message successfully. You can get the status of the message by sending the receipt code by way of getMessageStatus.
// Get message with the receipt code $messageStatus = $pushy->getMessageStatus($receiptCode); // Was the message acknowledged? (true or false) $messageStatus->isAcknowledged(); // When the message was acknowledged (DateTime or null) $messageStatus->acknowledgedAt(); // When the message was last delivered (DateTime or null) $messageStatus->lastDeliveredAt(); // Is the message expired? (true or false) $messageStatus->isExpired(); // When the message expired (DateTime or null) $messageStatus->expiresAt(); // Has Pushover contacted the callback URL? (true or false) $messageStatus->hasCalledBack(); // When Pushover contacted the callback URL (DateTime or null) $messageStatus->calledBackAt();
Getting application limitations
Pushover.net allows you to send 7,500 messages per month for each application you own. Sending more than that limit will result in rejected requests from the service.
Pushy provides 3 convenience methods on the client to retrieve your app's message limit, remaining messages, and timestamp for when the limit is reset. These values are available after making any other request to Pushover.
// Call limit for the application per month. $pushy->getAppLimit(); // Calls remaining for the month. $pushy->getAppRemaining(); // Timestamp for when calls remaining is reset to limit. $pushy->getAppReset();
Command-line Interface
Included in Pushy is a convenient script to send messages from the command line.
You can call it like so:
$ bin/pushy --token=yourtokenhere --user-id=useridhere --message="Message here" --title="Title here" --url="http://example.org" --url-title="Example.org" --timestamp=123456 --sound=echo --priority=high
sqmk/pushy 适用场景与选型建议
sqmk/pushy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.47k 次下载、GitHub Stars 达 41, 最近一次更新时间为 2013 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「client」 「pushover」 「pushy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sqmk/pushy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sqmk/pushy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sqmk/pushy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel integration for the Pushy SDK including a notification channel
A Yii2 PushOver log target and pushover messaging component
A PHP package to access the Pushy API by a comprehensive way.
Symfony Pushy Notifier Bridge
First-class Notifications for Craft CMS.
Mock PSR-18 HTTP client
统计信息
- 总下载量: 15.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 22
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-04-03