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

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.consts.CertSearchEnum;
import cn.unitid.matrix.pkiservice.sdk.consts.DataType;
import cn.unitid.matrix.pkiservice.sdk.consts.SignatureAlgorithm;
import cn.unitid.matrix.pkiservice.sdk.svs.request.P1VerifyBatchRequest;
import cn.unitid.matrix.pkiservice.sdk.svs.response.P1VerifyBatchResponse;

import java.util.ArrayList;

public class P1VerifyBatchTest {

    public static void main(String[] args) {


        // 提供的URL
        String url = "http://localhost:9200";

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

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

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

        P1VerifyBatchRequest request = new P1VerifyBatchRequest();

        request.setSignatureDataType(DataType.BASE64);

        //request.setTemplateId("640987992c1ca52e602cfe7e");

        //通过何种方式进行签名 CERT_ID：证书ID，KEY_INDEX：密钥索引， SN_HEX：证书序列号(十六进制格式)，SN_DEC：证书序列号(十进制格式)，TN_HASH：证书证书指纹，CERT_CN：证书CN ，CERT_DN：证书主题项(DN)
        request.setSignType(CertSearchEnum.CERT_ID);
        //签名项目的值
        request.setSignItemValue("640723b080a0554c3a6a0fec");
        //原文数据类型
        request.setDataType(DataType.ORIGINAL);

        ArrayList<String> dataList = new ArrayList<>();

        dataList.add("123");

        dataList.add("312");

        //设置待验签数据集合
        request.setDataList(dataList);

        ArrayList<String> sList = new ArrayList<>();

        sList.add("MEYCIQCdc5Oz2oqaIWVDFDbI0haxKDGxpmMFrXCjLuT+V4UB3QIhALyfS3ptgMNymbOX0P9ZPaSh+WJQHxuiH7xz1iJVPN5T");

        sList.add("MEUCIDFDlWs7bUKRDPdyULNFpSAOjmti5l+8PXUPudiDOZ5vAiEA62OZV+GZ6AwXweTOkCrTDwuY9PZi8fHOuVuHVRK8UqA=");

        //设置签名值集合
        request.setSignatureList(sList);

        // 摘要算法，SM2证书签名固定为SM3，RSA默认SHA256
        request.setSignatureAlgorithm(SignatureAlgorithm.SM3withSM2);
        // 是否返回证书
        request.setReturnCert(false);


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

    }

}
