定制 triyatna/php-valid-game 二次开发

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

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

triyatna/php-valid-game

Composer 安装命令:

composer require triyatna/php-valid-game

包简介

PHP package for validating game user IDs via Codashop scraping and GoPay Games

README 文档

README

License: MIT

PHP package for validating game user IDs via Codashop scraping and GoPay Games API.

Install

composer require triyatna/php-valid-game

Requires PHP 8.1+ and works with Laravel, CodeIgniter, Symfony, Slim, or plain PHP.

Features

  • Dual Provider — Validates via Codashop initPayment scraping and GoPay Games API
  • Auto Fallback — If the preferred provider fails, automatically tries the next one
  • Nickname Extraction — Returns the player's in-game nickname when available
  • 22 Games Supported — Mobile Legends, Free Fire, Genshin Impact, VALORANT, PUBG Mobile, and more
  • Alias Resolution — Accepts human names, aliases, and canonical codes (ff, ml, mlbb, etc.)
  • Magic Methods — Call any game as a method: $client->freefire('123'), $client->pubg('456')
  • Smart Registry — Search games, filter by provider, register custom games at runtime
  • Laravel Integration — Auto-discovery service provider, facade, and publishable config
  • PSR-3 Logging — Optional debug logging via any PSR-3 compatible logger
  • Proxy Support — Route requests through HTTP proxy

Supported Games

Game Code Zone Required Codashop GoPay Aliases
8 Ball Pool 8ballpool No eightballpool
Aether Gazer aethergazer No
Arena of Valor aov No arenaofvalor
Auto Chess autochess No
Azur Lane azurlane Yes
Badlanders badlanders Yes
BarbarQ barbarq No
Basketrio basketrio Yes
Call of Duty Mobile cod No codm, callofduty
Dragon City dragoncity No
FC Mobile fcmobile No fcm, efootball
Free Fire freefire No ff, garena
Genshin Impact genshinimpact Yes genshin, gi
Hago hago No
Honkai Star Rail honkaistarrail Yes hsr, starrail
Honor of Kings hok No honorofkings
Magic Chess: Go Go magicchessgogo Yes magicchess, mcgg
Mobile Legends mobilelegends Yes ml, mlbb, mobilelegend
Point Blank pb No pointblank
PUBG Mobile pubg No pubgmobile, pubgm, pubgid
VALORANT valorant No val
Zenless Zone Zero zenlesszonezero Yes zzz

Usage

Plain PHP

<?php
require __DIR__ . '/vendor/autoload.php';

use Triyatna\PhpValidGame\ValidGameClient;
use Triyatna\PhpValidGame\Enums\Provider;

// Default: Codashop first, GoPay Games as fallback
$client = new ValidGameClient();

// Free Fire (no zone required)
$result = $client->freefire('123456789');

// Mobile Legends (zone required)
$result = $client->mobileLegends('123456789', '7890');

// New games (GoPay-only, also work via magic method)
$result = $client->pubg('123456789');
$result = $client->honorOfKings('123456789');
$result = $client->fcMobile('123456789');
$result = $client->magicChessGoGo('123456789', '7890');

// Generic check (accepts aliases)
$result = $client->check('ff', '123456789');
$result = $client->check('Mobile Legends', '123456', '7890');
$result = $client->check('Azur Lane', '12345', 'avrora');

// Force a specific provider
$result = $client->checkWith(Provider::GOPAY_GAMES, 'freefire', '123456789');

// Smart registry queries
$gopayGames = $client->gamesForProvider('gopaygames'); // all GoPay-supported
$matches    = $client->searchGames('mobile');           // fuzzy search

// List all available games (code, label, provider support, aliases, servers)
$allGames = $client->listGames();
foreach ($allGames as $game) {
    echo "{$game['code']} => {$game['label']}";
    echo " | Providers: " . implode(', ', $game['providers']);
    echo " | Zone: " . ($game['requiresZone'] ? 'Yes' : 'No');
    if (!empty($game['aliases'])) {
        echo " | Aliases: " . implode(', ', $game['aliases']);
    }
    if (!empty($game['servers'])) {
        echo " | Servers: " . implode(', ', $game['servers']);
    }
    echo PHP_EOL;
}

// Output
print_r($result->toArray());
echo $result->toJson();
echo $result->isValid() ? 'Valid!' : 'Invalid!';
echo $result->nickname; // Player's nickname

Advanced Options

use Triyatna\PhpValidGame\ValidGameClient;
use Triyatna\PhpValidGame\Enums\Provider;

$client = new ValidGameClient(
    preferredProvider: Provider::GOPAY_GAMES,  // Try GoPay first
    fallback: true,                            // Fall back to Codashop
    proxy: 'http://user:pass@host:port',       // HTTP proxy
    debug: true,                               // Include raw data in meta
    logger: $psrLogger,                        // PSR-3 logger
    timeout: 20,                               // HTTP timeout (seconds)
);

Laravel 11+ (Auto-Discovery)

The service provider and facade are auto-discovered.

Publish config (optional):

php artisan vendor:publish --tag=valid-game-config

Using the Facade:

use Triyatna\PhpValidGame\Laravel\Facades\ValidGame;

