Browse Source

IRS 签章平台账号密码配置

tags/24080901
niohe·erbao 1 year ago
parent
commit
4b3d48e297
2 changed files with 11 additions and 21 deletions
  1. +9
    -20
      pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java
  2. +2
    -1
      pmapi/src/main/resources/application-dev.yml

+ 9
- 20
pmapi/src/main/java/com/ningdatech/pmapi/irs/sign/IRSAPIRequest.java View File

@@ -1,6 +1,7 @@
package com.ningdatech.pmapi.irs.sign; package com.ningdatech.pmapi.irs.sign;


import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ningdatech.pmapi.irs.config.IrsSealPlatformProperties;
import com.ningdatech.pmapi.todocenter.model.dto.SignReqDTO; import com.ningdatech.pmapi.todocenter.model.dto.SignReqDTO;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@@ -29,18 +30,6 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;


public class IRSAPIRequest { 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 { 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 dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = dateFormat.format(new Date()); 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); URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
String canonicalQueryString = getCanonicalQueryString(uri.getQuery()); 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"); 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()); byte[] hash = hasher.doFinal(message.getBytes());
DatatypeConverter.printHexBinary(hash); DatatypeConverter.printHexBinary(hash);
String sign = DatatypeConverter.printBase64Binary(hash); String sign = DatatypeConverter.printBase64Binary(hash);
@@ -111,14 +100,14 @@ public class IRSAPIRequest {
String signature = sign(stream); String signature = sign(stream);
//System.out.println(signature); //System.out.println(signature);
// 设置HTTP请求头 // 设置HTTP请求头
HttpEntityEnclosingRequestBase req = new HttpPost(apiUrl);
HttpEntityEnclosingRequestBase req = new HttpPost(IrsSealPlatformProperties.apiUrl);
// project-id为用户的projectId // project-id为用户的projectId
req.addHeader("appId", ProjectID);
req.addHeader("appId", IrsSealPlatformProperties.projectId);
// signature为之前生成的签名 // signature为之前生成的签名
req.addHeader("signature", signature); req.addHeader("signature", signature);
req.addHeader("X-BG-HMAC-SIGNATURE", sign); req.addHeader("X-BG-HMAC-SIGNATURE", sign);
req.addHeader("X-BG-HMAC-ALGORITHM", "hmac-sha256"); 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("X-BG-DATE-TIME", date);
req.addHeader("Content-Type", "application/json"); req.addHeader("Content-Type", "application/json");


@@ -150,7 +139,7 @@ public class IRSAPIRequest {
Mac mac = Mac.getInstance("HmacSHA256"); 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); mac.init(secKey);
@@ -168,7 +157,7 @@ public class IRSAPIRequest {
Mac mac = Mac.getInstance("HmacSHA256"); 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); mac.init(secKey);


+ 2
- 1
pmapi/src/main/resources/application-dev.yml View File

@@ -96,7 +96,7 @@ mybatis-plus:
logic-not-delete-value: false logic-not-delete-value: false
logging: logging:
config: classpath:logback-spring.xml config: classpath:logback-spring.xml
#日志配置
#日志配置
level: level:
root: info root: info
file: file:
@@ -195,6 +195,7 @@ provincial:
secret: 75152a97f20e4c4c854dc6301cf72ad4 secret: 75152a97f20e4c4c854dc6301cf72ad4




#天印服务器接口信息
irs: irs:
seal-platform: seal-platform:
project-id: 1 project-id: 1


Loading…
Cancel
Save