Skip to content

Commit 7c26fd1

Browse files
committed
chore(release): release php v0.1.15
1 parent b9a9335 commit 7c26fd1

3 files changed

Lines changed: 369 additions & 209 deletions

File tree

README.md

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@
1111
## 快速开始
1212

1313
```bash
14-
composer require axt-team/uapi-sdk-php
14+
composer require AxT-Team/uapi-sdk-php
1515
```
1616

1717
```php
1818
<?php
1919
require 'vendor/autoload.php';
2020

2121
$client = new Uapi\Client('https://uapis.cn', 'YOUR_API_KEY');
22-
$result = $client->misc()->getMiscHotboard(['type' => 'weibo']);
22+
$result = $client->social()->getSocialQqUserinfo(['qq' => '10001']);
2323
var_dump($result);
2424
```
2525

26-
这个接口默认只要传 `type` 就可以拿当前热榜。`time``keyword``time_start``time_end``limit``sources` 都是按场景再传的可选参数。
27-
2826
## 特性
2927

3028
现在你不再需要反反复复的查阅文档了。
@@ -39,67 +37,6 @@ HTTP 层基于 Guzzle,构造函数会自动设置 Base URL、追加 `Authoriza
3937

4038
如果你需要查看字段细节或内部逻辑,仓库中的 `./internal` 目录同步保留了由 `openapi-generator` 生成的完整结构体,随时可供参考。
4139

42-
## 响应元信息
43-
44-
每次请求完成后,SDK 会自动把响应 Header 解析成结构化的 `ResponseMeta`,你不用自己拆原始字符串。
45-
46-
成功时可以通过 `$client->lastResponseMeta` 读取,失败时可以通过 `$e->meta` 读取,两条路径拿到的是同一套字段。
47-
48-
```php
49-
<?php
50-
require 'vendor/autoload.php';
51-
52-
use Uapi\Client;
53-
use Uapi\UapiError;
54-
55-
$client = new Client('https://uapis.cn', 'YOUR_API_KEY');
56-
57-
// 成功路径
58-
$client->social()->getSocialQqUserinfo(['qq' => '10001']);
59-
$meta = $client->lastResponseMeta;
60-
if ($meta) {
61-
echo '这次请求原价: ' . ($meta->creditsRequested ?? 0) . " 积分\n";
62-
echo '这次实际扣费: ' . ($meta->creditsCharged ?? 0) . " 积分\n";
63-
echo '特殊计价: ' . ($meta->creditsPricing ?? '原价') . "\n";
64-
echo '余额剩余: ' . ($meta->balanceRemainingCents ?? 0) . " 分\n";
65-
echo '资源包剩余: ' . ($meta->quotaRemainingCredits ?? 0) . " 积分\n";
66-
echo '当前有效额度桶: ' . ($meta->activeQuotaBuckets ?? 0) . "\n";
67-
echo '额度用空即停: ' . var_export($meta->stopOnEmpty, true) . "\n";
68-
echo 'Key QPS: ' . ($meta->billingKeyRateRemaining ?? 0) . ' / ' . ($meta->billingKeyRateLimit ?? 0) . ' ' . ($meta->billingKeyRateUnit ?? 'req') . "\n";
69-
echo 'Request ID: ' . ($meta->requestId ?? '-') . "\n";
70-
}
71-
72-
// 失败路径
73-
try {
74-
$client->social()->getSocialQqUserinfo(['qq' => '10001']);
75-
} catch (UapiError $e) {
76-
if ($e->meta) {
77-
echo 'Retry-After 秒数: ' . var_export($e->meta->retryAfterSeconds, true) . "\n";
78-
echo 'Retry-After 原始值: ' . ($e->meta->retryAfterRaw ?? '-') . "\n";
79-
echo '访客 QPS: ' . ($e->meta->visitorRateRemaining ?? 0) . ' / ' . ($e->meta->visitorRateLimit ?? 0) . "\n";
80-
echo 'Request ID: ' . ($e->meta->requestId ?? '-') . "\n";
81-
}
82-
}
83-
```
84-
85-
常用字段一览:
86-
87-
| 字段 | 说明 |
88-
|------|------|
89-
| `creditsRequested` | 这次请求原本要扣多少积分,也就是请求价 |
90-
| `creditsCharged` | 这次请求实际扣了多少积分 |
91-
| `creditsPricing` | 特殊计价原因,例如缓存半价 `cache-hit-half-price` |
92-
| `balanceRemainingCents` | 账户余额剩余(分) |
93-
| `quotaRemainingCredits` | 资源包剩余积分 |
94-
| `activeQuotaBuckets` | 当前还有多少个有效额度桶参与计费 |
95-
| `stopOnEmpty` | 额度耗尽后是否直接停止服务 |
96-
| `retryAfterSeconds` / `retryAfterRaw` | 限流后的等待时长;当服务端返回 HTTP 时间字符串时看 `retryAfterRaw` |
97-
| `requestId` | 请求唯一 ID,排障时使用 |
98-
| `billingKeyRateLimit` / `billingKeyRateRemaining` | Billing Key 当前 QPS 规则的上限与剩余 |
99-
| `billingIpRateLimit` / `billingIpRateRemaining` | Billing Key 单 IP 当前 QPS 规则的上限与剩余 |
100-
| `visitorRateLimit` / `visitorRateRemaining` | 访客当前 QPS 规则的上限与剩余 |
101-
| `rateLimitPolicies` / `rateLimits` | 完整结构化限流策略数据 |
102-
10340
## 错误模型概览
10441

10542
| HTTP 状态码 | SDK 错误类型 | 附加信息 |

internal/README.md

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,68 @@
1-
## uapi-sdk-php internal
1+
# uapi-sdk-php
22

3-
这个目录保留的是 OpenAPI Generator 生成的原始参考文档,主要用来对照 operation、model 和生成器层面的类名。
4-
如果你是想直接安装并使用 SDK,请优先查看仓库根目录的 `README.md`
3+
UAPI 官方接口文档
54

6-
## 安装
75

8-
```bash
9-
composer require axt-team/uapi-sdk-php
6+
## Installation & Usage
7+
8+
### Requirements
9+
10+
PHP 8.1 and later.
11+
12+
### Composer
13+
14+
To install the bindings via [Composer](https://getcomposer.org/), add the following to `composer.json`:
15+
16+
```json
17+
{
18+
"repositories": [
19+
{
20+
"type": "vcs",
21+
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
22+
}
23+
],
24+
"require": {
25+
"GIT_USER_ID/GIT_REPO_ID": "*@dev"
26+
}
27+
}
1028
```
1129

12-
## 最小示例
30+
Then run `composer install`
31+
32+
### Manual Installation
33+
34+
Download the files and include `autoload.php`:
1335

1436
```php
1537
<?php
16-
require 'vendor/autoload.php';
17-
18-
$client = new Uapi\Client('https://uapis.cn', 'YOUR_API_KEY');
19-
$result = $client->misc()->getMiscHotboard(['type' => 'weibo']);
20-
var_dump($result);
38+
require_once('/path/to/uapi-sdk-php/vendor/autoload.php');
2139
```
2240

23-
## 说明
41+
## Getting Started
42+
43+
Please follow the [installation procedure](#installation--usage) and then run the following:
2444

25-
下面继续保留自动生成的 API / Model 索引,方便你按生成器原始命名检索。
45+
```php
46+
<?php
47+
require_once(__DIR__ . '/vendor/autoload.php');
48+
49+
50+
51+
52+
$apiInstance = new OpenAPI\Client\Api\DefaultApi(
53+
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
54+
// This is optional, `GuzzleHttp\Client` will be used as default.
55+
new GuzzleHttp\Client()
56+
);
57+
58+
try {
59+
$result = $apiInstance->getSearchEngines();
60+
print_r($result);
61+
} catch (Exception $e) {
62+
echo 'Exception when calling DefaultApi->getSearchEngines: ', $e->getMessage(), PHP_EOL;
63+
}
64+
65+
```
2666

2767
## API Endpoints
2868

0 commit comments

Comments
 (0)