This commit is contained in:
苏尹岚
2020-11-17 11:15:57 +08:00
parent 9e178e0673
commit 3e870f57a1
2 changed files with 5 additions and 6 deletions

View File

@@ -6,7 +6,6 @@ import (
"crypto/md5"
"crypto/sha256"
"crypto/tls"
"crypto/x509"
"encoding/xml"
"fmt"
"net/http"
@@ -397,7 +396,7 @@ func New(appID, appKey, mchID string, config ...*platformapi.APIConfig) *API {
}
}
func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock, rootCa interface{}, config ...*platformapi.APIConfig) (a *API) {
func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock interface{}, config ...*platformapi.APIConfig) (a *API) {
var certs tls.Certificate
var err error
if binCertPEMBlock, ok := certPEMBlock.([]byte); ok {
@@ -406,12 +405,12 @@ func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock,
certs, err = tls.LoadX509KeyPair(certPEMBlock.(string), keyPEMBlock.(string))
}
if err == nil {
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(rootCa.([]byte))
// pool := x509.NewCertPool()
// pool.AppendCertsFromPEM(rootCa.([]byte))
a = New(appID, appKey, mchID, config...)
a.client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: pool,
// RootCAs: pool,
Certificates: []tls.Certificate{certs},
},
}