定义业务凭证中某一证据点名称

更新时间:2024-03-12 16:15:24

接口描述

新增业务凭证中某一证据点名称记录,可理解成与证据发生时场景有关的信息,如合同签署人信息。

接口

环境

地址

沙箱环境

http://smlcunzheng.tsign.cn:8083/evi-service/evidence/v1/sp/temp/seg/add

https://smlcunzheng.tsign.cn:9443/evi-service/evidence/v1/sp/temp/seg/add

正式环境

http://evislb.tsign.cn:8080/evi-service/evidence/v1/sp/temp/seg/add

https://evislb.tsign.cn:443/evi-service/evidence/v1/sp/temp/seg/add

公共请求参数

参数名称

必选

参数说明

示例值

X-timevale-project-id

项目名称


X-timevale-signature

请求签名值<点击查看计算方法>


X-timevale-signature-algorithm

请求签名算法,固定值:HmacSHA256


X-timevale-mode

请求签名方式,固定值:package


Content-Type

请求报文数据格式,固定值:application/json


请求参数

参数名称

类型

必选

参数说明

示例值

sceneTempletId

String

业务凭证(名称)ID


name

List

证据点名称列表


响应参数

参数名称

类型

必选

参数说明

示例值

errCode

int

错误码


msg

string

错误信息


success

boolean

是否成功标识


result

JSON

添加成功后ID和名称的对应列表

请求示例  

{
"sceneTempletId":"64b9c14c-a7fd-4141-93b6-d62a238b8fb2",
"name":["开发者自定义的证据点名称"] // 如:合同签署人信息
}

