定制 ucubix/laravel-client 二次开发

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

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

ucubix/laravel-client

Composer 安装命令:

composer require ucubix/laravel-client

包简介

Laravel wrapper for the UCubix Distribution API PHP Client

README 文档

README

Laravel wrapper for the UCubix PHP Client — provides a service provider, facade, and config file for seamless Laravel integration. No duplicated business logic.

Requirements

  • PHP 8.2+
  • Laravel 10, 11, 12, or 13

Installation

composer require ucubix/laravel-client

The service provider and facade are auto-discovered. No manual registration needed.

Configuration

Publish the config file:

php artisan vendor:publish --tag=ucubix-config

This creates config/ucubix.php. All settings are configurable via environment variables:

UCUBIX_API_KEY=your-api-key
UCUBIX_BASE_URL=https://ucubix.com/api/v1/
UCUBIX_MAX_RETRY=3
Key Env Variable Default Description
api_key UCUBIX_API_KEY '' Bearer token for API authentication
base_url UCUBIX_BASE_URL https://ucubix.com/api/v1/ API base URL
max_retry_on_rate_limit UCUBIX_MAX_RETRY 3 Max retries on 429 responses

Quick Start

use Ucubix\LaravelClient\Facades\Ucubix;

// Get organisation info
$org = Ucubix::getOrganisation();
echo $org->name;

// Search products
$products = Ucubix::getProducts(['search' => 'Cyberpunk']);
foreach ($products->data as $product) {
    echo "{$product->name} ({$product->type})\n";
}

// Get single product with pricing
$product = Ucubix::getProduct('product-uuid');
foreach ($product->regional_pricing as $region) {
    echo "{$region->region_code}: {$region->reseller_wsp} WSP\n";
}

// Create order
$order = Ucubix::createOrder('product-uuid', 1, 'EU', 'DE');
echo "Order {$order->code}{$order->status}\n";

// Get license keys
$items = Ucubix::getOrderItems($order->id);
foreach ($items->data as $item) {
    if ($item->hasLicenseKey()) {
        $key = Ucubix::getLicenseKey($item->license_key_uuid);
        echo "Key: {$key->license_key}\n";
    }
}

Dependency Injection

use Ucubix\PhpClient\Client\UcubixClient;

class ProductController extends Controller
{
    public function index(UcubixClient $client)
    {
        $products = $client->getProducts(page: 1, perPage: 50);
        
        return response()->json($products->toArray());
    }
}

The UcubixClient is registered as a singleton — the same instance is reused across the request lifecycle.

Facade Reference

The Ucubix facade proxies all methods directly to UcubixClient. All DTOs extend Spatie\LaravelData\Data and support toArray(), toJson(), etc.

Organisation

Method Returns
Ucubix::getOrganisation() Organisation

Products

Method Returns
Ucubix::getProducts(filters, page, perPage, sort) PaginatedResponse<Product>
Ucubix::getProduct(id) Product
Ucubix::getProductPhotos(id, page, perPage) PaginatedResponse<Media>
Ucubix::getProductScreenshots(id, page, perPage) PaginatedResponse<Media>
Ucubix::getProductCategories(id, page, perPage) PaginatedResponse<Category>
Ucubix::getProductPublishers(id, page, perPage) PaginatedResponse<Publisher>
Ucubix::getProductPlatforms(id, page, perPage) PaginatedResponse<Platform>
Ucubix::getProductFranchises(id, page, perPage) PaginatedResponse<Franchise>
Ucubix::getProductDevelopers(id, page, perPage) PaginatedResponse<Developer>

Product filters: search, category, publisher, developer, franchise, platform

Orders

Method Returns
Ucubix::getOrders(filters, page, perPage, sort) PaginatedResponse<Order>
Ucubix::getOrder(id) Order
Ucubix::getOrderItems(orderId, page, perPage) PaginatedResponse<OrderItem>
Ucubix::createOrder(productUuid, quantity, regionCode, countryCode?) Order
Ucubix::updateOrder(id, quantity) Order
Ucubix::cancelOrder(id) bool

Order filters: code, external_reference

License Keys

Method Returns
Ucubix::getLicenseKey(id) LicenseKey
Ucubix::getBulkLicenseKeys(ids) LicenseKey[]

Catalog Dictionaries

Method Returns
Ucubix::getCategories(page, perPage, sort) PaginatedResponse<Category>
Ucubix::getPublishers(page, perPage, sort) PaginatedResponse<Publisher>
Ucubix::getPlatforms(page, perPage, sort) PaginatedResponse<Platform>
Ucubix::getDevelopers(page, perPage, sort) PaginatedResponse<Developer>
Ucubix::getFranchises(page, perPage, sort) PaginatedResponse<Franchise>

Rate Limiting

Method Returns Description
Ucubix::getRateLimitRemaining() ?int Server-reported remaining requests
Ucubix::getRateLimitLimit() ?int Server-reported limit
Ucubix::setMaxRetryOnRateLimit(max) UcubixClient Set max 429 retries
Ucubix::getMaxRetryOnRateLimit() int Get max 429 retries

Pagination

All list endpoints return PaginatedResponse<T>:

$page = 1;
do {
    $products = Ucubix::getProducts(page: $page, perPage: 50);

    foreach ($products->data as $product) {
        // process
    }

    $page++;
} while ($products->hasMorePages());

Error Handling

All exceptions from ucubix/php-client propagate as-is:

use Ucubix\PhpClient\Exceptions\ApiException;
use Ucubix\PhpClient\Exceptions\AuthenticationException;
use Ucubix\PhpClient\Exceptions\RateLimitException;
use Ucubix\PhpClient\Exceptions\ValidationException;

try {
    $order = Ucubix::createOrder($uuid, 5, 'InvalidRegion');
} catch (AuthenticationException $e) {
    // 401/403 — invalid API key or IP not whitelisted
} catch (ValidationException $e) {
    // 422 — validation failed
    echo $e->field;
} catch (RateLimitException $e) {
    // 429 — all retries exhausted
    echo $e->retryAfter;
} catch (ApiException $e) {
    // All other API errors
    echo $e->errorDetail;
}

Rate Limiting

The underlying PHP client has a dual-layer rate limiting system:

  1. Client-side sliding window — proactive throttling (default: 100 req/min)
  2. Server-side 429 retry — reactive, respects Retry-After header (default: 3 retries)

The UCUBIX_MAX_RETRY config controls the retry count. The sliding window adapts automatically if the server reports a higher limit.

For full rate limiting documentation, see ucubix/php-client.

DTOs

All DTOs are from ucubix/php-client and extend Spatie\LaravelData\Data:

$product = Ucubix::getProduct('uuid');

$product->toArray();  // array
$product->toJson();   // JSON string

// Works seamlessly in responses
return response()->json($product);

For full DTO documentation, see ucubix/php-client DTOs.

Testing

composer install
vendor/bin/phpunit

License

MIT. See LICENSE.

ucubix/laravel-client 适用场景与选型建议

ucubix/laravel-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ucubix/laravel-client 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-09