@@ -158,18 +158,27 @@ public SSLContext initSSLContext() throws WxPayException {
158158
159159 InputStream inputStream ;
160160 final String prefix = "classpath:" ;
161+ String fileHasProblemMsg = "证书文件【" + this .keyPath + "】有问题,请核实!" ;
162+ String fileNotFoundMsg = "证书文件【" + this .keyPath + "】不存在,请核实!" ;
161163 if (this .keyPath .startsWith (prefix )) {
162- inputStream = WxPayConfig .class .getResourceAsStream (this .keyPath .replace (prefix , "" ));
164+ String path = StringUtils .removeFirst (this .keyPath , prefix );
165+ if (!path .startsWith ("/" )) {
166+ path = "/" + path ;
167+ }
168+ inputStream = WxPayConfig .class .getResourceAsStream (path );
169+ if (inputStream == null ) {
170+ throw new WxPayException (fileNotFoundMsg );
171+ }
163172 } else {
164173 try {
165174 File file = new File (this .keyPath );
166175 if (!file .exists ()) {
167- throw new WxPayException ("证书文件【" + file . getPath () + "】不存在!" );
176+ throw new WxPayException (fileNotFoundMsg );
168177 }
169178
170179 inputStream = new FileInputStream (file );
171180 } catch (IOException e ) {
172- throw new WxPayException ("证书文件有问题,请核实!" , e );
181+ throw new WxPayException (fileHasProblemMsg , e );
173182 }
174183 }
175184
@@ -180,7 +189,7 @@ public SSLContext initSSLContext() throws WxPayException {
180189 this .sslContext = SSLContexts .custom ().loadKeyMaterial (keystore , partnerId2charArray ).build ();
181190 return this .sslContext ;
182191 } catch (Exception e ) {
183- throw new WxPayException ("证书文件有问题,请核实!" , e );
192+ throw new WxPayException (fileHasProblemMsg , e );
184193 } finally {
185194 IOUtils .closeQuietly (inputStream );
186195 }
0 commit comments