优化证书相关操作,新增证书的存储方式

This commit is contained in:
egan
2019-04-15 00:08:09 +08:00
parent 6e5ba155c8
commit b29bd06e77
17 changed files with 572 additions and 471 deletions

View File

@@ -9,7 +9,7 @@
AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
aliPayConfigStorage.setPid("合作者id");
aliPayConfigStorage.setAppId("应用id");
aliPayConfigStorage.setAppid("应用id");
aliPayConfigStorage.setKeyPublic("支付宝公钥");
aliPayConfigStorage.setKeyPrivate("应用私钥");
aliPayConfigStorage.setNotifyUrl("异步回调地址");
@@ -34,16 +34,19 @@
//代理端口
httpConfigStorage.setHttpProxyPort(3308);
//代理用户名
httpConfigStorage.setHttpProxyUsername("user");
httpConfigStorage.setAuthUsername("user");
//代理密码
httpConfigStorage.setHttpProxyPassword("password");
httpConfigStorage.setAuthPassword("password");
/* /网路代理配置 根据需求进行设置**/
/* 网络请求ssl证书 根据需求进行设置**/
//设置ssl证书路径
httpConfigStorage.setKeystorePath("证书绝对路径");
//设置ssl证书路径 跟着setCertStoreType 进行对应
httpConfigStorage.setKeystore("证书文件流,证书字符串信息或证书绝对地址");
//设置ssl证书对应的密码
httpConfigStorage.setStorePassword("证书对应的密码");
//设置ssl证书对应的存储方式
httpConfigStorage.setCertStoreType(CertStoreType.PATH);
/* /网络请求ssl证书**/
/* /网络请求连接池**/

View File

