package com.jeeplus.modules.esignature.service.contract;

import com.jeeplus.modules.esignature.kinggridserver.KingGridServer;
import com.jeeplus.modules.esignature.utils.HttpRequest;

import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * 文档签名接口
 * @author Administrator
 *
 */
public class ContractDocService {
	public static void main(String[] args) throws IOException {
		String contractid = "doc_contractid_test1";
		HttpRequest request = KingGridServer.createHttpRequest("/api/cnt/sign");
		InputStream is = null;
		try{
			is = ContractService.class.getResourceAsStream("/kinggrid/demo.pdf");
			request.addInputStream("docx_file", "/kinggrid/demo.pdf", is);
			request.addParam("contract_name", "测试合同");
			request.addParam("contract_id", contractid);
			request.addParam("biz_id", UUID.randomUUID().toString().replaceAll("-", ""));
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			//设置业务时间参数
			request.addParam("biz_time", sdf.format(new Date()));
			//设置签署人的编码
			request.addParam("signer_info", "[{code:\"fgy20180410\",seal_code:\"\" , fontsize:50,offsetX:100,y:123,x:100}]" );
			//在第一页的以左下角为原点偏移
			//request.addParam("signatures", "[{ y:680,x:200,pageno:\"1\"}]");
			
			request.send();
			System.out.println(request.resultToString());
		}finally{
			if(is!=null){
				is.close();
			}
		}
	}
	
}
