使用 Composer 安装
用单个命令将 SDK 添加到您的项目。
composer require lix-url/php-sdk
Lix.li URL 缩短 API 官方 PHP SDK。使用干净、定型、不可变 API 客户端创建短链接、管理分组并跟踪点击。
# Install via Composer $ composer require lix-url/php-sdk // Quick start use Lix\Client; $client = new Client('lix_live_xxx'); $link = $client->links()->create('https://example.com'); echo $link->link->shortUrl; // https://lix.li/a3b7k2
为现代 PHP 应用设计,具有定型 DTO、可预测的异常、PSR 兼容 HTTP 客户端和一流的 IDE 支持。
创建、更新、删除和组织短链接,具有定型 DTO 和可预测的 API 响应。
将链接组织成组。创建旋转分组进行网页 A/B 测试。
从您的应用中直接访问帐户信息、API 限制、使用统计和计划详情。
所有响应都是带有定型属性的只读 PHP 类。没有魔法数组 — IDE 自动完成即可用。
6 个专用异常类型用于验证、授权、速率限制、服务器错误和传输故障。
将 Guzzle 替换为任何与 PSR-18 兼容的 HTTP 客户端。为测试和自定义环境提供全面的灵活性。
通过 Composer 安装并在几分钟内开始创建短链接。为 PHP 8.2+ 构建,具有定型 DTO、不可变响应、PSR 兼容 HTTP 客户端和现代开发工作流。
用单个命令将 SDK 添加到您的项目。
composer require lix-url/php-sdk
传入您的 API 密钥。可选注入自定义 PSR-18 HTTP 客户端。
use Lix\Client; $client = new Client('lix_live_xxx');
缩短 URL 并获取带有短链接和使用信息的定型 LinkShortenResult。
$result = $client->links()->create('https://example.com'); echo $result->link->shortUrl; // https://lix.li/a3b7k2 // Links used: 42 / 100 echo $result->usage->used . ' / ' . $result->usage->limit;
使用自定义别名、UTM 参数、跟踪像素、密码、过期规则和组创建、更新和管理短链接。每次操作都返回定型的 DTO。
// Create a basic link $result = $client->links()->create( 'https://example.com' ); // With custom alias and UTM $result = $client->links()->create( url: 'https://example.com', alias: 'summer-sale', utm: [ 'source' => 'newsletter', 'medium' => 'email', 'campaign' => 'summer-sale', ], tags: ['marketing', '2026'], isPublic: true ); // Password protection + expiration $result = $client->links()->create( url: 'https://example.com', password: 'secret123', activeBeforeDatetime: '2026-12-31T23:59:59Z', trackingPixelIds: [1, 2] );
分页示例: $client->links()->list(limit: 100, fromId: 500) 返回从 ID 500 开始的下 100 个链接,其中 ResponseMeta 包含总数和下一个 URL。
按营销活动、产品、团队或项目组织链接。旋转组在多个目标之间分配流量并简化 A/B 测试流程。
// Create a regular group $group = $client->groups()->create( name: 'Marketing' ); echo $group->name; // Create a rotating group for A/B testing $group = $client->groups()->create( name: 'Landing Pages', isRotate: true ); // Update group $group = $client->groups()->update( groupId: 10, description: 'Updated description' ); // List with pagination $response = $client->groups()->list( limit: 10, fromId: 1000 ); foreach ($response->groups as $group) { echo $group->name . PHP_EOL; }
通过单个定型响应访问账户信息、订阅详情和使用限制。嵌套的只读 DTO 提供完整的 IDE 自动完成和可预测的数据结构。
$profile = $client->profile()->me(); // Account info echo $profile->client->name; echo $profile->user->email; // Plan details echo $profile->plan->name; echo $profile->plan->endDatetime; // Usage limits echo $profile->usages->links->remaining; echo $profile->usages->apiLinks->used; echo $profile->usages->massLinks->limit;
组织和帐户元数据。
认证用户信息和帐户详情。
当前订阅和计费周期。
API 限制、链接配额和剩余使用量。
使用专用异常类而非通用响应处理 API 错误。每个 HTTP 错误都映射到特定的异常类型,而 ValidationException 在字段级别暴露验证详情。
use Lix\Exceptions\ValidationException; use Lix\Exceptions\UnauthorizedException; use Lix\Exceptions\NotFoundException; use Lix\Exceptions\RateLimitException; use Lix\Exceptions\ServerException; try { $client->links()->create( url: 'invalid-url' ); } catch (ValidationException $e) { // Field-level validation errors // $e->data; } catch (UnauthorizedException $e) { // Invalid or expired API key } catch (NotFoundException $e) { // Link or group does not exist } catch (RateLimitException $e) { // Too many requests — retry after } catch (ServerException $e) { // 5xx server error }
400 — 输入无效。访问 $e->data 以获取字段错误。
401 — 缺少、无效或过期的 API 凭据。
404 — 未找到链接、组或资源。
429 — 超出速率限制。
500 — 意外的服务器错误。
网络 / 传输故障。
所有 SDK 异常都扩展自 LixException。捕获基类进行全局处理或在需要时定位特定类型。
从 PHP、JavaScript、Python 或 Go 使用相同的 Lix.li API,配备为每个生态系统量身定制的 SDK。
Install the SDK, get your API key, and start creating short links in under a minute.