fortnite-api/php-wrapper

此包已弃用且不再维护。未建议替代包。

PHP 对 https://fortnite-api.com 的封装

v1.0.0 2019-12-18 08:36 UTC

This package is not auto-updated.

Last update: 2024-04-18 04:36:27 UTC


README

GitHub release (latest by date) Packagist GitHub issues MIT License

PHP version Guzzle HTTP Donate Discord

此库为 fortnite-api.com 的端点提供了完整的封装。

所有类和 JSON 对象都有良好的文档支持,并为每个对象和属性提供自动完成和类型提示。

我们还为每个端点提供了异步请求!

Composer

composer require fortnite-api/php-wrapper

文档

以下是 API 的快速概述,让您可以快速开始。

如果您需要一个使用示例,请查看我的测试文件夹中的 index.php,我在其中使用了一些端点。

  • 通用用法
use FortniteApi\FortniteApi;

require_once __DIR__ . '/../vendor/autoload.php';

$api = new FortniteApi();
  • FortniteApi 类
$api = new FortniteApi();

// accesses the cosmetics endpoint (https://fortnite-api.com/cosmetics)
$api->cosmetics->...

// accesses the news endpoint (https://fortnite-api.com/news)
$api->news->...

// accesses the shop endpoint (https://fortnite-api.com/shop)
$api->shop->...

// accesses the creatorcode endpoint (https://fortnite-api.com/creatorcode)
$api->creatorCode->...
// returns the base uri of the api (https://fortnite-api.com)
FortniteApi::getBaseUri();

// returns an array of all supported languages
FortniteApi::getSupportedLanguages();
  • FortniteApiError
$result = $api->cosmetics->getAll();

if ($result === null)
{
    $lastError = FortniteApiError::getLastError();

    // this just shows which members you can access
    $members = [
        $lastError->statusCode,
        $lastError->reasonPhrase,
        $lastError->body,
        $lastError->message
    ];
}
// Returns the error set by the last request or false if none is set.
FortniteApiError::getLastError();

// Determines whether an error occured within the last called function.
FortniteApiError::hasLastError();
  • 异步方法

端点中的每个方法都有一个等效的异步方法(例如 getAsync),它返回一个可等待的任务。您可以在脚本中的任何位置等待响应。

// returns "instantly"
$task = $api->cosmetics->getAllAsync();
// retreives the result (the one you get from non-async versions)
$result = $task->await();
  • 端点

端点中的每个方法在失败时返回 null。每个对象都提供自动完成和类型提示。

对象与 fortnite-api.com/documentation 上的布局完全相同,但没有它们的 status 和 data 属性,这些属性已经为您进行了验证。

如果您需要有关属性和方法的信息,请查看实际实现。

端点

JSON 对象

  • 查询参数

某些方法需要 $query 参数才能工作。您可以在 官方文档 中找到可能的查询参数。此类查询 array 的示例

// key value pairs also support arrays as value if the api allows this
$query = [
    "rarity" => "uncommon",
    "hasIcon" => true
];

贡献

如果您能提供任何帮助,即使是拼写检查,请贡献!

我们欢迎任何贡献。

许可证

API 由 Fortnite-API.com 开发