mapalagama/uaship

Laravel 的 Urban Airship 库

0.6 2017-06-06 12:34 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:20:07 UTC


README

Build Status

Urban Airship library for Laravel 5. UAShip

用法

要求
  • Composer
  • PHP >= 5.6
安装
composer require mapalagama/uaship
导入

use Mapalagama\UAShip\UAShip

初始化

使用您的 App KeyApp Master Secret 初始化 UAShip

$uaShip = new UAShip("**app_key_here**", "**app_master_secret**");

警报

使用 UAShip 类中的 addAlert 方法添加警报

$uaShip->addAlert("This is alert");

通道

使用 addChannel 方法添加通道。参数:

  1. 通道类型
    • UAShip::IOS 用于 iOS 通道
    • UAShip::ANDROID 用于 Android 通道
  2. 通道 ID
$uaShip->addChannel(UAShip::IOS, "**Channel_id_here**");
$uaShip->addChannel(UAShip::ANDROID, "**Channel_id_here**");

额外数据

使用 addExtra 方法添加额外数据。参数:

  1. 额外数据 - 需要通用类或 stdClass。此参数在发送前将被编码为 JSON
$extra = new stdClass();
$extra->question = "what is your name ?";

$uaShip->addExtra($e);

发送消息

使用 send 方法发送通知。

$result = $uaShip->send();

成功消息 $result

{
  "ok": true,
  "operation_id": "**operation_id**",
  "push_ids": [
    "**push_id**"
  ],
  "message_ids": [],
  "content_urls": []
}

错误消息 $result

error 字段包含原因

{
  "ok": false,
  "error": "Unauthorized", 
  "error_code": 40101
}

完整代码

   //initialization
    $uaShip = new UAShip("**APP_KEY**", "**APP_MASTER_SECRET**");
    
    //add alert message
    $uaShip->addAlert("This is alert");

    //add channels
    $uaShip->addChannel(UAShip::IOS, "**CHANNEL_ID**");
    $uaShip->addChannel(UAShip::ANDROID, "**CHANNEL_ID**");

    //add extra
    $extra = new stdClass();
    $extra->question = "what is your name ?";
    $uaShip->addExtra($extra);

    //send
    echo $uaShip->send();
    

下一个版本有什么新功能

  • 使用设备令牌推送
  • 使用标签和设备类型推送
  • 调度
  • 更多...

许可证

UAShip 在 MIT 许可证 下发布。