tomloprod/ionic-push-php
Composer 安装命令:
composer require tomloprod/ionic-push-php
包简介
ionic-push-php is a library that allows you to consume the Ionic Cloud API for sending push notifications (normal and scheduled), get a paginated list of sending push notifications, get information of registered devices, remove registered devices by token, ...
关键字:
README 文档
README
ionic-push-php is a library that allows you to consume the Ionic Cloud API for sending push notifications (normal and scheduled), get a paginated list of sending push notifications, get information of registered devices, remove registered devices by token, ...
Ionic official documentation: Ionic HTTP API - Push.
Requirements:
- PHP 5.1+
- cURL
Installation:
composer require tomloprod/ionic-push-php
Configuration:
First, make sure you have your $ionicAPIToken and your $ionicProfile:
- (string) $ionicAPIToken: The API token that you must create in Settings › API Keys in the Dashboard.
- (string) $ionicProfile: The Security Profile tag found in Settings › Certificates in the Dashboard
More information here.
If you don't know how to configure your ionic app, you can take a look here: Setup Ionic Push
Exceptions
This library could throw:
- RequestException
echo $e; echo $e->prettify(); echo $e->getCode(); echo $e->getMessage(); echo $e->getType(); echo $e->getLink();
How to use:
First, instance an object as follow:
use Tomloprod\IonicApi\Push, Tomloprod\IonicApi\Exception\RequestException; $ionicPushApi = new Push($ionicProfile, $ionicAPIToken);
Then you can interact (list, remove, create, ...) with device tokens, messages and notifications.
Remember that all the interactions returns an ApiResponse object instance, except notifications->deleteAll that returns an array of ApiResponses.
[Device Tokens]
1) List tokens:
try { $response = $ionicPushApi->deviceTokens->paginatedList([ // Determines whether to include invalidated tokens (boolean) 'show_invalid' => 1, // Only display tokens associated with the User ID (string) 'user_id' => $desiredUserId, // Sets the number of items to return per page (integer) 'page_size' => 4, // Sets the page number (integer) 'page' => 1 ]); foreach($response->data as $deviceToken){ print_r($deviceToken); } } catch(RequestException $e) { echo $e; }
2) List users associated with a device token:
try { $response = $ionicPushApi->deviceTokens->listAssociatedUsers($desiredDeviceToken, [ // Sets the number of items to return per page (integer) 'page_size' => 1, // Sets the page number (integer) 'page' => 1, ]); // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
3) Associate a user with a device token:
try { $deviceToken = "c686..."; $userId = "a99ee..."; $ionicPushApi->deviceTokens->associateUser($deviceToken, $userId); // The user has been associated. } catch(RequestException $e) { echo $e; }
4) Dissociate a user with a device token:
try { $deviceToken = "c686..."; $userId = "a99ee..."; $ionicPushApi->deviceTokens->dissociateUser($deviceToken, $userId); // The user has been dissociated. } catch(RequestException $e) { echo $e; }
5) Create device token that was previously generated by a device platform:
try { $response = $ionicPushApi->deviceTokens->create([ // Device token (string) 'token' => $newToken, // User ID. Associate the token with the User (string) 'user_id' => $uuid ]); // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
6) Retrieve device information related to the device token:
try { $response = $ionicPushApi->deviceTokens->retrieve($desiredDeviceToken); // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
5) Update an specific token:
try { $isValid = true; // Determines whether the device token is valid (boolean) $ionicPushApi->deviceTokens->update($desiredDeviceToken, ['valid' => $isValid]); // The device token has been updated. } catch(RequestException $e) { echo $e; }
6) Delete a device related to the device token:
try { $ionicPushApi->deviceTokens->delete($desiredDeviceToken); // The device token has been deleted. } catch(RequestException $e) { echo $e; }
[Messages]
1) Retrieve specific message:
try { $response = $ionicPushApi->messages->retrieve($desiredMessageId); // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
2) Delete a message:
try { $ionicPushApi->messages->delete($desiredMessageId); // The message has been deleted. } catch(RequestException $e) { echo $e; }
[Notifications]
1) List notifications:
try { $response = $ionicPushApi->notifications->paginatedList([ // Sets the number of items to return per page (integer) 'page_size' => 1, // Sets the page number (integer) 'page' => 1, // You can also pass other fields like "message_total" or "overview" (string[]) 'fields' => [ // Total number of messages tied to each notification. 'message_total', // Get an overview of messages delivered and failed for each notification. 'overview' ] ]); // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
2) Retrieve specific notification:
try { $response = $ionicPushApi->notifications->retrieve($desiredNotificationId); // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
3) Delete a notification:
try { $ionicPushApi->notifications->delete($desiredNotificationId); // Notification has been deleted. } catch(RequestException $e) { echo $e; }
4) Delete all notifications:
try { ? $responses = $ionicPushApi->notifications->deleteAll(); // Notifications have been deleted. } catch(RequestException $e) { echo $e; }
5) List messages of a notification:
try { $response = $ionicPushApi->notifications->listMessages($desiredNotificationId, [ // Sets the number of items to return per page (integer) 'page_size' => 1, // Sets the page number (integer) 'page' => 1 ]) // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
6) Send notifications:
/** * ANDROID [OPTIONAL] CONFIG PARAMETERS */ // Filename of the Icon to display with the notification (string) $icon = "icon"; // Filename or URI of an image file to display with the notification (string) $image = "image"; // Indicates whether each notification message results in a new entry on the notification center on Android. // If not set, each request creates a new notification. // If set, and a notification with the same tag is already being shown, the new notification replaces the existing one in notification center. $tag = "yourTagIfYouNeedIt"; // When this parameter is set to true, it indicates that the message should not be sent until the device becomes active. (boolean) $delayWhileIdle = false; // Identifies a group of messages that can be collapsed, so that only the last message gets sent when delivery can be resumed. (string) $collapseKey = "group1"; /** * IOS [OPTIONAL] CONFIG PARAMETERS */ // Message Priority. A value of 10 will cause APNS to attempt immediate delivery. // A value of 5 will attempt a delivery which is convenient for battery life. (integer) $priority = 10; // The number to display as the badge of the app icon (integer) $badge = 1; // Alert Title, only applicable for iWatch devices $iWatchTitle = "Hi!"; // Assign the previously defined configuration parameters to each platform, as well as the title and message: $notificationConfig = [ 'title' => 'Your notification title', 'message' => 'Your notification message. Bla, bla, bla, bla.', 'android' => [ 'tag' => $tag, 'icon' => $icon, 'image' => $image, 'delay_while_idle' => $delayWhileIdle, 'collapse_key' => $collapseKey ], 'ios' => [ 'priority' => $priority, 'badge' => $badge, 'title' => $iWatchTitle ] ]; // [OPTIONAL] You can also pass custom data to the notification. Default => [] $notificationPayload = [ 'myCustomField' => 'This is the content of my customField', 'anotherCustomField' => 'More custom content' ]; // [OPTIONAL] And define, if you need it, a silent notification. Default => false $silent = true; // [OPTIONAL] Or/and even a scheduled notification for an indicated datetime. Default => '' $scheduled = '2016-12-10 10:30:10'; // [OPTIONAL] Filename of audio file to play when a notification is received. Setting this to default will use the default device notification sound. Default => 'default' $sound = 'default'; // Configure notification: $ionicPushApi->notifications->setConfig($notificationConfig, $notificationPayload, $silent, $scheduled, $sound); try { // Send notification... $response = $ionicPushApi->notifications->sendNotificationToAll(); // ...to all registered devices // or $response = $ionicPushApi->notifications->sendNotification([$desiredToken1, $desiredToken2, $desiredToken3]); // ...to some devices // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
7) Replace existing notification with new config:
// Identifier of the notification we want to replace. $notificationToReplace = "a86feewx..."; /** * ANDROID [OPTIONAL] CONFIG PARAMETERS */ // Filename of the Icon to display with the new notification (string) $icon = "icon"; // Filename or URI of an image file to display with the new notification (string) $image = "image"; // Indicates whether each notification message results in a new entry on the notification center on Android. // If not set, each request creates a new notification. // If set, and a notification with the same tag is already being shown, the new notification replaces the existing one in notification center. $tag = "yourTagIfYouNeedIt"; // When this parameter is set to true, it indicates that the message should not be sent until the device becomes active. (boolean) $delayWhileIdle = false; // Identifies a group of messages that can be collapsed, so that only the last message gets sent when delivery can be resumed. (string) $collapseKey = "group1"; /** * IOS [OPTIONAL] CONFIG PARAMETERS */ // Message Priority. A value of 10 will cause APNS to attempt immediate delivery. // A value of 5 will attempt a delivery which is convenient for battery life. (integer) $priority = 10; // The number to display as the badge of the app icon (integer) $badge = 1; // Alert Title, only applicable for iWatch devices $iWatchTitle = "Hi!"; // Assign the previously defined configuration parameters to each platform, as well as the title and message: $notificationConfig = [ 'title' => 'Your notification title', 'message' => 'Your notification message. Bla, bla, bla, bla.', 'android' => [ 'tag' => $tag, 'icon' => $icon, 'image' => $image, 'delay_while_idle' => $delayWhileIdle, 'collapse_key' => $collapseKey ], 'ios' => [ 'priority' => $priority, 'badge' => $badge, 'title' => $iWatchTitle ] ]; // [OPTIONAL] You can also pass custom data to the new notification. Default => [] $notificationPayload = [ 'myCustomField' => 'This is the content of my customField', 'anotherCustomField' => 'More custom content' ]; // [OPTIONAL] And define, if you need it, a silent notification. Default => false $silent = true; // [OPTIONAL] Or/and even a scheduled notification for an indicated datetime. Default => '' $scheduled = '2016-12-10 10:30:10'; // [OPTIONAL] Filename of audio file to play when a notification is received. Setting this to default will use the default device notification sound. Default => 'default' $sound = 'default'; // Configure new notification: $ionicPushApi->notifications->setConfig($notificationConfig, $notificationPayload, $silent, $scheduled, $sound); try { // Replace notification with new configuration $response = $ionicPushApi->notifications->replace($notificationToReplace); // Do what you want with $response->data } catch(RequestException $e) { echo $e; }
Contributing:
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -m 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
tomloprod/ionic-push-php 适用场景与选型建议
tomloprod/ionic-push-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.34k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2016 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「notifications」 「push」 「ionic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomloprod/ionic-push-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomloprod/ionic-push-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomloprod/ionic-push-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
A PSR-7 compatible library for making CRUD API endpoints
Captures outgoing SMS notifications
Alfabank REST API integration
Laravel package to send notifications when some exceptions are thrown.
Sms.ru Notification Channel for laravel.
统计信息
- 总下载量: 6.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-10