使用Aliyun的SDK进行调用

在Java中使用,引入aliyun-java-sdk-core

 <dependency>
   <groupId>com.aliyun</groupId>
   <artifactId>aliyun-java-sdk-core</artifactId>
   <version>${aliyun-java-sdk-core.version}</version>
 </dependency>
public class TestOpenAPI {
    public static final String product = "DAS";
    public static final String version = "2020-01-16";
    public static final String domain = "das.cn-shanghai.aliyuncs.com";
    public static final String key = "xxx";
    public static final String secret = "xxx";

    public static String requestDASOpenApi(String action, Map<String, Object> params) {
        CommonRequest request = new CommonRequest();
        request.setVersion(version);
        request.setDomain(domain);
        request.setMethod(MethodType.POST);
        request.setProduct(product);
        request.setAction(action);
        if (params != null) {
            params.forEach(request::putBodyParameter);
        }
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", key, secret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        try {
            CommonResponse response = client.getCommonResponse(request);
            if (response.getHttpStatus() == 200) {
                return response.getData();
            }
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void testCreateReport() {
        String action = "CreateDiagnosticReport";
        Long endTime = System.currentTimeMillis();
        Long startTime = endTime - TimeUnit.HOURS.toMillis(6);
        Map<String, Object> param = new HashMap<>();
        param.put("DBInstanceId", "rm-xx");
        param.put("StartTime", startTime);
        param.put("EndTime", endTime);
        System.out.println(requestDASOpenApi(action, param));
    }

    public static void testDescribeReport() {
        String action = "DescribeDiagnosticReportList";
        Map<String, Object> param = new HashMap<>();
        param.put("DBInstanceId", "rm-xxxx");
        System.out.println(requestDASOpenApi(action, param));
    }

    public static void main(String[] args) {
       testDescribeReport();
    }
}