syntax/steam-api

Laravel 10+ 的 steam-api 客户端

3.0.0 2024-04-28 00:46 UTC

README

Join the chat at https://gitter.im/syntaxerrors/Steam

Unit Tests Maintainability Latest Stable Version Total Downloads License

版本支持
Laravel >= 10.0
PHP >= 8.1

此包提供了一种从 Steam API 服务获取详细信息的方法。它可以访问的服务包括:

  • ISteamNews
  • IPlayerService
  • ISteamUser
  • ISteamUserStats
  • ISteamApp

安装

首先使用 composer 安装此包。

"require": {
	"syntax/steam-api": "3.*"
}

然后,在终端中更新 composer。

composer update syntax/steam-api

或者,您可以从命令行运行 "composer require syntax/steam-api:dev-master"。

最后,发布配置文件。您可以从 Steam 获取您的 API 密钥。

php artisan vendor:publish --provider="Syntax\SteamApi\SteamApiServiceProvider"

使用

use Syntax\SteamApi\Facades\SteamApi;

/** Get Portal 2 */
$apps = SteamApi::app()->appDetails(620);

echo $app->first()->name;

Steam API 中的每个服务都有自己的方法可供使用。

全局

这些是每个服务可用的方法。

convertId

此功能将给定的 Steam ID 转换为每种类型的 Steam ID(64 位、32 位和 Steam ID3)。

参数

可能的格式为 ID64、id64、64、ID32、id32、32、ID3、id3 和 3。

示例用法
SteamApi::convertId($id, $format);

示例输出: convertId

新闻

用于获取游戏文章的 Steam News 网络API。

SteamApi::news()

GetNewsForApp

此方法将获取给定应用 ID 的新闻文章。它有三个参数。

参数
示例用法
<?php
	$news = SteamApi::news()->GetNewsForApp($appId, 5, 500)->newsitems;
?>

示例输出: GetNewsForApp

玩家

用于获取玩家详细信息的 Player Service。

实例化玩家类时,您需要传递 steamId 或 Steam 社区 ID。

SteamApi::player($steamId)

GetSteamLevel

此方法将返回 Steam 用户的等级。它只返回他们当前等级的整数。

示例输出: GetSteamLevel

GetPlayerLevelDetails

这将返回一个包含玩家等级完整详细信息的 Syntax\Containers\Player_Level 对象。

示例输出: GetPlayerLevelDetails

GetBadges

此调用将为您提供玩家当前拥有的徽章列表。目前没有徽章的架构,所以您将只得到 ID 和详细信息。

示例输出: GetBadges

GetOwnedGames

GetOwnedGames 返回玩家拥有的游戏列表以及一些游戏时间信息,如果配置文件是公开的。私有、仅好友可见和其他隐私设置不支持,除非您要求自己的个人信息(即您使用的 WebAPI 密钥链接到您请求的 steamID)。

参数

示例输出: GetOwnedGames

GetRecentlyPlayedGames

GetRecentlyPlayedGames函数返回玩家在过去两周内玩过的游戏列表,如果个人资料是公开的。不支持私人、仅好友可见和其他隐私设置,除非您请求的是您自己的个人详细信息(即您使用的WebAPI密钥与请求的steamID相关联)。

参数

示例输出:GetRecentlyPlayedGames

IsPlayingSharedGame

如果借用的账户目前正在玩这款游戏,IsPlayingSharedGame返回原始所有者的SteamID。如果游戏未被借用或借用者当前未玩这款游戏,则结果始终为0。

参数

示例输出:IsPlayingSharedGame

用户

用于获取特定用户详情的User WebAPI调用。

在实例化用户类时,您至少需要传递一个steamId或steam社区ID。

SteamApi::user($steamId)

ResolveVanityURL

这将返回用户显示名称的详细信息。

参数
	$player = SteamApi::user($steamId)->ResolveVanityURL('gabelogannewell');

示例输出:ResolveVanityURL

GetPlayerSummaries

这将返回有关一个或多个用户的详细信息。

参数
	// One user
	$steamId = 76561197960287930;
	$player = SteamApi::user($steamId)->GetPlayerSummaries()[0];
	
	// Several users
	$steamIds = [76561197960287930, 76561197968575517]
	$players = SteamApi::user($steamIds)->GetPlayerSummaries();

示例输出:GetPlayerSummaries

GetFriendList

如果Steam用户的Steam社区资料设置为“公开”,则返回任何Steam用户的好友列表。

参数

在收集好友列表后,如果summaries未设置为false,则通过GetPlayerSummaries传递。这允许您获取一组玩家对象。

示例输出:GetFriendList

GetPlayerBans

返回对提供的steam ID(s)可能施加的禁令。

参数

示例输出:GetPlayerBans

用户统计

用于获取用户游戏详情的User Stats WebAPI调用。

在实例化用户统计类时,您需要传递一个steamID或Steam社区ID。

SteamApi::userStats($steamId)

GetPlayerAchievements

通过app ID返回此用户的成就列表。

参数

示例输出:GetPlayerAchievements

GetGlobalAchievementPercentagesForApp

此方法将返回指定游戏的全部成就列表和每个成就被解锁的用户百分比。

参数

示例输出:GetGlobalAchievementPercentagesForApp

GetUserStatsForGame

通过app ID返回此用户的成就列表。

参数

示例输出:GetUserStatsForGame | GetUserStatsForGame (all)

GetSchemaForGame

返回游戏详情列表,包括成就和统计信息。

参数

示例输出:GetSchemaForGame

应用

此区域将获取游戏详情。

SteamApi::app()

appDetails

这获取了关于游戏的全部详情。这是从游戏商店页面获取的大部分信息。

参数

示例输出:appDetails

GetAppList

此方法将直接从Steam返回一个app对象的数组。它包括appID和app名称。

示例输出:GetAppList

此方法将获取包的详细信息。

SteamApi::package()

packageDetails

此方法获取包的所有详细信息。这是从包的商店页面获取的大部分信息。

参数

示例输出: packageDetails

物品

此方法将获取物品的用户库存。

SteamApi::item()

GetPlayerItems

此方法获取用户库存中的所有物品。

参数

⚠️ 当前已知支持: 440, 570, 620, 730, 205790, 221540, 238460

示例输出: GetPlayerItems

此服务用于获取Steam群组的详细信息。

SteamApi::group()

GetGroupSummary

此方法将获取群组的详细信息。

参数
示例用法
<?php
	$news = SteamApi::group()->GetGroupSummary('Valve');
?>

示例输出: GetGroupSummary

测试Steam包

必须提供Steam API密钥,否则大多数测试将失败。

运行测试

# Build container
docker-compose build

# Install dependancies
docker-compose run --rm php composer install

# Run tests (assumes apiKey is set in .env file)
docker-compose run --rm php composer test

# Or with the apiKey inline
docker-compose run --rm -e api=YOUR_STEAM_API_KEY php composer test

# With coverage
docker-compose run --rm php composer coverage

# Play around
docker-compose run --rm php bash

贡献者