From 4b3d48e297510e2a289306a1a00336de59793938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Fri, 17 Mar 2023 09:10:18 +0800 Subject: [PATCH] =?UTF-8?q?IRS=20=E7=AD=BE=E7=AB=A0=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=AF=86=E7=A0=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ningdatech/pmapi/irs/sign/IRSAPIRequest.java | 29 +++++++--------------- pmapi/src/main/resources/application-dev.yml | 3 ++- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java index 8abf904..cf8a11c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java @@ -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); diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index 11eb7bc..b6df76f 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -96,7 +96,7 @@ mybatis-plus: logic-not-delete-value: false logging: config: classpath:logback-spring.xml -#日志配置 + #日志配置 level: root: info file: @@ -195,6 +195,7 @@ provincial: secret: 75152a97f20e4c4c854dc6301cf72ad4 +#天印服务器接口信息 irs: seal-platform: project-id: 1