package cn.unitid.matrix.pkiservice.test.kms;

import cn.unitid.matrix.pkiservice.sdk.ApiException;
import cn.unitid.matrix.pkiservice.sdk.PkiClient;
import cn.unitid.matrix.pkiservice.sdk.PkiOkhttpClient;
import cn.unitid.matrix.pkiservice.sdk.kms.request.CsrRequest;
import cn.unitid.matrix.pkiservice.sdk.kms.response.CsrResponse;

/**
 * 申请证书
 */
public class CsrTest {

    public static void main(String[] args) {
        // 提供的URL
        String url = "http://localhost:9200";

        // 您的appKey
        String appKey = "CLxUIrYIO0";

        // 您的appSecret
        String appSecret = "Rsl7kjMrqHrxhDk9uou23IYRnCVjRKJC";

        // 1.原客户端
        PkiClient pkiClient = new PkiOkhttpClient(url, appKey, appSecret);

        CsrRequest request = new CsrRequest();

        //算法
        request.setAlgorithm("SM2");

        //密钥强度
        request.setKeySize(256);

        //证书持有者名称
        request.setCn("test");

        //国家
        request.setC("");

        //省份
        request.setSt("");

        //城市
        request.setL("");

        //组织
        request.setO("");

        //部门
        request.setOu("");

        try {
            CsrResponse response = pkiClient.execute(request);
            // 后续业务
            if (response.isSuccess()) {
                System.out.println("成功响应：" + response.getResult());
            } else {
                System.out.println("失败响应：" + response.getBody());
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }

    }
}
