Skip to content

Commit 6da1854

Browse files
committed
支付宝证书实现
1 parent fb477c3 commit 6da1854

12 files changed

Lines changed: 3360 additions & 139 deletions

File tree

pay-java-ali/src/main/java/com/egzosn/pay/ali/api/AliPayConfigStorage.java

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
package com.egzosn.pay.ali.api;
22

3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
6+
import com.egzosn.pay.ali.bean.CertEnvironment;
37
import com.egzosn.pay.common.api.BasePayConfigStorage;
8+
import com.egzosn.pay.common.api.CertStore;
9+
import com.egzosn.pay.common.bean.result.PayException;
10+
import com.egzosn.pay.common.exception.PayErrorException;
411

512
/**
613
* 支付配置存储
714
*
815
* @author egan
9-
* <p>
10-
* email egzosn@gmail.com
11-
* date 2016-5-18 14:09:01
16+
* <p>
17+
* email egzosn@gmail.com
18+
* date 2016-5-18 14:09:01
19+
*
20+
*
21+
* 以下证书签名相关触发前提是 {@link BasePayConfigStorage#isCertSign}等于true的情况。不然走的就是普通的方式
1222
*/
1323
public class AliPayConfigStorage extends BasePayConfigStorage {
1424

25+
/**
26+
* ISV代商户代用,指定appAuthToken
27+
*/
28+
private String appAuthToken;
1529
/**
1630
* 商户应用id
1731
*/
@@ -27,6 +41,39 @@ public class AliPayConfigStorage extends BasePayConfigStorage {
2741
private String seller;
2842

2943

44+
/**
45+
* 应用公钥证书
46+
*/
47+
private Object merchantCert;
48+
49+
/**
50+
* 支付宝公钥证书
51+
*/
52+
private Object aliPayCert;
53+
/**
54+
* 支付宝CA证书,根证书
55+
*/
56+
private Object aliPayRootCert;
57+
58+
/**
59+
* 证书存储类型
60+
*/
61+
private CertStore certStoreType;
62+
63+
/**
64+
* 证书信息
65+
*/
66+
private CertEnvironment certEnvironment;
67+
68+
69+
public String getAppAuthToken() {
70+
return appAuthToken;
71+
}
72+
73+
public void setAppAuthToken(String appAuthToken) {
74+
this.appAuthToken = appAuthToken;
75+
}
76+
3077
public void setAppid(String appid) {
3178
this.appid = appid;
3279
}
@@ -55,5 +102,61 @@ public void setSeller(String seller) {
55102
this.seller = seller;
56103
}
57104

105+
public Object getMerchantCert() {
106+
return merchantCert;
107+
}
108+
109+
public void setMerchantCert(Object merchantCert) {
110+
this.merchantCert = merchantCert;
111+
}
112+
113+
public Object getAliPayCert() {
114+
return aliPayCert;
115+
}
116+
117+
public void setAliPayCert(Object aliPayCert) {
118+
this.aliPayCert = aliPayCert;
119+
}
120+
121+
public Object getAliPayRootCert() {
122+
return aliPayRootCert;
123+
}
124+
125+
public void setAliPayRootCert(Object aliPayRootCert) {
126+
this.aliPayRootCert = aliPayRootCert;
127+
}
128+
129+
public CertStore getCertStoreType() {
130+
return certStoreType;
131+
}
132+
133+
public void setCertStoreType(CertStore certStoreType) {
134+
this.certStoreType = certStoreType;
135+
}
136+
137+
public CertEnvironment getCertEnvironment() {
138+
return certEnvironment;
139+
}
140+
141+
public void setCertEnvironment(CertEnvironment certEnvironment) {
142+
this.certEnvironment = certEnvironment;
143+
}
144+
145+
/**
146+
* 初始化证书信息
147+
*/
148+
public void loadCertEnvironment() {
149+
if (!isCertSign() || null == this.certEnvironment){
150+
return;
151+
}
152+
try (InputStream merchantCertStream = certStoreType.getInputStream(merchantCert);
153+
InputStream aliPayCertStream = certStoreType.getInputStream(aliPayCert);
154+
InputStream aliPayRootCertStream = certStoreType.getInputStream(aliPayRootCert)) {
155+
this.certEnvironment = new CertEnvironment(merchantCertStream, aliPayCertStream, aliPayRootCertStream);
156+
} catch (IOException e) {
157+
throw new PayErrorException(new PayException("读取证书异常", e.getMessage()));
158+
}
159+
}
160+
58161

59162
}

0 commit comments

Comments
 (0)