fireboostio/php-client

此包是fireboostio api的PHP客户端。

v0.0.1 2024-07-04 19:48 UTC

This package is auto-updated.

Last update: 2024-09-08 19:16:36 UTC


README

此PHP客户端允许您与Fireboost API通信。对于登录凭证提取,您可以使用php-encryptor仓库。

安装

您可以通过Composer安装PHP客户端

composer require fireboostio/php-client

用法

身份验证和获取JWT令牌

要身份验证并获取JWT令牌以进行后续通信,请使用以下代码片段

无加密器仓库

use FireboostIO\Api\DefaultApi;
use FireboostIO\Model\LoginInput;

$api = new DefaultApi();
$response = $api->login(new LoginInput([
    'client_id' => 'your_client_id',
    'encrypted_api_key' => 'your_encrypted_api_key'
]));
$jwt = $response->getJwtToken();

有加密器仓库

use FireboostIO\Api\DefaultApi;
use Fireboostio\Encryptor\CredentialExtractor;
use FireboostIO\Model\LoginInput;

$encryptor = new CredentialExtractor();
$loginInputData = $encryptor->getLoginInputData($fireboostioKey);

$api = new DefaultApi();
$response = $api->login(new LoginInput($loginInputData));
$jwt = $response->getJwtToken();

设置JWT令牌以进行安全API调用

一旦您有了JWT令牌,将其设置在客户端配置中,以便进行后续的安全API调用

use FireboostIO\Configuration;

$config = new Configuration();
$config->setAccessToken($jwt);
$config->setApiKeyPrefix('bearer', 'Bearer');

$api = new FireboostIO\Api\DefaultApi(null, $config);

API示例

读取缓存(安全端点)

$response = $api->getCache('cache_key');
var_dump($response->getResult()[0]);

写入缓存(安全端点)

use FireboostIO\Model\SetInput;

$response = $api->setCache(new SetInput([
    'cache_key' => 'test.com/news/post/1234',
    'store_id' => 'test',
    'api_key' => 'test',
    'content' => json_encode(['whatever' => 'you like']),
    'is_public' => true // or false
]));

读取公共缓存(非安全端点)

$response = $api->publicGetCache($clientId, 'cache_key');
var_dump($response->getResult()[0]);

许可证

本项目采用MIT许可证。有关详细信息,请参阅许可证文件。