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.DataType;
import cn.unitid.matrix.pkiservice.sdk.svs.request.P7VerifyRequest;
import cn.unitid.matrix.pkiservice.sdk.svs.response.P7VerifyResponse;

/**
 * 作者： 徐霁
 * <p>
 * 时间： 2021/5/24 10:18
 * <p>
 * 描述信息： P7q签名验证
 */
public class P7VerifyTest {

    public static void main(String[] args) {

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

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

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

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

        String signature = "MIAGCiqBHM9VBgEEAgKggDCAAgEDMQ4wDAYIKoEcz1UBgxEFADCABgoqgRzPVQYBBAIBAACggDCCAhcwggG9oAMCAQICDQDEuillc8CChwJ+ee4wCgYIKoEcz1UBg3UwSTELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCeaxn+iLj+ecgTESMBAGA1UEBwwJ5Y2X5Lqs5biCMRIwEAYDVQQDDAl0ZXN0U00yQ0EwHhcNMjIwNjA3MDkxNDAyWhcNMjMwNjA3MDkxNDAyWjBeMQswCQYDVQQGEwJDTjEwMC4GA1UELQwnMjlhY2VjYjgzNTRjNDY0ZmI5MGIzMmRiYzMwZWQ1OTEyMDIyMDY4MR0wGwYDVQQDDBRNYXRyaXggUEtJIFRTUyBUZXN0MTBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABD9dnFKj6VDTTCg7n6l8FJANwPZjFODTpyeB2diSJlO3uWY38t3CTU0lhcIVnqX0Nr2Q4WPi5NPqdyUUSg5RH92jdTBzMAkGA1UdEwQCMAAwHQYDVR0OBBYEFHgkVz2SHJTgVwzjhZSNW/+OQW47MA4GA1UdDwEB/wQEAwIGwDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDCDAfBgNVHSMEGDAWgBQTcZFDuLKDKvEWLGWUNnpKpY0mJzAKBggqgRzPVQGDdQNIADBFAiBvFIi2ba4jkFZJ17k8maoR0DmZqmfCdtmtPLorvcKIIAIhAJU+M/aZlg8YD60qsqJzMKbCIzHv4rb8+brseNTYM4zMAAAxggE1MIIBMQIBATBaMEkxCzAJBgNVBAYTAkNOMRIwEAYDVQQIDAnmsZ/oi4/nnIExEjAQBgNVBAcMCeWNl+S6rOW4gjESMBAGA1UEAwwJdGVzdFNNMkNBAg0AxLopZXPAgocCfnnuMAwGCCqBHM9VAYMRBQCgaTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0yMjA2MDkwNzEyMDdaMC8GCSqGSIb3DQEJBDEiBCAgfPQQUy+SpH3uJFzpsR/3H1eOvXY+s7vqROvQQ9AY+zANBgkqgRzPVQGCLQEFAARIMEYCIQCD6gUt9xNPR4NPbQvZF+iSszG/F65DT684w7aluOvoMAIhAK/cACK7Jf7vVyj8T4nHeTgaCa5VE6+n+b8n8sw7z4S5AAAAAAAA";

        String data = "123456";

        P7VerifyRequest request = new P7VerifyRequest();
        // 签名值
        request.setSignature(signature);
        // 待验签数据
        request.setData(data);
        //待验签数据格式
        request.setDataType(DataType.ORIGINAL);
        // 签名是否包含原文
        request.setAttach(false);
        // 外置证书校验
        request.setCert("-----BEGIN CERTIFICATE-----\n" +
                "MIICQDCCAeegAwIBAgINALiXiKKh/hewQSXarDAKBggqgRzPVQGDdTBJMQswCQYD\n" +
                "VQQGEwJDTjESMBAGA1UECAwJ5rGf6IuP55yBMRIwEAYDVQQHDAnljZfkuqzluIIx\n" +
                "EjAQBgNVBAMMCXRlc3RTTTJDQTAeFw0yMjExMjkwMTIwMzdaFw0yMzExMjkwMTIw\n" +
                "MzdaMFExCzAJBgNVBAYTAkNOMTAwLgYDVQQtDCc4NTlhNzUxZGZmOTc0MzczYWI2\n" +
                "Y2VhZDJhMjc5NTljYjIwMjIxMTcxEDAOBgNVBAMMB3Rlc3R0dHQwWTATBgcqhkjO\n" +
                "PQIBBggqgRzPVQGCLQNCAAQJMJEhx3xTncFdY+bGP/u5iPlgwF5kiOXjiUq1W/LS\n" +
                "4SbwSOt+MuBdkDpnBS+w8aqz+FaKthBKl91UiBXyrZmDo4GrMIGoMAkGA1UdEwQC\n" +
                "MAAwHQYDVR0OBBYEFIFcrV5xZRzW9l72QnGPSdnxAPQdMEsGA1UdJQEB/wRBMD8G\n" +
                "CCsGAQUFBwMBBggrBgEFBQcDAgYIKwYBBQUHAwQGCCsGAQUFBwMIBgorBgEEAYI3\n" +
                "CgMDBglghkgBhvhCBAEwDgYDVR0PAQH/BAQDAgM4MB8GA1UdIwQYMBaAFBNxkUO4\n" +
                "soMq8RYsZZQ2ekqljSYnMAoGCCqBHM9VAYN1A0cAMEQCIG0tfmIja08ruYGASYOb\n" +
                "tZCSl47BlL7Y4e+B1alySBSTAiBXJPpCsvzyEwSY9gAtur4plkC6MAIhi4wv2zaU\n" +
                "mMwXXQ==\n" +
                "-----END CERTIFICATE-----\n" +
                "\n" +
                "\n" +
                "-----BEGIN CERTIFICATE-----\n" +
                "MIICQTCCAeegAwIBAgINAML8m/y2irWuHU5OqjAKBggqgRzPVQGDdTBJMQswCQYD\n" +
                "VQQGEwJDTjESMBAGA1UECAwJ5rGf6IuP55yBMRIwEAYDVQQHDAnljZfkuqzluIIx\n" +
                "EjAQBgNVBAMMCXRlc3RTTTJDQTAeFw0yMjExMjkwMTIwMzdaFw0yMzExMjkwMTIw\n" +
                "MzdaMFExCzAJBgNVBAYTAkNOMTAwLgYDVQQtDCc4NTlhNzUxZGZmOTc0MzczYWI2\n" +
                "Y2VhZDJhMjc5NTljYjIwMjIxMTcxEDAOBgNVBAMMB3Rlc3R0dHQwWTATBgcqhkjO\n" +
                "PQIBBggqgRzPVQGCLQNCAATICyE5fzbuehZsoYAacWkmLeI0GJyWfTUPl3SqJjqz\n" +
                "0SqMPbd6Xx8FGSN4X0s2icP18U5Z4sT8RNgQYmidMc6qo4GrMIGoMAkGA1UdEwQC\n" +
                "MAAwHQYDVR0OBBYEFPxUGLbKViITvWG6gNXGw17lbvHaMEsGA1UdJQEB/wRBMD8G\n" +
                "CCsGAQUFBwMBBggrBgEFBQcDAgYIKwYBBQUHAwQGCCsGAQUFBwMIBgorBgEEAYI3\n" +
                "CgMDBglghkgBhvhCBAEwDgYDVR0PAQH/BAQDAgbAMB8GA1UdIwQYMBaAFBNxkUO4\n" +
                "soMq8RYsZZQ2ekqljSYnMAoGCCqBHM9VAYN1A0gAMEUCIDFUYkFSFiX6goShiHtf\n" +
                "GQl5giQf6+chimjgXYyBXnvUAiEAkYtg0Ll2B7Y++tLl7KlSXYokW0teOTtyDb+p\n" +
                "q9Q2xOo=\n" +
                "-----END CERTIFICATE-----\n" +
                "-----BEGIN CERTIFICATE-----\n" +
                "\"MIIBuzCCAV6gAwIBAgIGAYTwoj4fMAwGCCqBHM9VAYN1BQAwSzELMAkGA1UEBhMCQ04xDjAMBgNVBAoTBUdNU1NMMRAwDgYDVQQLEwdQS0kvU00yMRowGAYDVQQDExFNaWRkbGVDQSBmb3IgVGVzdDAiGA8yMDIyMTIwNzE2MDAwMFoYDzIwMjMxMjA3MTYwMDAwWjAeMQ8wDQYDVQQDDAbmtYvor5UxCzAJBgNVBAYTAkNOMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEiEgC0tJ7FcJNsSDmyuNPG1F96kxRMNv6AU93QYTz3guRasodn2GKUIoE0Pf7cEHje//xM4r9sXKMwPHIDyIA96NVMFMwGwYDVR0jBBQwEoAQ+X9VtCeUM2KmVspvzF0a/zAZBgNVHQ4EEgQQvPB/TmoOPdNLqoP8MRwj6zAJBgNVHRMEAjAAMA4GA1UdDwEB/wQEAwIAwDAMBggqgRzPVQGDdQUAA0kAMEYCIQDHoCIy6lQEGQVMDiog6/Wq9Mrg1G2hh4RretTwpYrbXAIhAOIkYoNmvocCzFNeAGvEccSF+2ATVOaN/x8yUJSmYfAE\n" +
                "-----END CERTIFICATE-----\n");

        // 是否返回证书
        request.setReturnCert(true);

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

    }

}
