File tree Expand file tree Collapse file tree 2 files changed +23
-16
lines changed
main/java/com/github/binarywang/wxpay/config
test/java/com/github/binarywang/wxpay/config Expand file tree Collapse file tree 2 files changed +23
-16
lines changed Original file line number Diff line number Diff line change 11package com .github .binarywang .wxpay .config ;
22
3- import java .io .ByteArrayInputStream ;
4- import java .io .File ;
5- import java .io .FileInputStream ;
6- import java .io .IOException ;
7- import java .io .InputStream ;
8- import java .security .KeyStore ;
9- import javax .net .ssl .SSLContext ;
10-
3+ import com .github .binarywang .wxpay .exception .WxPayException ;
4+ import lombok .Data ;
115import org .apache .commons .io .IOUtils ;
126import org .apache .commons .lang3 .StringUtils ;
137import org .apache .http .ssl .SSLContexts ;
148
15- import com .github .binarywang .wxpay .exception .WxPayException ;
16- import lombok .Data ;
9+ import javax .net .ssl .SSLContext ;
10+ import java .io .*;
11+ import java .net .URL ;
12+ import java .security .KeyStore ;
1713
1814/**
1915 * 微信支付配置
@@ -131,6 +127,15 @@ public SSLContext initSSLContext() throws WxPayException {
131127 if (inputStream == null ) {
132128 throw new WxPayException (fileNotFoundMsg );
133129 }
130+ } else if (this .getKeyPath ().startsWith ("http://" ) || this .getKeyPath ().startsWith ("https://" )) {
131+ try {
132+ inputStream = new URL (this .keyPath ).openStream ();
133+ if (inputStream == null ) {
134+ throw new WxPayException (fileNotFoundMsg );
135+ }
136+ } catch (IOException e ) {
137+ throw new WxPayException (fileNotFoundMsg , e );
138+ }
134139 } else {
135140 try {
136141 File file = new File (this .getKeyPath ());
Original file line number Diff line number Diff line change 1414public class WxPayConfigTest {
1515 private WxPayConfig payConfig = new WxPayConfig ();
1616
17- /**
18- * Test init ssl context.
19- *
20- * @throws Exception the exception
21- */
2217 @ Test
23- public void testInitSSLContext () throws Exception {
18+ public void testInitSSLContext_classpath () throws Exception {
2419 payConfig .setMchId ("123" );
2520 payConfig .setKeyPath ("classpath:/abc.p12" );
2621 payConfig .initSSLContext ();
2722 }
2823
24+ @ Test
25+ public void testInitSSLContext_http () throws Exception {
26+ payConfig .setMchId ("123" );
27+ payConfig .setKeyPath ("https://www.baidu.com" );
28+ payConfig .initSSLContext ();
29+ }
30+
2931}
You can’t perform that action at this time.
0 commit comments