shamota/dotapi2

PHP DotA 2 API 客户端

1.0.5 2017-06-29 18:02 UTC

This package is not auto-updated.

Last update: 2024-09-21 01:02:22 UTC


README

Build Status Dependency Status Test Coverage Code Climate SensioLabsInsight

PHP 的 Dota 2 API 包装器

参考

安装

此模块可以使用Composer安装。将 dotapi2 包添加到您的 composer.json 文件中。

{
    "require": {
        "shamota/dotapi2": "~1.0"
    }
}

您还需要一个 Steam API 密钥,您可以在http://steamcommunity.com/dev/apikey处获取一个。

配置

// Set your Steam API key
Client::setDefaultKey('your_api_key_here');

// Create wrapper
$client = new Client();

支持端点

getMatchHistory

获取过滤后的比赛历史记录

$filter = new Filters\Match();
$filter->setGameMode(GameModes::CAPTAINS__MODE);
$filter->setMinimumPlayers(10);
$filter->setAccountId(22785577);

// Returns a Response object that contains the raw body and JSON data.
$response = $client->getMatchHistory($filter);

// Turns response into a Match collection
$matchCollection = $response->getCollection('Match');

// Loops through all the found matches and dispays the start time.
foreach ($matchCollection as $match) {
    echo $match->getStartTime()->format('d-m-Y H:i:s') . PHP_EOL;
}

getMatchHistoryBySequenceNumber

按序列号顺序获取比赛列表

// Returns a Response object that contains the raw body and JSON data.
$response = $client->getMatchHistoryBySequenceNumber(new Filters\MatchSequence(2040184605, 10));

// Turns response into a Match collection
$matchCollection = $response->getCollection('Match');

// Loops through all the found matches and dispays the start time.
foreach ($matchCollection as $match) {
    echo $match->getStartTime()->format('d-m-Y H:i:s') . PHP_EOL;
}

getMatchDetails

获取特定比赛的高级信息

// Returns a Response object that contains the raw body and JSON data.
$response = $client->getMatchDetails(new Filters\MatchDetails(2197925777));

// Turns response into a DetailedMatch collection
$match = $response->getEntity('DetailedMatch');

// Get Dire players
$direPlayers = $match->getPlayers()->getDire();

// Get a specific player
$specificPlayer = $match->getPlayers()->getById(22785577);
$specificPlayerHero = $specificPlayer->getHeroId();
$specificPlayerKills = $specificPlayer->getKills();

// Get Picks and Bans sequence if matchtype has picks and bans
$pickBanSequence = $match->getPicksBans();

getLeagueListing

获取 DotaTV 支持的联赛信息

$response = $client->getLeagueListing();

getLiveLeagueGames

获取正在进行的联赛比赛列表,以及比赛的详细信息

$response = $client->getLiveLeagueGames();

getScheduledLeagueGames

获取即将举行的联赛比赛列表

$response = $client->getScheduledLeagueGames();

getFantasyPlayerStats

获取梦幻玩家统计数据

// Puppey (87278757) in The Shanghai Major (4266)
$response = $client->getFantasyPlayerStats(new Filters\FantasyPlayerStats(4266, 87278757));

getPlayerOfficialInfo

获取官方玩家信息

// Puppey (87278757)
$response = $client->getPlayerOfficialInfo(new Filters\AccountId(87278757));

getBroadcasterInfo

使用 64 位 Steam ID 获取广播器信息。如果您需要转换,请查看Steam ID 转换

// Requires the 64-bit Steam ID of a broadcaster.
$response = $client->getBroadcasterInfo(new Filters\BroadcasterInfo(76561197997412731));

getActiveTournamentList

获取活动锦标赛列表

$response = $client->getActiveTournamentList();

getTeamInfo

获取团队信息

// Get team info for Team Secret (1838315). Filter is optional.
$response = $client->getTeamInfo(new Filters\TeamInfo(1838315));

getTopLiveGame

获取顶级直播游戏

$response = $client->getTopLiveGame(new Filters\TopLiveGame(0));

getEventStatsForAccount

检索账户的事件统计数据

// Get stats for account 22785577 at The Shanghai Major (4266)
$response = $client->getEventStatsForAccount(new Filters\EventStats(4266, 22785577));

getRealTimeStats

通过服务器 Steam ID 检索关于比赛的实时统计数据。您需要 Steam 服务器 ID 来获取统计数据,顶级直播游戏和某些其他锦标赛端点为比赛提供这些信息。

$response = $client->getRealTimeStats(new Filters\RealTimeStats(steam_server_id_here));

getGameItems

获取 Dota2 游戏内物品列表

$response = $client->getGameItems();

getItemIconPath

获取特定图标的 CDN 路径

$response = $client->getItemIconPath(new Filters\ItemIconPath('enchanted_manglewood_staff', IconType::LARGE));

getSchemaUrl

获取 Dota 2 最新架构的 URL

$response = $client->getSchemaUrl();

getHeroes

获取英雄列表

$response = $client->getHeroes();

getRarities

获取物品稀有度列表

$response = $client->getRarities();

getTournamentPrizePool

获取特定锦标赛的当前奖金池

$response = $client->getTournamentPrizePool();

自定义端点

您还可以联系 Steam API 上的自定义端点

$response = $client->get('IEconDOTA2_570/GetGameItems/v1', array|Filters\Filter $parameters);

Steam ID 转换

如果您已安装GMP 扩展,Dotapi2 允许您在 32 位和 64 位 ID 之间进行转换。

转换 32 位 ID

$steamId = UserId::to64Bit('22785577'); // 76561197983051305

转换 64 位 ID

$accountId = UserId::to32Bit('76561197983051305'); // 22785577