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

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.DegistEnum;
import cn.unitid.matrix.pkiservice.sdk.tss.request.TssGenerateRequest;
import cn.unitid.matrix.pkiservice.sdk.tss.response.TssGenerateResponse;

/**
 * @Author 南京壹证通信息科技有限公司 - PKI服务项目组
 * @Description：
 * @Date：Create in 10:20 2021/12/14
 * @Modified By:
 */
public class TssGenerateTest {

    public static void main(String[] args) {

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

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

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

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

        TssGenerateRequest request = new TssGenerateRequest();
        request.setDataType(DataType.ORIGINAL);
        request.setData("123");
        request.setAlgo(DegistEnum.SM3);
        request.setSignType(CertSearchEnum.CERT_ID);
        request.setSignItemValue("629f172a9f39400d65cd3de5");
        request.setIncludeCert(Boolean.TRUE);

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