定制 pmzedx/steam-service 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pmzedx/steam-service

Composer 安装命令:

composer require pmzedx/steam-service

包简介

A clean PHP wrapper for the Steam Web API using Guzzle HTTP.

README 文档

README

A clean, well-documented PHP wrapper for the Steam Web API built on top of Guzzle HTTP.

Installation

composer require pmzedx/steam-service

Getting an API Key

Request a Steam Web API key at: https://steamcommunity.com/dev/apikey

Setup

Option 1 — Environment variable (recommended)

Set STEAM_API_KEY in your .env or server environment:

STEAM_API_KEY=your_key_here

Then create the client with no arguments:

use PmZedx\SteamService\SteamClient;

$steam = new SteamClient();

Option 2 — Pass the key directly

$steam = new SteamClient('your_api_key_here');

Usage

👤 User Profiles — $steam->users()

// Single profile
$data = $steam->users()->getProfiles('76561197960435530');
$player = $data['response']['players'][0];
echo $player['personaname']; // Display name
echo $player['avatarfull'];  // Avatar URL

// Multiple profiles (up to 100)
$data = $steam->users()->getProfiles([
    '76561197960435530',
    '76561197960287930',
]);

// Friend list
$data = $steam->users()->getFriends('76561197960435530');
foreach ($data['friendslist']['friends'] as $friend) {
    echo $friend['steamid'];
}

🎮 Player Games — $steam->player()

// All owned games
$data = $steam->player()->getOwnedGames('76561197960435530');
echo $data['response']['game_count'];

// With options
$data = $steam->player()->getOwnedGames(
    steamId: '76561197960435530',
    includeGameDetails: true,
    includeFreeGames: true,
    filterToAppIds: [440, 730] // Only TF2 and CS2
);

// Recently played (last 2 weeks)
$data = $steam->player()->getRecentlyPlayedGames('76561197960435530', limit: 5);
foreach ($data['response']['games'] as $game) {
    echo $game['name'] . ': ' . $game['playtime_2weeks'] . ' minutes';
}

🏆 Achievements & Stats — $steam->userStats()

// Global achievement unlock rates for a game (no auth needed)
$data = $steam->userStats()->getGlobalAchievementPercentages(440);
foreach ($data['achievementpercentages']['achievements'] as $a) {
    echo $a['name'] . ': ' . $a['percent'] . '%';
}

// A player's achievement status in a game
$data = $steam->userStats()->getPlayerAchievements('76561197960435530', 440, language: 'en');
foreach ($data['playerstats']['achievements'] as $a) {
    echo $a['name'] . ': ' . ($a['achieved'] ? '' : '');
}

// A player's in-game stats
$data = $steam->userStats()->getPlayerStats('76561197960435530', 440);
foreach ($data['playerstats']['stats'] as $stat) {
    echo $stat['name'] . ': ' . $stat['value'];
}

📰 Game News — $steam->news()

$data = $steam->news()->getForGame(appId: 440, count: 5, maxLength: 300);
foreach ($data['appnews']['newsitems'] as $article) {
    echo $article['title'] . "\n" . $article['url'];
}

Error Handling

All methods throw SteamApiException on failure (bad key, rate limit, network error, etc.):

use PmZedx\SteamService\Exceptions\SteamApiException;

try {
    $data = $steam->users()->getProfiles('76561197960435530');
} catch (SteamApiException $e) {
    echo 'Steam API error: ' . $e->getMessage();
}

Package Structure

src/
├── SteamClient.php              ← Main entry point
├── Concerns/
│   └── MakesHttpRequests.php    ← Guzzle HTTP trait (shared by all resources)
├── Exceptions/
│   └── SteamApiException.php    ← Thrown on all API/network errors
└── Resources/
    ├── NewsResource.php         ← ISteamNews
    ├── UserResource.php         ← ISteamUser
    ├── PlayerResource.php       ← IPlayerService
    └── UserStatsResource.php    ← ISteamUserStats

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固