|
| 1 | +# ALAPI-SDK |
| 2 | +ALAPI 的 Java SDK / Java SDK for ALAPI. |
| 3 | + |
| 4 | +## 环境要求 (Environment) |
| 5 | + - Java 8 / Kotlin |
| 6 | + - Maven / Gradle |
| 7 | + - Language Level 8 or greater |
| 8 | + |
| 9 | +## 安装 (Installation) |
| 10 | +(如果想以 jar 包安装) If you want to install with jar file |
| 11 | + |
| 12 | +(下载) Download [`dist/alapi-javasdk.jar`](dist/alapi-javasdk.jar) |
| 13 | + |
| 14 | +### Apache Maven |
| 15 | +package manager |
| 16 | +```xml |
| 17 | +<dependency> |
| 18 | + <groupId>cn.alapi</groupId> |
| 19 | + <artifactId>javasdk</artifactId> |
| 20 | + <version>1.0</version> |
| 21 | + <type>pom</type> |
| 22 | +</dependency> |
| 23 | +``` |
| 24 | + |
| 25 | +Jar |
| 26 | +```xml |
| 27 | +<dependency> |
| 28 | + <groupId>cn.alapi</groupId> |
| 29 | + <artifactId>javasdk</artifactId> |
| 30 | + <version>1.0.1</version> |
| 31 | + <scope>system</scope> |
| 32 | + <systemPath>path/to/alapi-javasdk.jar</systemPath> |
| 33 | +</dependency> |
| 34 | +``` |
| 35 | + |
| 36 | +### Gradle |
| 37 | + |
| 38 | +package manager |
| 39 | +```groovy |
| 40 | +implementation 'cn.alapi:javasdk:1.0' |
| 41 | +``` |
| 42 | + |
| 43 | +Jar |
| 44 | +```groovy |
| 45 | +compile files('path/to/alapi-javasdk.jar') |
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | +## 示例 (Example) |
| 50 | +```java |
| 51 | +// 替换为你自己的包名 / replace it with your own package name |
| 52 | +package org.example.sdktest; |
| 53 | + |
| 54 | +import cn.alapi.javasdk.AlapiClient; |
| 55 | +import cn.alapi.javasdk.AlapiRequest; |
| 56 | +import cn.alapi.javasdk.AlapiResponse; |
| 57 | + |
| 58 | +public class TestClass { |
| 59 | + // 定义为静态属性以更好地重用 |
| 60 | + // Defined as a static property for better reuse |
| 61 | + private static final AlapiClient client = new AlapiClient() |
| 62 | + .setToken("your access token / 你的 token"); |
| 63 | + |
| 64 | + public static void main(String[] args) { |
| 65 | + AlapiRequest request = new AlapiRequest(); |
| 66 | + // example "/api/joke/random" |
| 67 | + request.setApi("API 地址 / specific API path"); |
| 68 | + try { |
| 69 | + AlapiResponse response = client.execute(request); |
| 70 | + System.out.println(response.getCode()); // status code / 状态码 |
| 71 | + System.out.println(response.getMsg()); // status message / 状态消息 |
| 72 | + System.out.println(response.getData()); // api data / 请求数据 |
| 73 | + System.out.println(response.getTime()); // timestamp / 时间戳 |
| 74 | + System.out.println(response.getLogID()); // log id for this request / 本次请求记录 ID |
| 75 | + } catch (Exception ignored) { } |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## 接口文档地址 |
| 81 | +ALAPI 接口文档地址:[https://www.alapi.cn](https://www.alapi.cn) |
0 commit comments