@@ -270,6 +270,7 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
270
270
if (objects != null ) {
271
271
merchantPrivateKey = (PrivateKey ) objects [0 ];
272
272
certificate = (X509Certificate ) objects [1 ];
273
+ this .certSerialNo = certificate .getSerialNumber ().toString (16 ).toUpperCase ();
273
274
}
274
275
try {
275
276
if (merchantPrivateKey == null ) {
@@ -405,38 +406,24 @@ private InputStream loadConfigInputStream(String configPath) throws WxPayExcepti
405
406
}
406
407
}
407
408
408
- /**
409
- * 从配置路径 加载p12证书文件流
410
- *
411
- * @return 文件流
412
- */
413
- private InputStream loadP12InputStream () {
414
- try (InputStream inputStream = this .loadConfigInputStream (this .keyString , this .getKeyPath (),
415
- this .keyContent , "p12证书" );) {
416
- return inputStream ;
417
- } catch (Exception e ) {
418
- return null ;
419
- }
420
- }
421
-
422
409
/**
423
410
* 分解p12证书文件
424
411
*
425
412
* @return
426
413
*/
427
414
private Object [] p12ToPem () {
428
- InputStream inputStream = this .loadP12InputStream ();
429
- if (inputStream == null ) {
430
- return null ;
431
- }
432
415
String key = getMchId ();
433
416
if (StringUtils .isBlank (key )) {
434
417
return null ;
435
418
}
436
419
// 分解p12证书文件
437
420
PrivateKey privateKey = null ;
438
421
X509Certificate x509Certificate = null ;
439
- try {
422
+ try (InputStream inputStream = this .loadConfigInputStream (this .keyString , this .getKeyPath (),
423
+ this .keyContent , "p12证书" );){
424
+ if (inputStream == null ) {
425
+ return null ;
426
+ }
440
427
KeyStore keyStore = KeyStore .getInstance ("PKCS12" );
441
428
keyStore .load (inputStream , key .toCharArray ());
442
429
@@ -446,8 +433,8 @@ private Object[] p12ToPem() {
446
433
Certificate certificate = keyStore .getCertificate (alias );
447
434
x509Certificate = (X509Certificate ) certificate ;
448
435
return new Object []{privateKey , x509Certificate };
449
- } catch (Exception ignored ) {
450
-
436
+ } catch (Exception e ) {
437
+ e . printStackTrace ();
451
438
}
452
439
return null ;
453
440
0 commit comments