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.DigitalEnvelopePacketRequest;
import cn.unitid.matrix.pkiservice.sdk.ces.response.DigitalEnvelopePacketResponse;
import cn.unitid.matrix.pkiservice.sdk.consts.CertSearchEnum;
import cn.unitid.matrix.pkiservice.sdk.consts.DataType;

/**
 * 数字信封--封包
 */
public class DigitalEnvelopePacketTest {

    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);

        DigitalEnvelopePacketRequest request = new DigitalEnvelopePacketRequest();


        // 通过何种方式进行封包
        request.setEncryptType(CertSearchEnum.CERT);

        // 封包依据项目的值
        request.setEncryptItemValue("");

        // 数据格式
        request.setDataType(DataType.BASE64);

        // 待封包数据
        request.setData("test_data");

        // 封包后数据格式
        request.setEnvelopeDataType(DataType.BASE64);

        try {

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


    }

}
