acurrieclark/ionic-php-pusher

此包已被放弃,不再维护。作者建议使用 onsetsoftware/sns-push 包。

Ionic Push API 的 PHP SDK 测试版

v0.1 2016-04-03 23:42 UTC

This package is auto-updated.

Last update: 2020-04-19 14:48:51 UTC


README

此包是一个基本的 PHP SDK,用于协助使用 Ionic Push API 发送推送通知。

安装

$ composer require acurrieclark/ionic-php-pusher

使用方法

// include autoloader if you haven't already
include_once('vendor/autoload.php');

use acurrieclark\IonicPhpPusher\Pusher;
use acurrieclark\IonicPhpPusher\PusherData;

// create an instance
$pusher = new Pusher(API_JWT_TOKEN);

// set an array of device tokens to push to. Can be a mix of Android and iOS devices
$device_tokens = ["android_token", "ios_token"];

// set which Ionic push profile you are using
$profile = IONIC_PUSH_PROFILE_NAME;

// the PusherData helper class provides a blank object to populate with notification data
// it is provided for convenience. Feel free to create your own object here
$notification = new PusherData();


$notification->title = "Message Title";
$notification->message = "Message Body";
$notification->ios->sound = "Default.caf";
$notification->ios->badge = 2;
$notification->android->title = "Android Title";
$notification->android->message = "Android Message";
$notification->android->data->style = 'inbox';
$notification->android->data->summaryText = "There are %n% updates";
$notification->android->sound = "default_alert";

try {

  // API endpoint to check you are using a valid token. This is not necessary before pushing
  $pusher->testApiAccess();

  // send your notification and output its response
  $response = $pusher->sendToTokens($tokens, $profile, $notification);
  print_r($response);

} catch (PusherException $e) {
  // any exceptions can be caught and handled here
  echo $e->getType().' - '.$e->getCode() .": ".$e->getMessage() . "\n";

  if ($e->hasResponse()) {
    print_r($e->getResponse());
  }
  else echo "No response\n";
}

许可

MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。

感谢

基于 Vladimir Dmitrovskiy 为 Ionic Alpha API 所做的工作。