退款证书改造,增加证书信息串

This commit is contained in:
egan
2018-01-14 23:59:14 +08:00
parent da9b06c17a
commit 8f5f3e8eaa
2 changed files with 52 additions and 8 deletions

View File

@@ -19,8 +19,13 @@ public class HttpConfigStorage {
//代理密码
protected String httpProxyPassword;
//https请求所需的证书PKCS12地址请使用绝对路径
private String keystorePath;
/**
* @see #keystore 是否为https请求所需的证书PKCS12的地址,默认为地址,否则为证书信息串
*/
private boolean isPath = true;
//https请求所需的证书PKCS12
private String keystore;
//证书对应的密码
private String storePassword;
@@ -76,13 +81,54 @@ public class HttpConfigStorage {
/**
* https请求所需的证书PKCS12地址请使用绝对路径
* @return 证书PKCS12地址
* @see #getKeystore()
*/
@Deprecated
public String getKeystorePath() {
return keystorePath;
return keystore;
}
/**
* 设置https请求所需的证书PKCS12地址请使用绝对路径
* @param keystorePath 证书PKCS12地址
* @see #getKeystore()
*/
@Deprecated
public void setKeystorePath(String keystorePath) {
this.keystorePath = keystorePath;
this.keystore = keystorePath;
}
/**
* 获取是否为证书地址
* @return 是否为证书地址,配合 {@link #getKeystore()}使用
*/
public boolean isPath() {
return isPath;
}
/**
* 设置是否为证书地址
* @param path 是否为证书地址
*/
public void setPath(boolean path) {
isPath = path;
}
/**
* 获取证书信息
* @return 证书信息 根据 {@link #isPath()}进行区别地址与信息串
*/
public String getKeystore() {
return keystore;
}
/**
* 设置证书
* @param keystore 证书信息
*/
public void setKeystore(String keystore) {
this.keystore = keystore;
}
/**

View File

@@ -14,9 +14,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.*;
import java.net.URI;
import java.security.*;
import java.util.Map;
@@ -72,7 +70,7 @@ public class HttpRequestTemplate {
}
//读取本机存放的PKCS12证书文件
try(FileInputStream instream = new FileInputStream(new File(configStorage.getKeystorePath()))){
try(InputStream instream = configStorage.isPath() ? new FileInputStream(new File(configStorage.getKeystore())) : new ByteArrayInputStream(configStorage.getKeystore().getBytes())){
//指定读取证书格式为PKCS12
KeyStore keyStore = KeyStore.getInstance("PKCS12");