problematik / php-autoremote
PHP 对 AutoRemote 的封装
Requires
- php: >=5.3.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~3.7
This package is not auto-updated.
Last update: 2024-09-24 02:29:00 UTC
README
PHP-AutoRemote 是 [AutoRemote] 1 的 PHP 封装。它使用方法链来简化设置,并可以设置 [AutoRemoteWebInterface] 2 上列出的所有属性。
安装
要将 PHP-AutoRemote 包含到您的项目中,编辑您的项目的 composer.json
文件,并添加 require "problematik/php-autoremote"
"require": {
"problematik\php-autoremote": "~1.0.2"
}
用法
PHP-AutoRemote 的使用很简单。要向您的设备发送通知,只需执行以下操作
<?php use Problematik\AutoRemote\AutoRemote; use Problematik\AutoRemote\AutoRemoteNotification; $notification = new AutoRemoteNotification(); $notification->title("Hello World!")->text("This will be the notification message!"); $autoremote = new AutoRemote("YOUR_API_KEY"); $autoremote->send($notification);
完成!就是这样!现在您应该在设备上看到通知!您发送了通知但出现错误?那么将抛出 AutoRemoteException
不想链式调用方法,您宁愿将属性数组传递给构造函数?这当然可以...
$notification = new AutoRemoteNotification(array("title" => "title", "text" => "text");
但有时您只是想发送一条 AutoRemote 消息
,可以这样做
<?php use Problematik\AutoRemote\AutoRemote; use Problematik\AutoRemote\AutoRemoteMessage; $message = new AutoRemoteMessage(); $message->message("message"); $autoremote = new AutoRemote("YOUR_API_KEY"); $autoremote->send($notification);
想在通知中添加一个按钮吗?
<?php use Problematik\AutoRemote\AutoRemote; use Problematik\AutoRemote\AutoRemoteIcon; use Problematik\AutoRemote\AutoRemoteNotification; use Problematik\AutoRemote\AutoRemoteNotificationButton; $button = new AutoRemoteNotificationButton("message to send on button click", "Click me", AutoRemoteIcon::ACTION_HELP); $anotherButton = new AutoRemoteNotificationButton("another message", "Edit me!", AutoRemoteIcon::CONTENT_EDIT); $notification = new AutoRemoteNotification(); $notification->title("I've added buttons!")->text("Please click on the button!"); $notification->addButton($button)->addButton($anotherButton); $autoremote = new AutoRemote("YOUR_API_KEY"); $autoremote->send($notification);
我们刚刚使用 AutoRemoteNotificationButton
类添加了一个按钮到通知中,该类接受分别的 message, label, icon
。
对于图标,我们使用了 AutoRemoteIcon
类,该类具有预定义的常量,其中包含您可以在通知中使用的图标,但只要它在 Tasker 下的 AutoRemote 通知动作的按钮图标字段中列出,您就可以使用任何字符串值
$button = new AutoRemoteNotificationButton("message to send on button click", "Click me", "action_help");
请注意,
AutoRemoteIcon
类仅列出在AutoRemoteNotification
apk 下的res/drawable-hdpi
中可找到的图标,因此有些图标可能缺失(但这应该足够了,您有 350 个预定义图标可供选择)
属性
所有属性名称都可以在 [AutoRemoteWebInterface] 2 上找到。名称如下生成
Message
=>message
// (所有都是小写)Target (可选)
=>target
(所有都是不带括号的)Act as Sender (可选)
=>actAsSender
(所有都是驼峰命名法)
但有例外
Message validity time in seconds (可选)
=>messageValidity
Picture URL
=>pictureUrl
Led On ms
=>ledOnMS
Led Off ms
=>ledOffMS
Icon URL
=>iconUrl
一些更多示例
发送带有振动模式的提醒
$notification = new AutoRemoteNotification(); $notification->title("title")->text("text"); $notification->vibrationPattern("100,200,100,200");
发送带有 LED 颜色的提醒
$notification = new AutoRemoteNotification(); $notification->title("title")->text("text"); $notification->ledColor("red"); $notification->ledOnMS(200)->ledOffMS(200);
或使用简写方法
$notification->led("red", 200, 200);
发送带有进度条的提醒
$notification = new AutoRemoteNotification(); $notification->title("title")->text("text"); $notification->notificationId("my-id"); $notification->maxProgress(100); $notification->currentProgress(30);