wxpay.NewWithCertificate支持文件名与二进制流
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user