@@ -15,7 +15,7 @@ public class AliPayConfigStorage extends BasePayConfigStorage {
/**
* 商户应用id
*/
private String appId;
private String appid;
/**
* 商户签约拿到的pid,partner_id的简称合作伙伴身份等同于 partner
*/
@@ -27,13 +27,13 @@ public class AliPayConfigStorage extends BasePayConfigStorage {
private String seller;
public void setAppId(String appId) {
this.appId = appId;
public void setAppid(String appid) {
this.appid = appid;
}
@Override
public String getAppid() {
return appId;
return appid;
}

View File

@@ -1,8 +1,7 @@
package com.egzosn.pay.common.api;
import com.egzosn.pay.common.bean.CertStoreType;
import com.egzosn.pay.common.bean.MsgType;
import com.egzosn.pay.common.bean.result.PayException;
import com.egzosn.pay.common.exception.PayErrorException;
import com.egzosn.pay.common.util.sign.CertDescriptor;
import java.util.concurrent.locks.Lock;
@@ -19,61 +18,57 @@ import java.util.concurrent.locks.ReentrantLock;
*/
public abstract class BasePayConfigStorage implements PayConfigStorage {
private Object attach;
/**
* 证书管理器
*/
private CertDescriptor certDescriptor;
private Object attach;
/**
* 应用私钥rsa_private pkcs8格式 生成签名时使用
*/
private String keyPrivate;
private String keyPrivate;
/**
* 应用私钥rsa_private pkcs8格式 生成签名时使用
* 应用私钥证书rsa_private pkcs8格式 生成签名时使用
*/
private String keyPrivateCertPwd;
private String keyPrivateCertPwd;
/**
* 支付平台公钥(签名校验使用)
*/
private String keyPublic;
private String keyPublic;
/**
* 异步回调地址
*/
private String notifyUrl;
private String notifyUrl;
/**
* 同步回调地址,支付完成后展示的页面
*/
private String returnUrl;
private String returnUrl;
/**
* 签名加密类型
*/
private String signType;
private String signType;
/**
* 字符类型
*/
private String inputCharset;
private String inputCharset;
/**
* 支付类型 aliPay 支付宝, wxPay微信..等等,扩展支付模块定义唯一。
*/
private String payType;
private String payType;
/**
* 消息来源类型
*/
private MsgType msgType;
private MsgType msgType;
/**
* 访问令牌 每次请求其他方法都要传入的值
*/
private String accessToken;
private String accessToken;
/**
* access token 到期时间时间戳
*/
private long expiresTime;
private long expiresTime;
/**
* 授权码锁
*/
@@ -88,10 +83,6 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
*/
private boolean isCertSign = false;
/**
* 支付回调消息
*/
protected PayMessageHandler handler;
@Override
public Object getAttach() {
@@ -102,17 +93,6 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
this.attach = attach;
}
@Override
public CertDescriptor getCertDescriptor() {
if (!isCertSign) {
throw new PayErrorException(new PayException("certDescriptor fail", "isCertSign is false"));
}
if (null == certDescriptor) {
certDescriptor = new CertDescriptor();
}
return certDescriptor;
}
@Override
public String getKeyPrivate() {
return keyPrivate;
@@ -121,6 +101,7 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
public void setKeyPrivate(String keyPrivate) {
this.keyPrivate = keyPrivate;
}
@Override
public String getKeyPrivateCertPwd() {
return keyPrivateCertPwd;
@@ -148,7 +129,6 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
this.notifyUrl = notifyUrl;
}
@Override
public String getReturnUrl() {
return returnUrl;
@@ -264,9 +244,6 @@ public abstract class BasePayConfigStorage implements PayConfigStorage {
public void setCertSign(boolean certSign) {
isCertSign = certSign;
if (certSign) {
certDescriptor = new CertDescriptor();
}
}

View File

@@ -20,11 +20,6 @@ import java.util.concurrent.locks.Lock;
* @return 附加信息
*/
Object getAttach();
/**
* 获取证书解释器
* @return 证书解释器
*/
CertDescriptor getCertDescriptor();
/**
* 获取私钥证书密码

View File

@@ -0,0 +1,69 @@
package com.egzosn.pay.common.bean;
import java.io.*;
/**
* 证书存储类型
*
* @author egan
* email egzosn@gmail.com
* date 2019/4/14.23:04
*/
public enum CertStoreType {
/**
* 路径,建议绝对路径
*/
PATH {
/**
* 证书信息转化为对应的输入流
*
* @param cert 证书信息
* @return 输入流
*/
@Override
public InputStream getInputStream(Object cert) throws IOException {
return new FileInputStream(new File((String) cert));
}
},
/**
* 文件流转化成字符串存储至文件或者数据库中
*/
STR {
/**
* 证书信息转化为对应的输入流
*
* @param cert 证书信息
* @return 输入流
*/
@Override
public InputStream getInputStream(Object cert) throws IOException {
return new ByteArrayInputStream(((String) cert).getBytes("ISO-8859-1"));
}
},
/**
* 文件流
*/
INPUT_STREAM {
/**
* 证书信息转化为对应的输入流
*
* @param cert 证书信息
* @return 输入流
*/
@Override
public InputStream getInputStream(Object cert) throws IOException {
return (InputStream) cert;
}
};
/**
* 证书信息转化为对应的输入流
*
* @param cert 证书信息
* @return 输入流
*/
public abstract InputStream getInputStream(Object cert) throws IOException;
}

View File

@@ -1,6 +1,8 @@
package com.egzosn.pay.common.http;
import com.egzosn.pay.common.bean.CertStoreType;
import java.io.*;
/**
@@ -29,10 +31,12 @@ public class HttpConfigStorage {
*/
private String authPassword;
/**
* @see #keystore 是否为https请求所需的证书PKCS12的地址,默认为地址,否则为证书信息串
* 证书存储类型
* @see #keystore 是否为https请求所需的证书PKCS12的地址,默认为地址,否则为证书信息串,文件流
*/
private boolean isPath = true;
private CertStoreType certStoreType = CertStoreType.PATH;
/**
* https请求所需的证书PKCS12
@@ -104,109 +108,35 @@ public class HttpConfigStorage {
this.authPassword = authPassword;
}
/**
* 代理用户名
* @return 代理用户名
* @see #getAuthUsername()
*/
@Deprecated
public String getHttpProxyUsername() {
return authUsername;
public CertStoreType getCertStoreType() {
return certStoreType;
}
/**
* 设置代理用户名
* @param httpProxyUsername 代理用户名
* @see #setAuthUsername(String)
*/
@Deprecated
public void setHttpProxyUsername(String httpProxyUsername) {
this.authUsername = httpProxyUsername;
}
/**
* 代理密码
* @return 代理密码
* @see #getAuthPassword()
*/
@Deprecated
public String getHttpProxyPassword() {
return authPassword;
}
/**
* 设置代理密码
* @param httpProxyPassword 代理密码
* @see #setAuthPassword(String)
*/
@Deprecated
public void setHttpProxyPassword(String httpProxyPassword) {
this.authPassword = httpProxyPassword;
}
/**
* https请求所需的证书PKCS12地址请使用绝对路径
* @return 证书PKCS12地址
* @see #getKeystore()
*/
@Deprecated
public String getKeystorePath() {
return (String) keystore;
}
/**
* 设置https请求所需的证书PKCS12地址请使用绝对路径
* @param keystorePath 证书PKCS12地址
* @see #getKeystore()
*/
@Deprecated
public void setKeystorePath(String keystorePath) {
this.keystore = keystorePath;
}
/**
* 获取是否为证书地址
* @return 是否为证书地址,配合 {@link #getKeystore()}使用
*/
public boolean isPath() {
return isPath;
}
/**
* 设置是否为证书地址
* @param path 是否为证书地址
*/
public void setPath(boolean path) {
isPath = path;
public void setCertStoreType(CertStoreType certStoreType) {
this.certStoreType = certStoreType;
}
/**
* 获取证书信息
* @return 证书信息 根据 {@link #isPath()}进行区别地址与信息串
* @return 证书信息 根据 {@link #getCertStoreType()}进行区别地址与信息串
*/
public InputStream getKeystoreInputStream() throws FileNotFoundException, UnsupportedEncodingException {
if (null == keystore){
public InputStream getKeystoreInputStream() throws IOException {
if (null == keystore) {
return null;
}
if(isPath()){
return new FileInputStream(new File(getKeystoreStr()));
}
if(this.keystore instanceof String){
return new ByteArrayInputStream(getKeystoreStr().getBytes("ISO-8859-1"));
}
return (InputStream) keystore;
return certStoreType.getInputStream(keystore);
}
/**
* 获取证书信息
* @return 证书信息 根据 {@link #isPath()}进行区别地址与信息串
* @return 证书信息 根据 {@link #getCertStoreType()}进行区别地址与信息串
*/
public Object getKeystore() {
return keystore;
}
/**
* 获取证书信息 证书地址
* @return 证书信息 根据 {@link #isPath()}进行区别地址与信息串
* @return 证书信息 根据 {@link #getCertStoreType()}进行区别地址与信息串
*/
public String getKeystoreStr() {
return (String) keystore;

View File

@@ -1,16 +1,15 @@
/**
*
* Licensed Property to China UnionPay Co., Ltd.
*
* <p>
* (C) Copyright of China UnionPay Co., Ltd. 2010
* All Rights Reserved.
*
*
* All Rights Reserved.
* <p>
* <p>
* Modification History:
* =============================================================================
* Author Date Description
* ------------ ---------- ---------------------------------------------------
* xshu 2014-05-28 证书工具类.
* Author Date Description
* ------------ ---------- ---------------------------------------------------
* xshu 2014-05-28 证书工具类.
* =============================================================================
*/
package com.egzosn.pay.common.util.sign;
@@ -19,10 +18,15 @@ import com.egzosn.pay.common.util.str.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.*;
import java.util.*;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
/**
@@ -31,227 +35,321 @@ import java.util.*;
* 声明:以下代码只是为了方便接入方测试而提供的样例代码,商户可以根据自己需要,按照技术文档编写。该代码仅供参考,不提供编码,性能,规范性等方面的保障
*/
public class CertDescriptor {
protected static final Log LOG = LogFactory.getLog(CertDescriptor.class);
/** 证书容器,存储对商户请求报文签名私钥证书. */
private KeyStore keyStore = null;
protected static final Log LOG = LogFactory.getLog(CertDescriptor.class);
/**
* 证书容器,存储对商户请求报文签名私钥证书.
*/
private KeyStore keyStore = null;
/** 验签公钥/中级证书 */
private X509Certificate publicKeyCert = null;
/** 验签根证书 */
private X509Certificate rootKeyCert = null;
/**
* 验签公钥/中级证书
*/
private X509Certificate publicKeyCert = null;
/**
* 验签根证书
*/
private X509Certificate rootKeyCert = null;
/**
* 通过证书路径初始化为公钥证书
*
* @param certIn 证书流
* @return X509 证书
*/
private static X509Certificate initCert(InputStream certIn) {
X509Certificate encryptCertTemp = null;
CertificateFactory cf = null;
try {
cf = CertificateFactory.getInstance("X.509");
encryptCertTemp = (X509Certificate) cf.generateCertificate(certIn);
// 打印证书加载信息,供测试阶段调试
if (LOG.isWarnEnabled()) {
LOG.warn("[CertId=" + encryptCertTemp.getSerialNumber().toString() + "]");
}
} catch (CertificateException e) {
LOG.error("InitCert Error", e);
} finally {
if (null != certIn) {
try {
certIn.close();
} catch (IOException e) {
LOG.error(e.toString());
}
}
}
return encryptCertTemp;
}
/**
* 通过证书路径初始化为公钥证书
* @param path 证书地址
* @return X509 证书
*/
private static X509Certificate initCert(String path) {
X509Certificate encryptCertTemp = null;
CertificateFactory cf = null;
FileInputStream in = null;
try {
cf = CertificateFactory.getInstance("X.509");
in = new FileInputStream(path);
encryptCertTemp = (X509Certificate) cf.generateCertificate(in);
// 打印证书加载信息,供测试阶段调试
if (LOG.isWarnEnabled()) {
LOG.warn("[" + path + "][CertId=" + encryptCertTemp.getSerialNumber().toString() + "]");
}
} catch (CertificateException e) {
LOG.error("InitCert Error", e);
} catch (FileNotFoundException e) {
LOG.error("InitCert Error File Not Found", e);
}finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
LOG.error(e.toString());
}
}
}
return encryptCertTemp;
}
/**
* 通过证书路径初始化为公钥证书
*
* @param path 证书地址
* @return X509 证书
*/
private static X509Certificate initCert(String path) {
X509Certificate encryptCertTemp = null;
CertificateFactory cf = null;
FileInputStream in = null;
try {
in = new FileInputStream(path);
encryptCertTemp = initCert(in);
} catch (FileNotFoundException e) {
LOG.error("InitCert Error File Not Found", e);
}
return encryptCertTemp;
}
/**
* 通过keyStore 获取私钥签名证书PrivateKey对象
*
* @param pwd 证书对应密码
* @return PrivateKey 私钥
*/
public PrivateKey getSignCertPrivateKey(String pwd) {
try {
Enumeration<String> aliasenum = keyStore.aliases();
String keyAlias = null;
if (aliasenum.hasMoreElements()) {
keyAlias = aliasenum.nextElement();
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(keyAlias,
pwd.toCharArray());
return privateKey;
} catch (KeyStoreException e) {
LOG.error("getSignCertPrivateKey Error", e);
return null;
} catch (UnrecoverableKeyException e) {
LOG.error("getSignCertPrivateKey Error", e);
return null;
} catch (NoSuchAlgorithmException e) {
LOG.error("getSignCertPrivateKey Error", e);
return null;
}
}
/**
* 配置的签名私钥证书certId
*
* @return 证书的物理编号
*/
public String getSignCertId() {
try {
Enumeration<String> aliasenum = keyStore.aliases();
String keyAlias = null;
if (aliasenum.hasMoreElements()) {
keyAlias = aliasenum.nextElement();
}
X509Certificate cert = (X509Certificate) keyStore
.getCertificate(keyAlias);
return cert.getSerialNumber().toString();
} catch (Exception e) {
LOG.error("getSignCertId Error", e);
return null;
}
}
/**
* 通过keyStore 获取私钥签名证书PrivateKey对象
*
* @param pwd 证书对应密码
* @return PrivateKey 私钥
*/
public PrivateKey getSignCertPrivateKey(String pwd) {
try {
Enumeration<String> aliasenum = keyStore.aliases();
String keyAlias = null;
if (aliasenum.hasMoreElements()) {
keyAlias = aliasenum.nextElement();
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(keyAlias,
pwd.toCharArray());
return privateKey;
} catch (KeyStoreException e) {
LOG.error("getSignCertPrivateKey Error", e);
return null;
} catch (UnrecoverableKeyException e) {
LOG.error("getSignCertPrivateKey Error", e);
return null;
} catch (NoSuchAlgorithmException e) {
LOG.error("getSignCertPrivateKey Error", e);
return null;
}
}
/**
* 配置的签名私钥证书certId
*
* @return 证书的物理编号
*/
public String getSignCertId() {
try {
Enumeration<String> aliasenum = keyStore.aliases();
String keyAlias = null;
if (aliasenum.hasMoreElements()) {
keyAlias = aliasenum.nextElement();
}
X509Certificate cert = (X509Certificate) keyStore.getCertificate(keyAlias);
return cert.getSerialNumber().toString();
} catch (Exception e) {
LOG.error("getSignCertId Error", e);
return null;
}
}
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param signCertPath 证书文件名
* @param signCertPwd 证书密码
* @param signCertType 证书类型
*/
public void initPrivateSignCert(String signCertPath, String signCertPwd, String signCertType) {
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param signCertPath 证书文件名
* @param signCertPwd 证书密码
* @param signCertType 证书类型
*/
public void initPrivateSignCert(String signCertPath, String signCertPwd, String signCertType) {
if (null != keyStore) {
keyStore = null;
}
try {
keyStore = getKeyInfo(signCertPath, signCertPwd, signCertType);
if (LOG.isInfoEnabled()) {
LOG.info("InitSignCert Successful. CertId=[" + getSignCertId() + "]");
}
} catch (IOException e) {
LOG.error("InitSignCert Error", e);
}
}
if (null != keyStore) {
keyStore = null;
}
try {
keyStore = getKeyInfo(signCertPath, signCertPwd,signCertType);
if (LOG.isInfoEnabled()) {
LOG.info("InitSignCert Successful. CertId=[" + getSignCertId() + "]");
}
} catch (IOException e) {
LOG.error("InitSignCert Error", e);
}
}
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param signCert 证书文件
* @param signCertPwd 证书密码
* @param signCertType 证书类型
*/
public void initPrivateSignCert(InputStream signCert, String signCertPwd, String signCertType) {
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param pfxkeyfile 证书文件名
* @param keypwd 证书密码
* @param type 证书类型
* @return 证书对象
* @throws IOException
*/
private KeyStore getKeyInfo(String pfxkeyfile, String keypwd, String type) throws IOException {
if (LOG.isWarnEnabled()) {
LOG.warn("加载签名证书==>" + pfxkeyfile);
}
try(FileInputStream fis = new FileInputStream(pfxkeyfile);) {
KeyStore ks = KeyStore.getInstance(type);
if (LOG.isWarnEnabled()) {
LOG.warn("Load RSA CertPath=[" + pfxkeyfile + "],Pwd=["+ keypwd + "],type=["+type+"]");
}
if (null != keyStore) {
keyStore = null;
}
keyStore = getKeyInfo(signCert, signCertPwd, signCertType);
if (LOG.isInfoEnabled()) {
LOG.info("InitSignCert Successful. CertId=[" + getSignCertId() + "]");
}
}
char[] nPassword = null;
nPassword = null == keypwd || "".equals(keypwd.trim()) ? null: keypwd.toCharArray();
if (null != ks) {
ks.load(fis, nPassword);
}
return ks;
} catch (Exception e) {
LOG.error("getKeyInfo Error", e);
return null;
}
}
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param fxKeyFile 证书文件名
* @param keyPwd 证书密码
* @param type 证书类型
* @return 证书对象
* @throws IOException
*/
private KeyStore getKeyInfo(String fxKeyFile, String keyPwd, String type) throws IOException {
if (LOG.isWarnEnabled()) {
LOG.warn("加载签名证书==>" + fxKeyFile);
}
FileInputStream fis = new FileInputStream(fxKeyFile);
return getKeyInfo(fis, keyPwd, type);
/**
* 通过keystore获取私钥证书的certId值
* @param keyStore
* @return
*/
private String getCertIdIdByStore(KeyStore keyStore) {
Enumeration<String> aliasenum = null;
try {
aliasenum = keyStore.aliases();
String keyAlias = null;
if (aliasenum.hasMoreElements()) {
keyAlias = aliasenum.nextElement();
}
X509Certificate cert = (X509Certificate) keyStore
.getCertificate(keyAlias);
return cert.getSerialNumber().toString();
} catch (KeyStoreException e) {
LOG.error("getCertIdIdByStore Error", e);
return null;
}
}
}
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param fxKeyFile 证书文件
* @param keyPwd 证书密码
* @param type 证书类型
* @return 证书对象
* @throws IOException
*/
public KeyStore getKeyInfo(InputStream fxKeyFile, String keyPwd, String type) {
try {
KeyStore ks = KeyStore.getInstance(type);
if (LOG.isWarnEnabled()) {
LOG.warn("Load RSA CertPath,Pwd=[" + keyPwd + "],type=[" + type + "]");
}
char[] nPassword = null;
nPassword = null == keyPwd || "".equals(keyPwd.trim()) ? null : keyPwd.toCharArray();
if (null != ks) {
ks.load(fxKeyFile, nPassword);
}
return ks;
} catch (Exception e) {
LOG.error("getKeyInfo Error", e);
return null;
} finally {
if (null != fxKeyFile) {
try {
fxKeyFile.close();
} catch (IOException e) {
LOG.error("getKeyInfo Error", e);
}
}
}
}
/**
* 通过keystore获取私钥证书的certId值
*
* @param keyStore
* @return
*/
private String getCertIdIdByStore(KeyStore keyStore) {
Enumeration<String> aliasenum = null;
try {
aliasenum = keyStore.aliases();
String keyAlias = null;
if (aliasenum.hasMoreElements()) {
keyAlias = aliasenum.nextElement();
}
X509Certificate cert = (X509Certificate) keyStore
.getCertificate(keyAlias);
return cert.getSerialNumber().toString();
} catch (KeyStoreException e) {
LOG.error("getCertIdIdByStore Error", e);
return null;
}
}
/**
* 加载中级证书
* @param certPath 证书地址
*/
public void initPublicCert(String certPath) {
if (!StringUtils.isEmpty(certPath)) {
publicKeyCert = initCert(certPath);
if (LOG.isInfoEnabled()) {
LOG.info("Load PublicKeyCert Successful");
}
} else if (LOG.isInfoEnabled()) {
LOG.info("PublicKeyCert is empty");
}
}
/**
* 加载证书
* @param certPath 证书地址
*/
public void initRootCert(String certPath) {
if (!StringUtils.isEmpty(certPath)) {
rootKeyCert = initCert(certPath);
if (LOG.isInfoEnabled()) {
LOG.info("Load RootCert Successful");
}
} else if (LOG.isInfoEnabled()) {
LOG.info("RootCert is empty");
}
}
/**
* 加载中级证书
*
* @param certPath 证书地址
*/
public void initPublicCert(String certPath) {
if (!StringUtils.isEmpty(certPath)) {
publicKeyCert = initCert(certPath);
if (LOG.isInfoEnabled()) {
LOG.info("Load PublicKeyCert Successful");
}
} else if (LOG.isInfoEnabled()) {
LOG.info("PublicKeyCert is empty");
}
}
/**
* 获取公钥/中级证书
* @return X509Certificate
*/
public X509Certificate getPublicCert() {
return publicKeyCert;
}
/**
* 加载中级证书
*
* @param cert 证书文件
*/
public void initPublicCert(InputStream cert) {
if (null != cert) {
publicKeyCert = initCert(cert);
if (LOG.isInfoEnabled()) {
LOG.info("Load PublicKeyCert Successful");
}
} else if (LOG.isInfoEnabled()) {
LOG.info("PublicKeyCert is empty");
}
}
/**
* 加载根证书
*
* @param certPath 证书地址
*/
public void initRootCert(String certPath) {
if (!StringUtils.isEmpty(certPath)) {
try {
initRootCert(new FileInputStream(certPath));
} catch (FileNotFoundException e) {
LOG.info("RootCert is empty");
}
} else if (LOG.isInfoEnabled()) {
LOG.info("RootCert is empty");
}
}
/**
* 加载根证书
*
* @param cert 证书文件
*/
public void initRootCert(InputStream cert) {
if (null != cert) {
rootKeyCert = initCert(cert);
if (LOG.isInfoEnabled()) {
LOG.info("Load RootCert Successful");
}
} else if (LOG.isInfoEnabled()) {
LOG.info("RootCert is empty");
}
}
/**
* 获取公钥/中级证书
*
* @return X509Certificate
*/
public X509Certificate getPublicCert() {
return publicKeyCert;
}
/**
* 获取中级证书
*
* @return X509Certificate
*/
public X509Certificate getRootCert() {
return rootKeyCert;
}
/**
* 获取中级证书
* @return X509Certificate
*/
public X509Certificate getRootCert() {
return rootKeyCert;
}
}

View File

@@ -22,7 +22,7 @@ public enum PayType implements BasePayType {
public PayService getPayService(ApyAccount apyAccount) {
AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
aliPayConfigStorage.setPid(apyAccount.getPartner());
aliPayConfigStorage.setAppId(apyAccount.getAppid());
aliPayConfigStorage.setAppid(apyAccount.getAppid());
aliPayConfigStorage.setKeyPublic(apyAccount.getPublicKey());
aliPayConfigStorage.setKeyPrivate(apyAccount.getPrivateKey());
aliPayConfigStorage.setNotifyUrl(apyAccount.getNotifyUrl());
@@ -153,9 +153,9 @@ public class PayResponse {
//代理端口
httpConfigStorage.setHttpProxyPort(3308);
//代理用户名
httpConfigStorage.setHttpProxyUsername("user");
httpConfigStorage.setAuthUsername("user");
//代理密码
httpConfigStorage.setHttpProxyPassword("password");
httpConfigStorage.setAuthPassword("password");
*/
//设置ssl证书路径

View File

@@ -48,7 +48,7 @@ public class AliPayController {
public void init() {
AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
aliPayConfigStorage.setPid("2088102169916436");
aliPayConfigStorage.setAppId("2016080400165436");
aliPayConfigStorage.setAppid("2016080400165436");
aliPayConfigStorage.setKeyPublic("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIgHnOn7LLILlKETd6BFRJ0GqgS2Y3mn1wMQmyh9zEyWlz5p1zrahRahbXAfCfSqshSNfqOmAQzSHRVjCqjsAw1jyqrXaPdKBmr90DIpIxmIyKXv4GGAkPyJ/6FTFY99uhpiq0qadD/uSzQsefWo0aTvP/65zi3eof7TcZ32oWpwIDAQAB");
aliPayConfigStorage.setKeyPrivate("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKroe/8h5vC4L6T+B2WdXiVwGsMvUKgb2XsKix6VY3m2wcf6tyzpNRDCNykbIwGtaeo7FshN+qZxdXHLiIam9goYncBit/8ojfLGy2gLxO/PXfzGxYGs0KsDZ+ryVPPmE34ZZ8jiJpR0ygzCFl8pN3QJPJRGTJn5+FTT9EF/9zyZAgMBAAECgYAktngcYC35u7cQXDk+jMVyiVhWYU2ULxdSpPspgLGzrZyG1saOcTIi/XVX8Spd6+B6nmLQeF/FbU3rOeuD8U2clzul2Z2YMbJ0FYay9oVZFfp5gTEFpFRTVfzqUaZQBIjJe/xHL9kQVqc5xHlE/LVA27/Kx3dbC35Y7B4EVBDYAQJBAOhsX8ZreWLKPhXiXHTyLmNKhOHJc+0tFH7Ktise/0rNspojU7o9prOatKpNylp9v6kux7migcMRdVUWWiVe+4ECQQC8PqsuEz7B0yqirQchRg1DbHjh64bw9Kj82EN1/NzOUd53tP9tg+SO97EzsibK1F7tOcuwqsa7n2aY48mQ+y0ZAkBndA2xcRcnvOOjtAz5VO8G7R12rse181HjGfG6AeMadbKg30aeaGCyIxN1loiSfNR5xsPJwibGIBg81mUrqzqBAkB+K6rkaPXJR9XtzvdWb/N3235yPkDlw7Z4MiOVM3RzvR/VMDV7m8lXoeDde2zQyeMOMYy6ztwA6WgE1bhGOnQRAkEAouUBv1sVdSBlsexX15qphOmAevzYrpufKgJIRLFWQxroXMS7FTesj+f+FmGrpPCxIde1dqJ8lqYLTyJmbzMPYw==");
aliPayConfigStorage.setNotifyUrl("http://pay.egzosn.com/payBack.json");

View File

@@ -3,6 +3,7 @@ package com.egzosn.pay.demo.controller;
import com.egzosn.pay.common.api.PayService;
import com.egzosn.pay.common.bean.CertStoreType;
import com.egzosn.pay.common.bean.MethodType;
import com.egzosn.pay.common.bean.PayOrder;
import com.egzosn.pay.common.bean.RefundOrder;
@@ -44,20 +45,22 @@ public class UnionPayController {
public void init() {
UnionPayConfigStorage unionPayConfigStorage = new UnionPayConfigStorage();
unionPayConfigStorage.setMerId("700000000000001");
//设置CertSign必须在设置证书前
//是否为证书签名
unionPayConfigStorage.setCertSign(true);
//公钥,验签证书链格式: 中级证书路径;根证书路径
// unionPayConfigStorage.setKeyPublic("D:/certs/acp_test_middle.cer;D:/certs/acp_test_root.cer");
//中级证书路径
unionPayConfigStorage.setAcpMiddleCert("D:/certs/acp_test_middle.cer");
//根证书路径
unionPayConfigStorage.setAcpRootCert("D:/certs/acp_test_root.cer");
//私钥, 私钥证书格式: 私钥证书路径;私钥证书对应的密码
// unionPayConfigStorage.setKeyPrivate("D:/certs/acp_test_sign.pfx;000000");
// 私钥证书路径
unionPayConfigStorage.setKeyPrivateCert("D:/certs/acp_test_sign.pfx");
//私钥证书对应的密码
unionPayConfigStorage.setKeyPrivateCertPwd("000000");
//设置证书对应的存储方式,这里默认为文件地址
unionPayConfigStorage.setCertStoreType(CertStoreType.PATH);
//前台通知网址 即SDKConstants.param_frontUrl
unionPayConfigStorage.setReturnUrl("http://www.pay.egzosn.com/payBack.json");
//后台通知地址 即SDKConstants.param_backUrl

View File

@@ -79,7 +79,8 @@ public class WxPayController {
// httpConfigStorage.setKeystore(WxPayController.class.getResourceAsStream("/证书文件"));
httpConfigStorage.setKeystore(KEYSTORE);
httpConfigStorage.setStorePassword(STORE_PASSWORD);
httpConfigStorage.setPath(true);
//设置ssl证书对应的存储方式这里默认为文件地址
httpConfigStorage.setCertStoreType(CertStoreType.PATH);
}

View File

@@ -34,9 +34,9 @@ public class ApyAccountRepository {
// TODO 2017/2/9 16:20 author: egan sign_type只有单一key时public_key与private_key相等比如sign_type=MD5的情况
apyAccount1.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIgHnOn7LLILlKETd6BFRJ0GqgS2Y3mn1wMQmyh9zEyWlz5p1zrahRahbXAfCfSqshSNfqOmAQzSHRVjCqjsAw1jyqrXaPdKBmr90DIpIxmIyKXv4GGAkPyJ/6FTFY99uhpiq0qadD/uSzQsefWo0aTvP/65zi3eof7TcZ32oWpwIDAQAB");
apyAccount1.setPrivateKey("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKroe/8h5vC4L6T+B2WdXiVwGsMvUKgb2XsKix6VY3m2wcf6tyzpNRDCNykbIwGtaeo7FshN+qZxdXHLiIam9goYncBit/8ojfLGy2gLxO/PXfzGxYGs0KsDZ+ryVPPmE34ZZ8jiJpR0ygzCFl8pN3QJPJRGTJn5+FTT9EF/9zyZAgMBAAECgYAktngcYC35u7cQXDk+jMVyiVhWYU2ULxdSpPspgLGzrZyG1saOcTIi/XVX8Spd6+B6nmLQeF/FbU3rOeuD8U2clzul2Z2YMbJ0FYay9oVZFfp5gTEFpFRTVfzqUaZQBIjJe/xHL9kQVqc5xHlE/LVA27/Kx3dbC35Y7B4EVBDYAQJBAOhsX8ZreWLKPhXiXHTyLmNKhOHJc+0tFH7Ktise/0rNspojU7o9prOatKpNylp9v6kux7migcMRdVUWWiVe+4ECQQC8PqsuEz7B0yqirQchRg1DbHjh64bw9Kj82EN1/NzOUd53tP9tg+SO97EzsibK1F7tOcuwqsa7n2aY48mQ+y0ZAkBndA2xcRcnvOOjtAz5VO8G7R12rse181HjGfG6AeMadbKg30aeaGCyIxN1loiSfNR5xsPJwibGIBg81mUrqzqBAkB+K6rkaPXJR9XtzvdWb/N3235yPkDlw7Z4MiOVM3RzvR/VMDV7m8lXoeDde2zQyeMOMYy6ztwA6WgE1bhGOnQRAkEAouUBv1sVdSBlsexX15qphOmAevzYrpufKgJIRLFWQxroXMS7FTesj+f+FmGrpPCxIde1dqJ8lqYLTyJmbzMPYw==\n");
apyAccount1.setNotifyUrl("http://pay.egan.in/payBack1.json");
apyAccount1.setNotifyUrl("http://pay.egzosn.com/payBack1.json");
// 无需同步回调可不填
apyAccount1.setReturnUrl("http://pay.egan.in/payBack1.json");
apyAccount1.setReturnUrl("http://pay.egzosn.com/payBack1.json");
apyAccount1.setInputCharset("UTF-8");
apyAccount1.setSeller("2088102169916436");
apyAccount1.setSignType(SignUtils.RSA.name());

View File

@@ -5,6 +5,7 @@ import com.egzosn.pay.ali.api.AliPayService;
import com.egzosn.pay.ali.bean.AliTransactionType;
import com.egzosn.pay.common.api.PayService;
import com.egzosn.pay.common.bean.BasePayType;
import com.egzosn.pay.common.bean.CertStoreType;
import com.egzosn.pay.common.bean.MsgType;
import com.egzosn.pay.common.bean.TransactionType;
import com.egzosn.pay.common.http.HttpConfigStorage;
@@ -51,7 +52,7 @@ public enum PayType implements BasePayType {
//配置的附加参数的使用
configStorage.setAttach(apyAccount.getPayId());
configStorage.setPid(apyAccount.getPartner());
configStorage.setAppId(apyAccount.getAppid());
configStorage.setAppid(apyAccount.getAppid());
configStorage.setKeyPublic(apyAccount.getPublicKey());
configStorage.setKeyPrivate(apyAccount.getPrivateKey());
configStorage.setNotifyUrl(apyAccount.getNotifyUrl());
@@ -103,8 +104,8 @@ public enum PayType implements BasePayType {
// httpConfigStorage.setKeystore(PayType.class.getResourceAsStream("/证书文件"));
httpConfigStorage.setKeystore("证书信息串");
httpConfigStorage.setStorePassword("证书密码");
//是否为证书地址
httpConfigStorage.setPath(false);
//设置ssl证书对应的存储方式这里默认为文件地址
httpConfigStorage.setCertStoreType(CertStoreType.PATH);
return new WxPayService(wxPayConfigStorage, httpConfigStorage);*/
return new WxPayService(wxPayConfigStorage);
}
@@ -179,8 +180,20 @@ public enum PayType implements BasePayType {
UnionPayConfigStorage unionPayConfigStorage = new UnionPayConfigStorage();
unionPayConfigStorage.setMerId(apyAccount.getPartner());
unionPayConfigStorage.setCertSign(true);
unionPayConfigStorage.setKeyPublic(apyAccount.getPublicKey());
unionPayConfigStorage.setKeyPrivate(apyAccount.getPrivateKey());
// unionPayConfigStorage.setKeyPublic(apyAccount.getPublicKey());
// unionPayConfigStorage.setKeyPrivate(apyAccount.getPrivateKey());
//中级证书路径
unionPayConfigStorage.setAcpMiddleCert("D:/certs/acp_test_middle.cer");
//根证书路径
unionPayConfigStorage.setAcpRootCert("D:/certs/acp_test_root.cer");
// 私钥证书路径
unionPayConfigStorage.setKeyPrivateCert("D:/certs/acp_test_sign.pfx");
//私钥证书对应的密码
unionPayConfigStorage.setKeyPrivateCertPwd("000000");
//设置证书对应的存储方式,这里默认为文件地址
unionPayConfigStorage.setCertStoreType(CertStoreType.PATH);
unionPayConfigStorage.setNotifyUrl(apyAccount.getNotifyUrl());
unionPayConfigStorage.setReturnUrl(apyAccount.getReturnUrl());
unionPayConfigStorage.setSignType(apyAccount.getSignType());

View File

@@ -8,22 +8,23 @@
UnionPayConfigStorage unionPayConfigStorage = new UnionPayConfigStorage();
unionPayConfigStorage.setMerId("700000000000001");
//设置CertSign必须在设置证书前
//是否为证书签名
unionPayConfigStorage.setCertSign(true);
//公钥,验签证书链格式: 中级证书路径;根证书路径
// unionPayConfigStorage.setKeyPublic("D:/certs/acp_test_middle.cer;D:/certs/acp_test_root.cer");
//中级证书路径
unionPayConfigStorage.setAcpMiddleCert("D:/certs/acp_test_middle.cer");
unionPayConfigStorage.setAcpMiddleCert("证书文件流,证书字符串信息或证书绝对地址");
//根证书路径
unionPayConfigStorage.setAcpRootCert("D:/certs/acp_test_root.cer");
//私钥, 私钥证书格式: 私钥证书路径;私钥证书对应的密码
// unionPayConfigStorage.setKeyPrivate("D:/certs/acp_test_sign.pfx;000000");
unionPayConfigStorage.setAcpRootCert("证书文件流,证书字符串信息或证书绝对地址");
// 私钥证书路径
unionPayConfigStorage.setKeyPrivateCert("D:/certs/acp_test_sign.pfx");
unionPayConfigStorage.setKeyPrivateCert("证书文件流,证书字符串信息或证书绝对地址");
//私钥证书对应的密码
unionPayConfigStorage.setKeyPrivateCertPwd("000000");
unionPayConfigStorage.setKeyPrivateCertPwd("私钥证书对应的密码");
//设置证书对应的存储方式,这里默认为文件地址
httpConfigStorage.setCertStoreType(CertStoreType.PATH);
unionPayConfigStorage.setNotifyUrl("http://www.pay.egzosn.com/payBack.json");
// 无需同步回调可不填 app填这个就可以
unionPayConfigStorage.setReturnUrl("http://www.pay.egzosn.com/payBack.json");
@@ -48,9 +49,9 @@
//代理端口
httpConfigStorage.setHttpProxyPort(3308);
//代理用户名
httpConfigStorage.setHttpProxyUsername("user");
httpConfigStorage.setAuthUsername("user");
//代理密码
httpConfigStorage.setHttpProxyPassword("password");
httpConfigStorage.setAuthPassword("password");
/* /网路代理配置 根据需求进行设置**/
/* /网络请求连接池**/

View File

@@ -1,6 +1,10 @@
package com.egzosn.pay.union.api;
import com.egzosn.pay.common.api.BasePayConfigStorage;
import com.egzosn.pay.common.bean.CertStoreType;
import java.io.IOException;
import java.io.InputStream;
/**
@@ -32,104 +36,100 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
*/
private String accessType = "0";
/**
* 中级证书路径
*/
private String acpMiddleCert;
/**
* 根证书路径
*/
private String acpRootCert;
/**
* 私钥证书是否已经初始化
* 默认没有
* 应用私钥证书
*/
private boolean keyPrivateInit = false;
private Object keyPrivateCert;
/**
* 公钥证书是否已经初始化
* 默认没有
* 中级证书
*/
private boolean keyPublicInit = false;
private Object acpMiddleCert;
/**
* 根证书
*/
private Object acpRootCert;
/**
* 证书存储类型
*/
private CertStoreType certStoreType;
/**
* 设置私钥证书
*
* @param certificatePath 私钥证书地址
* @param certificate 私钥证书地址 或者证书内容字符串
* 私钥证书密码 {@link #setKeyPrivateCertPwd(String)}
*/
public void setKeyPrivateCert(String certificatePath) {
super.setKeyPrivate(certificatePath);
public void setKeyPrivateCert(String certificate) {
super.setKeyPrivate(certificate);
this.keyPrivateCert = certificate;
}
/**
* 设置私钥证书
*
* @param keyPrivateCert 私钥证书信息流
* 私钥证书密码 {@link #setKeyPrivateCertPwd(String)}
*/
public void setKeyPrivateCert(InputStream keyPrivateCert) {
this.keyPrivateCert = keyPrivateCert;
}
public InputStream getKeyPrivateCertInputStream() throws IOException {
return certStoreType.getInputStream(keyPrivateCert);
}
/**
* 设置中级证书
*
* @param certificatePath 证书地址
* @param acpMiddleCert 证书信息或者证书路径
*/
public void setAcpMiddleCert(String certificatePath) {
this.acpMiddleCert = certificatePath;
public void setAcpMiddleCert(String acpMiddleCert) {
this.acpMiddleCert = acpMiddleCert;
}
/**
* 设置中级证书
*
* @param acpMiddleCert 证书文件
*/
public void setAcpMiddleCert(InputStream acpMiddleCert) {
this.acpMiddleCert = acpMiddleCert;
}
/**
* 设置根证书路径
* 设置根证书
*
* @param certificatePath 证书路径
* @param acpRootCert 证书路径或者证书信息字符串
*/
public void setAcpRootCert(String certificatePath) {
this.acpRootCert = certificatePath;
public void setAcpRootCert(String acpRootCert) {
this.acpRootCert = acpRootCert;
}
/**
* 设置根证书
*
* @param acpRootCert 证书文件流
*/
public void setAcpRootCert(InputStream acpRootCert) {
this.acpRootCert = acpRootCert;
}
public String getAcpMiddleCert() {
return acpMiddleCert;
return (String) acpMiddleCert;
}
public String getAcpRootCert() {
return acpRootCert;
return (String) acpRootCert;
}
public InputStream getAcpMiddleCertInputStream() throws IOException {
return certStoreType.getInputStream(acpMiddleCert);
}
/**
* 设置私钥证书与证书密码
*
* @param keyPrivate 私钥证书与证书对应的密码 格式: D:/certs/acp_test_sign.pfx;000000
* 替代方法
* {@link #setKeyPrivateCert(String)}
* {@link #setKeyPrivateCertPwd(String)}
*/
@Deprecated
@Override
public void setKeyPrivate(String keyPrivate) {
super.setKeyPrivate(keyPrivate);
if (isCertSign() && keyPrivate.length() < 1024 && keyPrivate.contains(";")) {
String[] split = keyPrivate.split(";");
super.setKeyPrivateCertPwd(split[1]);
super.setKeyPrivate(split[0]);
getCertDescriptor().initPrivateSignCert(getKeyPrivate(), getKeyPrivateCertPwd(), "PKCS12");
keyPrivateInit = true;
}
public InputStream getAcpRootCertInputStream() throws IOException {
return certStoreType.getInputStream(acpRootCert);
}
/**
* 设置中级证书与根证书 格式D:/certs/acp_test_middle.cer;D:/certs/acp_test_root.cer
*
* @param keyPublic 中级证书与根证书
* 替代方法
* {@link #setAcpRootCert(String)}
* {@link #setAcpMiddleCert(String)}
*/
@Deprecated
@Override
public void setKeyPublic(String keyPublic) {
super.setKeyPublic(keyPublic);
if (isCertSign() && keyPublic.length() < 1024) {
String[] split = keyPublic.split(";");
getCertDescriptor().initPublicCert(split[0]);
getCertDescriptor().initRootCert(split[1]);
keyPublicInit = true;
}
}
@Override
public String getAppid() {
@@ -199,11 +199,15 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
this.accessType = accessType;
}
public boolean isKeyPrivateInit() {
return keyPrivateInit;
/**
* 证书存储类型
* @return 证书存储类型
*/
public CertStoreType getCertStoreType() {
return certStoreType;
}
public boolean isKeyPublicInit() {
return keyPublicInit;
public void setCertStoreType(CertStoreType certStoreType) {
this.certStoreType = certStoreType;
}
}

View File

@@ -21,6 +21,7 @@ import com.egzosn.pay.union.bean.UnionTransactionType;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.security.cert.*;
@@ -55,7 +56,10 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
private static final String FILE_TRANS_URL = "https://filedownload.%s/";
private static final String APP_TRANS_URL = "https://gateway.%s/gateway/api/appTransReq.do";
private static final String CARD_TRANS_URL = "https://gateway.%s/gateway/api/cardTransReq.do";
/**
* 证书解释器
*/
private CertDescriptor certDescriptor = new CertDescriptor();
/**
* 构造函数
*
@@ -81,15 +85,15 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
if (!payConfigStorage.isCertSign()) {
return this;
}
CertDescriptor certDescriptor = payConfigStorage.getCertDescriptor();
if (!payConfigStorage.isKeyPrivateInit()) {
certDescriptor.initPrivateSignCert(payConfigStorage.getKeyPrivate(), payConfigStorage.getKeyPrivateCertPwd(), "PKCS12");
}
if (!payConfigStorage.isKeyPublicInit()) {
certDescriptor.initPublicCert(payConfigStorage.getAcpMiddleCert());
certDescriptor.initRootCert(payConfigStorage.getAcpRootCert());
try {
certDescriptor.initPrivateSignCert(payConfigStorage.getKeyPrivateCertInputStream(), payConfigStorage.getKeyPrivateCertPwd(), "PKCS12");
certDescriptor.initPublicCert(payConfigStorage.getAcpMiddleCertInputStream());
certDescriptor.initRootCert(payConfigStorage.getAcpRootCertInputStream());
} catch (IOException e) {
LOG.error(e);
}
return this;
}
@@ -127,7 +131,7 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
*/
private Map<String, Object> getCommonParam() {
Map<String, Object> params = new TreeMap<>();
UnionPayConfigStorage configStorage = (UnionPayConfigStorage) payConfigStorage;
UnionPayConfigStorage configStorage = payConfigStorage;
//银联接口版本
params.put(SDKConstants.param_version, configStorage.getVersion());
//编码方式
@@ -291,15 +295,15 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
switch (signUtils) {
case RSA:
parameters.put(SDKConstants.param_signMethod, SDKConstants.SIGNMETHOD_RSA);
parameters.put(SDKConstants.param_certId, payConfigStorage.getCertDescriptor().getSignCertId());
parameters.put(SDKConstants.param_certId, certDescriptor.getSignCertId());
signStr = SignUtils.SHA1.createSign(SignUtils.parameterText(parameters, "&", "signature"), "", payConfigStorage.getInputCharset());
parameters.put(SDKConstants.param_signature, RSA.sign(signStr, payConfigStorage.getCertDescriptor().getSignCertPrivateKey(payConfigStorage.getKeyPrivateCertPwd()), payConfigStorage.getInputCharset()));
parameters.put(SDKConstants.param_signature, RSA.sign(signStr, certDescriptor.getSignCertPrivateKey(payConfigStorage.getKeyPrivateCertPwd()), payConfigStorage.getInputCharset()));
break;
case RSA2:
parameters.put(SDKConstants.param_signMethod, SDKConstants.SIGNMETHOD_RSA);
parameters.put(SDKConstants.param_certId, payConfigStorage.getCertDescriptor().getSignCertId());
parameters.put(SDKConstants.param_certId, certDescriptor.getSignCertId());
signStr = SignUtils.SHA256.createSign(SignUtils.parameterText(parameters, "&", "signature"), "", payConfigStorage.getInputCharset());
parameters.put(SDKConstants.param_signature, RSA2.sign(signStr, payConfigStorage.getCertDescriptor().getSignCertPrivateKey(payConfigStorage.getKeyPrivateCertPwd()), payConfigStorage.getInputCharset()));
parameters.put(SDKConstants.param_signature, RSA2.sign(signStr, certDescriptor.getSignCertPrivateKey(payConfigStorage.getKeyPrivateCertPwd()), payConfigStorage.getInputCharset()));
break;
case SHA1:
case SHA256:
@@ -326,8 +330,8 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
private X509Certificate verifyCertificate(X509Certificate cert) {
try {
cert.checkValidity();//验证有效期
X509Certificate middleCert = payConfigStorage.getCertDescriptor().getPublicCert();
X509Certificate rootCert = payConfigStorage.getCertDescriptor().getRootCert();
X509Certificate middleCert = certDescriptor.getPublicCert();
X509Certificate rootCert = certDescriptor.getRootCert();
X509CertSelector selector = new X509CertSelector();
selector.setCertificate(cert);

View File

@@ -29,9 +29,9 @@
//代理端口
httpConfigStorage.setHttpProxyPort(3308);
//代理用户名
httpConfigStorage.setHttpProxyUsername("user");
httpConfigStorage.setAuthUsername("user");
//代理密码
httpConfigStorage.setHttpProxyPassword("password");
httpConfigStorage.setAuthPassword("password");
/* /网路代理配置 根据需求进行设置**/
//退款使用
@@ -39,9 +39,12 @@
//设置ssl证书路径
//TODO 这里也支持输入流的入参。
// httpConfigStorage.setKeystore(this.getClass()..getResourceAsStream("/证书文件"));
httpConfigStorage.setKeystorePath("证书绝对路径");
//设置ssl证书路径 跟着setCertStoreType 进行对应
httpConfigStorage.setKeystore("证书文件流,证书字符串信息或证书绝对地址");
//设置ssl证书对应的密码
httpConfigStorage.setStorePassword("证书对应的密码");
//设置ssl证书对应的存储方式
httpConfigStorage.setCertStoreType(CertStoreType.PATH);
/* /网络请求ssl证书**/
/* /网络请求连接池**/
//最大连接数