// Convenience helpers (magic methods work for any registered game)
$result = ValidGame::freefire('123456789');
$result = ValidGame::mobileLegends('123456', '7890');
$result = ValidGame::genshinImpact('800123456', 'os_asia');
$result = ValidGame::pubg('123456789');
$result = ValidGame::honorOfKings('123456789');

// Generic
$result = ValidGame::check('valorant', '99887766');
$result = ValidGame::check('Azur Lane', '112233', 'amagi');

// Smart queries
$gopayGames = ValidGame::gamesForProvider('gopaygames');
$matches    = ValidGame::searchGames('legend');

// List all games with full details
$allGames = ValidGame::listGames();
// Returns: [['code' => 'freefire', 'label' => 'Free Fire', 'providers' => ['codashop', 'gopaygames'], ...], ...]

return response()->json($result->toArray(), $result->isValid() ? 200 : 422);

Environment variables:

VALID_GAME_PROVIDER=codashop    # codashop or gopaygames
VALID_GAME_FALLBACK=true
VALID_GAME_PROXY=
VALID_GAME_DEBUG=false
VALID_GAME_TIMEOUT=15

CodeIgniter 4

<?php
namespace App\Controllers;

use Triyatna\PhpValidGame\ValidGameClient;

class GameCheck extends BaseController
{
    public function freefire()
    {
        $client = new ValidGameClient();
        $result = $client->freefire($this->request->getGet('uid'));

        return $this->response
            ->setJSON($result->toArray())
            ->setStatusCode($result->isValid() ? 200 : 422);
    }

    public function check()
    {
        $client = new ValidGameClient();
        $result = $client->check(
            $this->request->getGet('game'),
            $this->request->getGet('uid'),
            $this->request->getGet('zone'),
        );

        return $this->response
            ->setJSON($result->toArray())
            ->setStatusCode($result->isValid() ? 200 : 422);
    }
}

Extending the Registry

Register custom games or aliases at runtime:

use Triyatna\PhpValidGame\Registry\GameRegistry;

// Register a new game
GameRegistry::register('mygame', [
    'label'        => 'My Game',
    'requiresZone' => false,
    'gopayCode'    => 'MY_GAME',
    'codashop'     => [
        'typeName' => 'MY_GAME',
        'payload'  => fn($uid, $zone) => [
            'voucherPricePoint.id'    => '999999',
            'voucherPricePoint.price' => '10000.0000',
            'user.userId'             => $uid,
            'voucherTypeName'         => 'MY_GAME',
            'shopLang'                => 'id_ID',
        ],
    ],
    'nicknameFrom' => ['confirmationFields.username'],
]);

// Register an alias
GameRegistry::alias('mg', 'mygame');

Listing All Available Games

Use listGames() to get a structured list of every registered game:

$client = new ValidGameClient();
$games  = $client->listGames();

print_r($games);

Each entry returns:

[
    'code'         => 'freefire',          // Canonical game code
    'label'        => 'Free Fire',         // Human-readable name
    'requiresZone' => false,               // Whether zoneId is mandatory
    'providers'    => ['codashop', 'gopaygames'], // Supported providers
    'aliases'      => ['ff', 'garena'],    // Accepted aliases
    'servers'      => [],                  // Server map keys (if any)
]

For games with server maps (e.g., Azur Lane):

[
    'code'         => 'azurlane',
    'label'        => 'Azur Lane',
    'requiresZone' => true,
    'providers'    => ['codashop'],
    'aliases'      => [],
    'servers'      => ['avrora', 'lexington', 'sandy', 'washington', 'amagi', 'littleenterprise'],
]

Available Methods

Method Returns Description
listGames() array of game details Full structured list of all available games
supportedGames() string[] of codes All canonical game codes
supportedGamesWithLabels() array<code, label> Code → label mapping
gamesForProvider('codashop') string[] of codes Games supporting a specific provider
searchGames('mobile') array<code, label> Fuzzy search by name/alias
check($game, $userId, $zoneId) ValidationResult Validate with auto-provider
checkWith($provider, $game, ...) ValidationResult Validate with a specific provider

Result Format

Every call returns a ValidationResult:

{
  "status": true,
  "message": "User ID is valid.",
  "data": {
    "game": "Free Fire",
    "nickname": "PlayerName",
    "country": ""
  }
}

Error Codes

Code Meaning
OK Validation successful, user ID is valid.
INVALID_INPUT Missing userId, or required zoneId not provided.
UNKNOWN_GAME Game not found in registry.
HTTP_ERROR Transport failure (network/proxy/DNS/timeout).
API_ERROR Provider API returned an error (invalid user ID, etc.).
NON_JSON Response body empty or non-JSON.
UNEXPECTED_FORMAT HTTP non-2xx or malformed success shape.
PROVIDER_ERROR Provider failed or no provider supports the game.
EXCEPTION Unexpected runtime error.

Testing

composer install
vendor/bin/phpunit

License

MIT — see LICENSE for details.

triyatna/php-valid-game 适用场景与选型建议

triyatna/php-valid-game 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 240 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「validation」 「game」 「codashop」 「mobile-legends」 「freefire」 「game-id」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 triyatna/php-valid-game 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 triyatna/php-valid-game 我们能提供哪些服务?
定制开发 / 二次开发

基于 triyatna/php-valid-game 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-15