|
| 1 | +# uapi-sdk-cpp |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +[](https://isocpp.org/) |
| 6 | +[](https://uapis.cn/) |
| 7 | + |
| 8 | +> [!NOTE] |
| 9 | +> 所有接口的 C++ 示例都可以在 [UApi](https://uapis.cn/docs/introduction) 的接口文档页面,向下滚动至 **快速启动** 区块后直接复制。 |
| 10 | +
|
| 11 | +## 快速开始 |
| 12 | + |
| 13 | +```bash |
| 14 | +git submodule add https://github.com/AxT-Team/uapi-cpp-sdk deps/uapi-cpp |
| 15 | +``` |
| 16 | + |
| 17 | +```cpp |
| 18 | +#include <uapi/Client.hpp> |
| 19 | +#include <iostream> |
| 20 | +#include <unordered_map> |
| 21 | + |
| 22 | +int main() { |
| 23 | + uapi::Client client("https://uapis.cn/api/v1", ""); |
| 24 | + std::unordered_map<std::string, std::string> args; |
| 25 | + args["qq"] = "10001"; |
| 26 | + auto result = client.Social().getSocialQqUserinfo(args); |
| 27 | + std::cout << result << std::endl; |
| 28 | + return 0; |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +## 特性 |
| 33 | + |
| 34 | +现在你不再需要反反复复的查阅文档了。 |
| 35 | + |
| 36 | +只需在 IDE 中键入 `client.`,所有核心模块——如 `Social()`、`Game()`、`Image()`——即刻同步展现。进一步输入即可直接定位到 `getSocialQqUserinfo` 这样的具体方法,其名称与文档的 `operationId` 严格保持一致,确保了开发过程的直观与高效。 |
| 37 | + |
| 38 | +所有方法签名只接受真实且必需的参数。当你在构建请求时,IDE 会即时提示 `qq`、`username` 等键名,这彻底杜绝了在 `std::unordered_map<std::string, std::string>` 中因键名拼写错误而导致的运行时错误。 |
| 39 | + |
| 40 | +针对 401、404、429 等标准 HTTP 响应,SDK 已将其统一映射为具名的错误类型。这些错误均附带 `code`、`status`、`details` 等关键上下文信息,确保你在日志中能第一时间准确、快速地诊断问题。 |
| 41 | + |
| 42 | +基础域名、请求超时和 `User-Agent` 已预设为合理的默认值。但你完全拥有控制权,可以通过 `uapi::Client(baseUrl, token)` 及其可插拔 HTTP 实现灵活覆盖 Token、BaseURL 等配置。 |
| 43 | + |
| 44 | +如果你需要查看字段细节或内部逻辑,仓库中的 `./internal` 目录同步保留了由 `openapi-generator` 生成的完整结构体,随时可供参考。 |
| 45 | + |
| 46 | +## 错误模型概览 |
| 47 | + |
| 48 | +| HTTP 状态码 | SDK 错误类型 | 附加信息 | |
| 49 | +|-------------|------------------------|------------------------------| |
| 50 | +| 401/403 | `UnauthorizedError` | `code`、`status`、`details` | |
| 51 | +| 404 | `NotFoundError` | `code`、`status`、`details` | |
| 52 | +| 400 | `InvalidParameterError` / `InvalidParamsError` | `code`、`status`、`details` | |
| 53 | +| 429 | `ServiceBusyError` | `code`、`status` | |
| 54 | +| 5xx | `InternalServerErrorError` | `code`、`status`、`details` | |
| 55 | +| 其他 4xx/5xx| `UapiError` / `ApiErrorError` | `code`、`status`、`details` | |
| 56 | + |
| 57 | +## 其他 SDK |
| 58 | + |
| 59 | +| 语言 | 仓库地址 | |
| 60 | +|-------------|--------------------------------------------------------------| |
| 61 | +| Go | https://github.com/AxT-Team/uapi-go-sdk | |
| 62 | +| Python | https://github.com/AxT-Team/uapi-python-sdk | |
| 63 | +| TypeScript| https://github.com/AxT-Team/uapi-typescript-sdk | |
| 64 | +| Browser (TypeScript/JavaScript)| https://github.com/AxT-Team/uapi-browser-sdk | |
| 65 | +| Java | https://github.com/AxT-Team/uapi-java-sdk | |
| 66 | +| PHP | https://github.com/AxT-Team/uapi-php-sdk | |
| 67 | +| C# | https://github.com/AxT-Team/uapi-csharp-sdk | |
| 68 | +| C++(当前) | https://github.com/AxT-Team/uapi-cpp-sdk | |
| 69 | +| Rust | https://github.com/AxT-Team/uapi-rust-sdk | |
| 70 | + |
| 71 | +## 文档 |
| 72 | + |
| 73 | +访问 [UApi文档首页](https://uapis.cn/docs/introduction) 并选择任意接口,向下滚动到 **快速启动** 区块即可看到最新的 C++ 示例代码。 |
0 commit comments