braze/sdk

使用 Braze API 跟踪用户、发送消息、导出数据等。

2.2.0 2024-07-30 23:48 UTC

README

packagist build test

PHP 库,用于 Braze。代码使用 OpenAPI 规范 生成。

要求

版本

PHP >=8.0

API URL

使用您在仪表板登录时分配给您的账户的 REST 端点

API Key

您可以在 Braze 仪表板中创建 API 密钥

安装

使用 Composer 安装

composer require braze/sdk

使用 Composer 的 自动加载

require_once 'vendor/autoload.php';

使用方法

实例化客户端

use Braze\Braze;

$braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY');

$client = $braze->client;

或创建自定义客户端

use Braze\Client;

$httpClient = \Http\Discovery\Psr18ClientDiscovery::find();
$uri = \Http\Discovery\Psr17FactoryDiscovery::findUriFactory()->createUri('YOUR_API_URL');
$bearer = new \Http\Message\Authentication\Bearer('YOUR_API_KEY');
$plugins = [
    new \Http\Client\Common\Plugin\AddHostPlugin($uri),
    new \Http\Client\Common\Plugin\AuthenticationPlugin($bearer),
];
$httpClient = new \Http\Client\Common\PluginClient($httpClient, $plugins);

$client = Client::create($httpClient);

向用户发送消息

use Braze\Braze;
use Braze\Model\MessagesSendPostBody;

$braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY');

$braze->client->postMessagesSend(new MessagesSendPostBody([
    'external_user_ids' => ['your_external_user_id'],
    'messages' => [
        'email' => [
            'app_id' => 'your_app_id',
            'from' => 'Company <company@example.com>',
            'email_template_id' => 'your_email_template_id',
        ],
    ],
]));

处理 API 错误

use Braze\Braze;

$braze = new Braze('YOUR_API_URL', 'YOUR_API_KEY');

try {
    $braze->client->getCatalog();
} catch (Throwable $exception) {
    echo $exception->getMessage();
    echo $exception->getCode();
}

脚本

composer build

生成代码

composer build

composer clean

删除 lib/ 目录

composer clean

composer test

运行测试

composer test

关于此包

此包由 Jane 自动生成。