mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-31 04:49:54 +08:00
将证书等设置方式分开,便于使用者更容易使用
This commit is contained in:
@@ -19,8 +19,6 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
*/
|
||||
private volatile String merId;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 商户收款账号
|
||||
*/
|
||||
@@ -34,19 +32,89 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
*/
|
||||
private volatile String accessType = "0";
|
||||
|
||||
/**
|
||||
* 中级证书路径
|
||||
*/
|
||||
private String acpMiddleCert;
|
||||
/**
|
||||
* 根证书路径
|
||||
*/
|
||||
private String acpRootCert;
|
||||
|
||||
/**
|
||||
* 私钥证书是否已经初始化
|
||||
* 默认没有
|
||||
*/
|
||||
private boolean keyPrivateInit = false;
|
||||
|
||||
/**
|
||||
* 公钥证书是否已经初始化
|
||||
* 默认没有
|
||||
*/
|
||||
private boolean keyPublicInit = false;
|
||||
|
||||
|
||||
/**
|
||||
* 设置私钥证书
|
||||
* @param certificatePath 私钥证书地址
|
||||
* 私钥证书密码 {@link #setKeyPrivateCertPwd(String)}
|
||||
*/
|
||||
public void setKeyPrivateCert(String certificatePath){
|
||||
super.setKeyPrivate(certificatePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置中级证书
|
||||
* @param certificatePath 证书地址
|
||||
*/
|
||||
public void setAcpMiddleCert(String certificatePath){
|
||||
this.acpMiddleCert = certificatePath;
|
||||
}
|
||||
/**
|
||||
* 设置根证书路径
|
||||
* @param certificatePath 证书路径
|
||||
*/
|
||||
public void setAcpRootCert(String certificatePath){
|
||||
this.acpRootCert = certificatePath;
|
||||
}
|
||||
|
||||
public String getAcpMiddleCert() {
|
||||
return acpMiddleCert;
|
||||
}
|
||||
|
||||
public String getAcpRootCert() {
|
||||
return acpRootCert;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 设置私钥证书与证书密码
|
||||
* @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(";");
|
||||
setKeyPrivateCertPwd( split[1]);
|
||||
super.setKeyPrivateCertPwd( split[1]);
|
||||
super.setKeyPrivate(split[0]);
|
||||
getCertDescriptor().initPrivateSignCert(getKeyPrivate(), getKeyPrivateCertPwd(), "PKCS12");
|
||||
keyPrivateInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置中级证书与根证书 格式: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);
|
||||
@@ -54,11 +122,12 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
String[] split = keyPublic.split(";");
|
||||
getCertDescriptor().initPublicCert(split[0]);
|
||||
getCertDescriptor().initRootCert(split[1]);
|
||||
keyPublicInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppid () {
|
||||
public String getAppid() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -67,7 +136,7 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
* @see #getPid()
|
||||
*/
|
||||
@Deprecated
|
||||
public String getPartner () {
|
||||
public String getPartner() {
|
||||
return merId;
|
||||
}
|
||||
|
||||
@@ -79,12 +148,12 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
* @see #setPid(String)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPartner (String partner) {
|
||||
public void setPartner(String partner) {
|
||||
this.merId = partner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPid () {
|
||||
public String getPid() {
|
||||
return merId;
|
||||
}
|
||||
|
||||
@@ -92,7 +161,7 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
this.merId = pid;
|
||||
}
|
||||
@Override
|
||||
public String getSeller () {
|
||||
public String getSeller() {
|
||||
return seller;
|
||||
}
|
||||
|
||||
@@ -100,7 +169,7 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
this.seller = seller;
|
||||
}
|
||||
|
||||
public String getMerId () {
|
||||
public String getMerId() {
|
||||
return merId;
|
||||
}
|
||||
|
||||
@@ -123,4 +192,12 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
public void setAccessType(String accessType) {
|
||||
this.accessType = accessType;
|
||||
}
|
||||
|
||||
public boolean isKeyPrivateInit() {
|
||||
return keyPrivateInit;
|
||||
}
|
||||
|
||||
public boolean isKeyPublicInit() {
|
||||
return keyPublicInit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.egzosn.pay.union.api;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.egzosn.pay.common.api.BasePayService;
|
||||
import com.egzosn.pay.common.api.Callback;
|
||||
import com.egzosn.pay.common.api.PayConfigStorage;
|
||||
import com.egzosn.pay.common.bean.*;
|
||||
import com.egzosn.pay.common.bean.outbuilder.PayTextOutMessage;
|
||||
import com.egzosn.pay.common.bean.result.PayException;
|
||||
@@ -11,6 +9,7 @@ import com.egzosn.pay.common.exception.PayErrorException;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.http.UriVariables;
|
||||
import com.egzosn.pay.common.util.MatrixToImageWriter;
|
||||
import com.egzosn.pay.common.util.sign.CertDescriptor;
|
||||
import com.egzosn.pay.common.util.sign.SignUtils;
|
||||
import com.egzosn.pay.common.util.sign.encrypt.RSA;
|
||||
import com.egzosn.pay.common.util.sign.encrypt.RSA2;
|
||||
@@ -35,7 +34,7 @@ import java.util.*;
|
||||
* create 2017 2017/11/5
|
||||
* </pre>
|
||||
*/
|
||||
public class UnionPayService extends BasePayService {
|
||||
public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
private static final Log log = LogFactory.getLog(UnionPayService.class);
|
||||
/**
|
||||
* 测试域名
|
||||
@@ -64,15 +63,35 @@ public class UnionPayService extends BasePayService {
|
||||
* 构造函数
|
||||
* @param payConfigStorage 支付配置
|
||||
*/
|
||||
public UnionPayService (PayConfigStorage payConfigStorage) {
|
||||
public UnionPayService (UnionPayConfigStorage payConfigStorage) {
|
||||
super(payConfigStorage);
|
||||
}
|
||||
|
||||
public UnionPayService (PayConfigStorage payConfigStorage, HttpConfigStorage configStorage) {
|
||||
public UnionPayService (UnionPayConfigStorage payConfigStorage, HttpConfigStorage configStorage) {
|
||||
super(payConfigStorage, configStorage);
|
||||
|
||||
}
|
||||
/**
|
||||
* 设置支付配置
|
||||
* @param payConfigStorage 支付配置
|
||||
*/
|
||||
@Override
|
||||
public UnionPayService setPayConfigStorage(UnionPayConfigStorage payConfigStorage) {
|
||||
super.setPayConfigStorage(payConfigStorage);
|
||||
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());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 根据是否为沙箱环境进行获取请求地址
|
||||
*
|
||||
@@ -182,7 +201,7 @@ public class UnionPayService extends BasePayService {
|
||||
* @return true通过
|
||||
*/
|
||||
@Override
|
||||
public boolean verifySource (String id) {
|
||||
public boolean verifySource(String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -194,7 +213,7 @@ public class UnionPayService extends BasePayService {
|
||||
* @see PayOrder 支付订单信息
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> orderInfo (PayOrder order) {
|
||||
public Map<String, Object> orderInfo(PayOrder order) {
|
||||
Map<String, Object> params = this.getCommonParam();
|
||||
|
||||
UnionTransactionType type = (UnionTransactionType)order.getTransactionType();
|
||||
|
||||
Reference in New Issue
Block a user