|
|
@@ -1,6 +1,7 @@ |
|
|
|
package com.ningdatech.pmapi.irs.sign; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ningdatech.pmapi.irs.config.IrsSealPlatformProperties; |
|
|
|
import com.ningdatech.pmapi.todocenter.model.dto.SignReqDTO; |
|
|
|
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; |
|
|
|
import org.apache.commons.lang3.tuple.Pair; |
|
|
@@ -29,18 +30,6 @@ import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
public class IRSAPIRequest { |
|
|
|
//天印服务器接口信息 |
|
|
|
// private static String ProjectID = "XXX"; |
|
|
|
// private static String ProjectSecret = "XXXX"; |
|
|
|
// private static String accessKey = "XXXX"; |
|
|
|
// private static String secretKey = "XXXX"; |
|
|
|
// private static String apiUrl = "https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220309000004/seal-platform/seal/v1/rest/sign/signPdf"; |
|
|
|
|
|
|
|
private static String ProjectID = "XXX"; |
|
|
|
private static String ProjectSecret = "XXXX"; |
|
|
|
private static String accessKey = "XXXX"; |
|
|
|
private static String secretKey = "XXXX"; |
|
|
|
private static String apiUrl = "https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220309000004/seal-platform/seal/v1/rest/sign/signPdf"; |
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception { |
|
|
|
|
|
|
@@ -91,12 +80,12 @@ public class IRSAPIRequest { |
|
|
|
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); |
|
|
|
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); |
|
|
|
String date = dateFormat.format(new Date()); |
|
|
|
URL url = new URL(apiUrl); |
|
|
|
URL url = new URL(IrsSealPlatformProperties.apiUrl); |
|
|
|
URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null); |
|
|
|
String canonicalQueryString = getCanonicalQueryString(uri.getQuery()); |
|
|
|
String message = requestMethod.toUpperCase() + "\n" + uri.getPath() + "\n" + canonicalQueryString + "\n" + accessKey + "\n" + date + "\n"; |
|
|
|
String message = requestMethod.toUpperCase() + "\n" + uri.getPath() + "\n" + canonicalQueryString + "\n" + IrsSealPlatformProperties.accessKey + "\n" + date + "\n"; |
|
|
|
Mac hasher = Mac.getInstance("HmacSHA256"); |
|
|
|
hasher.init(new SecretKeySpec(secretKey.getBytes(), "HmacSHA256")); |
|
|
|
hasher.init(new SecretKeySpec(IrsSealPlatformProperties.secretKey.getBytes(), "HmacSHA256")); |
|
|
|
byte[] hash = hasher.doFinal(message.getBytes()); |
|
|
|
DatatypeConverter.printHexBinary(hash); |
|
|
|
String sign = DatatypeConverter.printBase64Binary(hash); |
|
|
@@ -111,14 +100,14 @@ public class IRSAPIRequest { |
|
|
|
String signature = sign(stream); |
|
|
|
//System.out.println(signature); |
|
|
|
// 设置HTTP请求头 |
|
|
|
HttpEntityEnclosingRequestBase req = new HttpPost(apiUrl); |
|
|
|
HttpEntityEnclosingRequestBase req = new HttpPost(IrsSealPlatformProperties.apiUrl); |
|
|
|
// project-id为用户的projectId |
|
|
|
req.addHeader("appId", ProjectID); |
|
|
|
req.addHeader("appId", IrsSealPlatformProperties.projectId); |
|
|
|
// signature为之前生成的签名 |
|
|
|
req.addHeader("signature", signature); |
|
|
|
req.addHeader("X-BG-HMAC-SIGNATURE", sign); |
|
|
|
req.addHeader("X-BG-HMAC-ALGORITHM", "hmac-sha256"); |
|
|
|
req.addHeader("X-BG-HMAC-ACCESS-KEY", accessKey); |
|
|
|
req.addHeader("X-BG-HMAC-ACCESS-KEY", IrsSealPlatformProperties.accessKey); |
|
|
|
req.addHeader("X-BG-DATE-TIME", date); |
|
|
|
req.addHeader("Content-Type", "application/json"); |
|
|
|
|
|
|
@@ -150,7 +139,7 @@ public class IRSAPIRequest { |
|
|
|
Mac mac = Mac.getInstance("HmacSHA256"); |
|
|
|
|
|
|
|
// 获取安全密钥 |
|
|
|
Key secKey = new SecretKeySpec(ProjectSecret.getBytes("UTF-8"), mac.getAlgorithm()); |
|
|
|
Key secKey = new SecretKeySpec(IrsSealPlatformProperties.projectSecret.getBytes("UTF-8"), mac.getAlgorithm()); |
|
|
|
|
|
|
|
// 初始化 |
|
|
|
mac.init(secKey); |
|
|
@@ -168,7 +157,7 @@ public class IRSAPIRequest { |
|
|
|
Mac mac = Mac.getInstance("HmacSHA256"); |
|
|
|
|
|
|
|
// 获取安全密钥 |
|
|
|
Key secKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), mac.getAlgorithm()); |
|
|
|
Key secKey = new SecretKeySpec(IrsSealPlatformProperties.secretKey.getBytes("UTF-8"), mac.getAlgorithm()); |
|
|
|
|
|
|
|
// 初始化 |
|
|
|
mac.init(secKey); |
|
|
|