SDK 示例

Java SDK 提供了适用于 Web 的代码 Demo,Demo 中模拟了如何使用智能双录质检的 API。您可以参考 Demo 来了解 SDK 整个集成过程。

参数配置

Demo 中的以下几个参数,您需要根据实际情况进行配置。

  • <AccessKey>:阿里云账号(主账号)或 RAM 用户的 AccessKey ID。

  • <AccessSecret>:阿里云账号(主账号)或 RAM 用户的 AccessKeySecret。

  • <RegionId>:服务所在的地域 ID,智能双录质检优先在金融云上架,可填入cn-shanghai-finance-1。

关于 AccessKey ID 和 AccessKeySecret 的获取方式请参见 获取AccessKey

pom 依赖

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.3.2</version>
</dependency>
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>idrsservice20200630</artifactId>
  <version>2.0.0</version>
</dependency>

Demo

import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.idrsservice.model.v20200630.GetUserRequest;
import com.aliyuncs.idrsservice.model.v20200630.GetUserResponse;
import com.aliyuncs.idrsservice.model.v20200630.ListUsersRequest;
import com.aliyuncs.idrsservice.model.v20200630.ListUsersResponse;
import com.aliyuncs.profile.DefaultProfile;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class IdrsSDKDemo {
    private static DefaultAcsClient client;

    public static String regionId = "<RegionId>";
    public static String accessKeyId = "<AccessKey>";
    public static String accessKeySecret = "<AccessSecret>";

    /**
     * 初始化 aliyun api客户端
     */
    public IdrsSDKDemo () {
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        client = new DefaultAcsClient(profile);
    }

    /**
     * 查询所有用户接口示例
     */
    public void listUsers() {
        ListUsersRequest request = new ListUsersRequest();
        ListUsersResponse response = null;
        try {
            response = client.getAcsResponse(request);
        } catch (ClientException e) {
            log.error("error msg: ", e);
        }
        log.info(JSON.toJSONString(response));
    }

    /**
     * 根据ID查询单个用户信息接口示例
     */
    public void getUser() {
        GetUserRequest request = new GetUserRequest();
        GetUserResponse response = null;
        try {
            request.setId("***");
            response = client.getAcsResponse(request);
        } catch (ClientException e) {
            log.error("error msg: ", e);
        }
        log.info(JSON.toJSONString(response));
    }

    public static void main(String[] args) {
        IdrsSDKDemo idrsSDKDemo = new IdrsSDKDemo();
        idrsSDKDemo.listUsers();
        idrsSDKDemo.getUser();
    }
}
阿里云首页 智能双录质检 相关技术圈