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.AuthCertRequest;
import cn.unitid.matrix.pkiservice.sdk.kms.response.AuthCertResponse;

import java.util.HashSet;
import java.util.Set;

/**
 * 同步授权
 */
public class AuthCertTest {

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

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

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

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

        AuthCertRequest request = new AuthCertRequest();

        //证书id
        request.setCertId("63512d8a00c7887adcc6da5a");

        Set<String> set = new HashSet<>();

        set.add("BKH4KjNJRpHO3mL7tk9/+v0O+QJZJb0xlOxlODHICPF+s9DHESicyAVqQbpYZRS+2MTf1Pru+cYC2psQrxetxAo=");
        //被授权对象公钥列表
        request.setAuthPublicKeys(set);

        request.setAuthId("123456");

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

    }
}
