From 3f8d69090a3a102ae1fa8a040a65ba34bc304650 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 21 Nov 2019 09:44:47 +0800 Subject: [PATCH] =?UTF-8?q?wxpay.NewWithCertificate=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E4=B8=8E=E4=BA=8C=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/wxpay/wxpay.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/platformapi/wxpay/wxpay.go b/platformapi/wxpay/wxpay.go index 8dcb64ee..afee6dd1 100644 --- a/platformapi/wxpay/wxpay.go +++ b/platformapi/wxpay/wxpay.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/utils" "github.com/clbanning/mxj" @@ -224,8 +225,14 @@ func New(appID, appKey, mchID string, config ...*platformapi.APIConfig) *API { } } -func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock []byte, config ...*platformapi.APIConfig) (a *API) { - certs, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock) +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 { + certs, err = tls.X509KeyPair(binCertPEMBlock, keyPEMBlock.([]byte)) + } else { + certs, err = tls.LoadX509KeyPair(certPEMBlock.(string), keyPEMBlock.(string)) + } if err == nil { a = New(appID, appKey, mchID, config...) a.client.Transport = &http.Transport{ @@ -233,6 +240,8 @@ func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock [ Certificates: []tls.Certificate{certs}, }, } + } else { + baseapi.SugarLogger.Warnf("NewWithCertificate failed with err:%v", err) } return a }