psfd-dev/exponent-server-sdk-php

使用PHP处理Expo推送通知的服务端库

1.2.1 2021-11-08 08:23 UTC

This package is auto-updated.

Last update: 2024-09-08 15:16:18 UTC


README

使用PHP处理Expo推送通知的服务端库

Latest Stable Version License Total Downloads

使用方法

  • 在项目中要求此包
composer require alymosul/exponent-server-sdk-php
  • 在PHP文件中
    require_once __DIR__.'/vendor/autoload.php';
    
    $channelName = 'news';
    $recipient= 'ExponentPushToken[unique]';
    
    // You can quickly bootup an expo instance
    $expo = \ExponentPhpSDK\Expo::normalSetup();
    
    // Subscribe the recipient to the server
    $expo->subscribe($channelName, $recipient);
    
    // Build the notification data
    $notification = ['body' => 'Hello World!'];
    
    // Notify an interest with a notification
    $expo->notify([$channelName], $notification);

可以通过提供JSON对象来向通知添加数据。例如

// Build the notification data
$notification = ['body' => 'Hello World!', 'data'=> json_encode(array('someData' => 'goes here'))];

频道名称

您可以使用频道向单个用户或一组用户发送通知

一个接收者

为了针对单个接收者(并避免向错误的接收者发送通知),请使用针对每个用户特定的频道名称

$channelName = 'user_528491';
$recipient = 'ExponentPushToken[unique]';

// …

// Subscribe the recipient to the server
$expo->subscribe($channelName, $recipient);

// …

// Notify an interest with a notification, only one recipient will receive it
$expo->notify([$channelName], $notification);

多个接收者

声明一个将在接收者之间共享的频道名称

$channelName = 'group_4815';

$recipient1 = 'ExponentPushToken[unique1]';
$recipient2 = 'ExponentPushToken[unique2]';

// …

// Subscribe the recipients to the server
$expo->subscribe($channelName, $recipient1);
$expo->subscribe($channelName, $recipient2);

// …

// Notify an interest with a notification, the 2 recipients will receive it
$expo->notify([$channelName], $notification);
// Build the notification data
$notification = ['body' => 'Hello World!', 'data'=> json_encode(array('someData' => 'goes here'))];

待办事项

  • 需要创建测试

Laravel驱动程序

  • 有一个为Laravel应用程序构建的Expo通知驱动程序,可以直接使用,您可以在以下位置找到它:[链接](https://github.com/Alymosul/laravel-exponent-push-notifications)