Kaynağa Gözat

IRS 签章平台账号密码配置

master
niohe·erbao 1 yıl önce
ebeveyn
işleme
4b3d48e297
2 değiştirilmiş dosya ile 11 ekleme ve 21 silme
  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 Dosyayı Görüntüle

@@ -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);


+ 2
- 1
pmapi/src/main/resources/application-dev.yml Dosyayı Görüntüle

@@ -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


Yükleniyor…
İptal
Kaydet