JAVA请求示例

	public static void main(String[] args) {

		String segmentName = "合同签署人信息";
		// 存证场景环节类型列表(根据实际情况进行增减或修改,此处仅以"合同签署人信息"为例)
		ArrayList<String> segments = new ArrayList<String>();
		segments.add(segmentName);

		// 请求参数-JSON字符串
		JSONObject param_json = new JSONObject();
		// sceneTempletId对应的是[定义业务凭证(名称)]时获取的[业务凭证(名称)ID]
		param_json.put("sceneTempletId", "64b9c14c-a7fd-4141-93b6-d62a238b8fb2");
		param_json.put("name", JSONArray.fromObject(segments));
		System.out.println("请求参数:" + param_json);

		String PROJECT_ID = "项目id";
		String ALGORITHM = "HmacSHA256";
		String ENCODING = "UTF-8";
		String PROJECT_SECRET = "密钥";

		// 请求签名值
		String signature = getSignature(param_json.toString(), PROJECT_SECRET, ALGORITHM, ENCODING);
		// System.out.println("请求签署值 = " + signature);

		// HTTP请求内容类型
		String ContentType = "application/json";

		// 设置HTTP请求头信息
		LinkedHashMap<String, String> headers = getPOSTHeaders(PROJECT_ID, signature, ALGORITHM, ContentType, ENCODING);
		// 向指定URL发送POST方法的请求
		JSONObject RequestResult = sendPOST("http://smlcunzheng.tsign.cn:8083/evi-service/evidence/v1/sp/temp/seg/add",
				param_json.toString(), headers, ENCODING);
		System.out.println("[定义业务凭证中某一证据点名称]接口返回json数据:" + RequestResult);
	}

	/***
	 * 将JSON字符串转成JSON对象
	 * 
	 * @param str
	 * @return JSON对象
	 */
	public static JSONObject toJSONObject(String str) {
		JSONObject obj = JSONObject.fromObject(str);
		return obj;
	}

	/***
	 * 向指定URL发送POST方法的请求
	 * 
	 * @param apiUrl
	 * @param data
	 * @param projectId
	 * @param signature
	 * @param encoding
	 * @return
	 */
	public static JSONObject sendPOST(String apiUrl, String data, LinkedHashMap<String, String> headers,
			String encoding) {
		StringBuffer strBuffer = null;
		JSONObject obj = null;
		try {
			// 建立连接
			URL url = new URL(apiUrl);
			HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
			// 需要输出
			httpURLConnection.setDoOutput(true);
			// 需要输入
			httpURLConnection.setDoInput(true);
			// 不允许缓存
			httpURLConnection.setUseCaches(false);

			httpURLConnection.setRequestMethod("POST");
			// 设置Headers
			if (null != headers) {
				for (String key : headers.keySet()) {
					httpURLConnection.setRequestProperty(key, headers.get(key));
				}
			}

			// 连接会话
			httpURLConnection.connect();
			// 建立输入流,向指向的URL传入参数
			DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());
			// 设置请求参数
			dos.write(data.getBytes(encoding));
			dos.flush();
			dos.close();
			// 获得响应状态
			int http_StatusCode = httpURLConnection.getResponseCode();
			String http_ResponseMessage = httpURLConnection.getResponseMessage();
			obj = new JSONObject();
			if (HttpURLConnection.HTTP_OK == http_StatusCode) {
				strBuffer = new StringBuffer();
				String readLine = new String();
				BufferedReader responseReader = new BufferedReader(
						new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8"));
				while ((readLine = responseReader.readLine()) != null) {
					strBuffer.append(readLine);
				}
				responseReader.close();
				// System.out.println("http_StatusCode = " + http_StatusCode + "
				// request_Parameter = " + data);
				obj = toJSONObject(strBuffer.toString());
			} else {
				throw new RuntimeException(
						MessageFormat.format("请求失败,失败原因: Http状态码 = {0} , {1}", http_StatusCode, http_ResponseMessage));
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return obj;
	}

	/***
	 * POST请求的头部信息
	 * 
	 * @param projectId
	 * @param signature
	 * @param algorithm
	 * @param ContentType
	 * @param encoding
	 * @return
	 */
	public static LinkedHashMap<String, String> getPOSTHeaders(String projectId, String signature, String algorithm,
			String ContentType, String encoding) {
		LinkedHashMap<String, String> headers = new LinkedHashMap<String, String>();
		headers.put("X-timevale-project-id", projectId);
		headers.put("X-timevale-signature", signature);
		headers.put("X-signature-algorithm", algorithm);
		headers.put("X-timevale-mode", "package");
		headers.put("Content-Type", ContentType);
		headers.put("Charset", encoding);
		return headers;
	}

	/***
	 * 获取请求签名值
	 * 
	 * @param data      加密前数据
	 * @param key       密钥
	 * @param algorithm HmacMD5 HmacSHA1 HmacSHA256 HmacSHA384 HmacSHA512
	 * @param encoding  编码格式
	 * @return HMAC加密后16进制字符串
	 * @throws Exception
	 */
	public static String getSignature(String data, String key, String algorithm, String encoding) {
		Mac mac = null;
		try {
			mac = Mac.getInstance(algorithm);
			SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(encoding), algorithm);
			mac.init(secretKey);
			mac.update(data.getBytes(encoding));
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return null;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return null;
		} catch (InvalidKeyException e) {
			e.printStackTrace();
			return null;
		}
		return byte2hex(mac.doFinal());
	}

	/***
	 * 将byte[]转成16进制字符串
	 * 
	 * @param data
	 * 
	 * @return 16进制字符串
	 */
	public static String byte2hex(byte[] data) {
		StringBuilder hash = new StringBuilder();
		String stmp;
		for (int n = 0; data != null && n < data.length; n++) {
			stmp = Integer.toHexString(data[n] & 0XFF);
			if (stmp.length() == 1)
				hash.append('0');
			hash.append(stmp);
		}
		return hash.toString();
	}

	/**
	 * description 获取文件字节流
	 * 
	 * @param filePath 文件路径
	 **/
	public static byte[] getFileBytes(String filePath) {
		File file = new File(filePath);
		FileInputStream fis = null;
		byte[] buffer = null;

		try {
			fis = new FileInputStream(file);
			buffer = new byte[(int) file.length()];
			fis.read(buffer);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return buffer;
	}

Postman请求示例

响应示例

{
    "errCode": 0,
    "msg": "成功",
    "success": true,
    "result": {
        "9d12cc70-bdc8-48b6-932c-b6c6798257ac": "房屋租赁行业子目录下的证据点"
    }
}

错误码

错误码

错误描述

解决方案

200200

项目ID必填

请核实项目id是否为空

1000001

内部服务错误

请核实项目id传入是否正确

1000011

外部服务错误:50016, 项目不存在

请核实项目id传入是否真实存在

1000112

项目签名验证失败

请核实请求签名值是否正确

936057

场景类型ID不能为空

请核实传入sceneTempletId是否正确以及传入的业务凭证ID是否为空

936058

场景类型ID长度不能超过50

请核实传入的业务凭证ID是否超出最大长度限制

936059

环节类型名称不能为空

请核实传入的name字段是否正确以及对应的证据点名称是否为空

936060

环节类型名称长度不能超过50

请核实传入的证据点名称是否超出最大长度限制

936061

无效的场景类型ID

请核实传入的业务凭证ID是否真实存在

我要纠错