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.consts.DataType;
import cn.unitid.matrix.pkiservice.sdk.consts.SignatureAlgorithm;
import cn.unitid.matrix.pkiservice.sdk.kms.request.P1SignBatchRequest;
import cn.unitid.matrix.pkiservice.sdk.kms.response.SignBatchResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * p1批量签名
 */
public class P1SignBatchTest {

    public static void main(String[] args) {

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

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

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

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

        P1SignBatchRequest request = new P1SignBatchRequest();

        List<String> dataList = new ArrayList<>();
        dataList.add("123");
        dataList.add("345");
        dataList.add("=;&*abC12!@#$%^&*()\"'<>?:{}_+,./;'[]");
        //待签名数据
        request.setDataList(dataList);

        //待签名数据类型
        request.setDataType(DataType.ORIGINAL);

        //签名算法
        request.setSignatureAlgorithm(SignatureAlgorithm.SM3withSM2);

        //签名数据类型
        request.setSignDataType(DataType.BASE64);

        //授权码
        request.setAuthorizationCode("RuMuggS0xtRzGZYW3dg4L");

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

    }
}
