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

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.ces.request.CertificateRequest;
import cn.unitid.matrix.pkiservice.sdk.ces.response.CertificateResponse;

/**
 * 枚举服务器证书
 *
 * @author lihongyu
 * @date 2022/5/18 16:37
 */
public class CertificateTest {

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

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

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

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

        CertificateRequest request = new CertificateRequest();
//        request.setCn("qw");
//        request.setIssuer("C=CN,ST=江苏省,L=南京市,CN=testSM2CA");
//        request.setSubject("C=CN,ST=江苏,L=南京,O=通透,UniqueIdentifier=5202da6956424e99ab2af1a78406de2b2022057,CN=qw");
        try {
            CertificateResponse response = pkiClient.execute(request);
            // 后续业务
            if (response.isSuccess()) {
                System.out.println("成功：" + response.getResult());
            } else {
                System.out.println("失败：" + response.getBody());
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }
}
