本文介绍了如何调用魔笔 OpenAPI。
魔笔 OpenAPI 可使用阿里云官方提供的 SDK 进行调用,下面是核心的参数列表。
参数名 | 参数值 |
参数名 | 参数值 |
x-acs-product | mobi |
x-acs-version | 2024-04-11 |
RegionId | cn-beijing |
Domain | mobi.aliyuncs.com |
下面以 java 语言为例,展示如何调用魔笔 OpenAPI,其它语言 SDK 调用逻辑类似。
引用 SDK
如使用 maven 作为依赖包管理时,可通过下面代码引用阿里云官方 SDK。
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.7.3</version>
</dependency>
可通过此链接查看官方最新 SDK。
获取 JWT token 调用示例
以下代码使用阿里云官方 SDK 调用 JWT token 生成接口。
public class Example {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "access key", "secret key");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysDomain("mobi.aliyuncs.com");
request.setSysProtocol(ProtocolType.HTTPS);
request.setSysMethod(MethodType.POST);
request.setSysVersion("2024-04-11");
request.setSysAction("GenerateNativeUserToken");
request.putQueryParameter("RegionId", "cn-beijing");
request.putQueryParameter("WorkspaceId", "空间id");
request.putQueryParameter("Username", "用户名");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ClientException e) {
e.printStackTrace();
}
}
}
示例输出
{"RequestId":"A5863101-****-****-****-46E2F54E7F60","Data":{"ExpiresIn":1800,"TokenType":"Bearer","RefreshToken":"","Scope":"profile email groups","AccessToken":"","RefreshExpiresIn":1800}}
刷新 JWT token 调用示例
以下代码使用阿里云官方 SDK 调用 JWT token 生成接口
public class Example {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "access key", "secret key");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysDomain("mobi.aliyuncs.com");
request.setSysProtocol(ProtocolType.HTTPS);
request.setSysMethod(MethodType.POST);
request.setSysVersion("2024-04-11");
request.setSysAction("RefreshNativeUserToken");
request.putQueryParameter("RegionId", "cn-beijing");
request.putQueryParameter("WorkspaceId", "17205062027392");
request.putQueryParameter("RefreshToken", "refresh token");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ClientException e) {
e.printStackTrace();
}
}
}
示例输出
{"RequestId":"AFC35A89-****-****-****-5B50C8D58BEB","Data":{"ExpiresIn":1800,"TokenType":"Bearer","RefreshToken":"","Scope":"profile email groups","AccessToken":"","RefreshExpiresIn":1800}}
该文章对您有帮助吗?
- 本页导读
- 引用 SDK
- 获取 JWT token 调用示例
- 刷新 JWT token 调用示例