Skip to content

如何对接开放接口

关于 如何获取 UID 和 APIToken如何请求接口 的介绍已在 后端接口 中详细介绍,此处不再过多阐述。

声明 API 链接

java
private static final String URL = "https://skidonion.tech/api/oauth/";

所有请求的链接都是基于该 URL 进行的。

准备请求标头

编写一个请求表头构造器。

java
public static Map<String, String> header() {
    Map<String, String> header = new HashMap<>();
    // 用户ID
    header.put("phantom-shield-x-uid", "xxxxxx");
    // 用户TOKEN
    header.put("phantom-shield-x-api-token", "xxxxxx");
    return header;
}

当涉及到用户操作时应该还需要 access-token:

java
public static Map<String, String> header() {
    Map<String, String> header = new HashMap<>();
    // 用户ID
    header.put("phantom-shield-x-uid", "xxxxxx");
    // 用户TOKEN
    header.put("phantom-shield-x-api-token", "xxxxxx");
    // Access Token
    header.put("phantom-shield-x-access-token", "xxxxxx");
    return header;
}

如何构建授权链接?

官方的开放授权链接有且仅有skidonion.techuncrackable.me

您应该这样构建开放授权链接:

console
https://skidonion.tech/#/oauth/您的UID/业务参数?redirect_url=您的链接

以下是一个示例链接:

console
https://skidonion.tech/#/oauth/1/helloworld?redirect_url=https%3A%2F%2Fbaidu.com%2F

注意

您在输入重定向指令时应该是完整的超链接,例如:

https://www.baidu.com/

https://yourdomain.com/path

请不要带任何参数:

https://yourdomain.com/path?a=1111

这是不被允许的

您还应该填入参数时将您的超链接编码

URL在线编码工具

授权成功回调

授权成功之后,网页将会重定向至您指定的网站并附带参数,示例:

console
https://yourdomain.com/path?code=334432a6-7f09-475e-9e09-ebf8d484d271&state=helloworld

state 参数即为 业务参数 您可以利用此参数来拓展您的业务。

通过 code 参数可以获取到用户的 access_token

请注意:您只有十分钟时间可以使用code

请求 AccessToken

请求参数

参数类型描述必需
code字符串用于获取AccessToken的临时码

请求示例

java
void queryAccessToken() {
    Map<String, String> params = new HashMap<>();
    params.put("code", "临时码");
    String result = HttpUtils.post(URL + "token", params, header());
    System.out.println(result);
}

预期结果

字段名类型描述
access_token字符串访问令牌
expires_in整数型过期秒数
json
{
  "code": 0,
  "message": "成功",
  "entity": {
    "access_token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "expires_in": 2678400
  }
}

请求用户信息

请求示例

java
void queryUserInfo() {
    Map<String, String> params = new HashMap<>();
    String result = HttpUtils.post(URL + "user-info", params, header());
    System.out.println(result);
}

预期结果

json
{
  "code": 0,
  "message": "成功",
  "entity": {
    "ranks": [
      {
        "expired": "2025-03-06 00:00:00",
        "name": "基础用户组",
        "id": 1,
        "software_name": "幻影盾X"
      },
      {
        "expired": "2024-06-20 12:21:09",
        "name": "授权验证用户组",
        "id": 2,
        "software_name": "幻影盾X"
      }
    ],
    "softwares": [
      {
        "name": "幻影盾X",
        "id": 1
      }
    ],
    "register_ip": "127.0.0.1",
    "username": "imfl0wow"
  }
}