From 9e178e06731b4e5eabb57862dc288e88b4d11a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 17 Nov 2020 11:11:22 +0800 Subject: [PATCH] wx --- platformapi/wxpayapi/wxpayapi.go | 6 +++++- platformapi/wxpayapi/wxpayapi_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/platformapi/wxpayapi/wxpayapi.go b/platformapi/wxpayapi/wxpayapi.go index 8de94a1c..297b3a21 100644 --- a/platformapi/wxpayapi/wxpayapi.go +++ b/platformapi/wxpayapi/wxpayapi.go @@ -6,6 +6,7 @@ import ( "crypto/md5" "crypto/sha256" "crypto/tls" + "crypto/x509" "encoding/xml" "fmt" "net/http" @@ -396,7 +397,7 @@ func New(appID, appKey, mchID string, config ...*platformapi.APIConfig) *API { } } -func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock interface{}, config ...*platformapi.APIConfig) (a *API) { +func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock, rootCa interface{}, config ...*platformapi.APIConfig) (a *API) { var certs tls.Certificate var err error if binCertPEMBlock, ok := certPEMBlock.([]byte); ok { @@ -405,9 +406,12 @@ func NewWithCertificate(appID, appKey, mchID string, certPEMBlock, keyPEMBlock i certs, err = tls.LoadX509KeyPair(certPEMBlock.(string), keyPEMBlock.(string)) } if err == nil { + pool := x509.NewCertPool() + pool.AppendCertsFromPEM(rootCa.([]byte)) a = New(appID, appKey, mchID, config...) a.client.Transport = &http.Transport{ TLSClientConfig: &tls.Config{ + RootCAs: pool, Certificates: []tls.Certificate{certs}, }, } diff --git a/platformapi/wxpayapi/wxpayapi_test.go b/platformapi/wxpayapi/wxpayapi_test.go index 10404e15..2f23e5c9 100644 --- a/platformapi/wxpayapi/wxpayapi_test.go +++ b/platformapi/wxpayapi/wxpayapi_test.go @@ -23,7 +23,7 @@ func init() { baseapi.Init(sugarLogger) certPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_cert.pem") keyPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_key.pem") - api = NewWithCertificate("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702", certPEMBlock, keyPEMBlock) + api = NewWithCertificate("wx70d0943e61e0d15c", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1603491062", certPEMBlock, keyPEMBlock, nil) // api = New("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702") } @@ -131,11 +131,11 @@ func TestTransfers(t *testing.T) { orderNo := utils.GetUUID() result, err := api.Transfers(&TransfersParam{ PartnerTradeNo: orderNo, - OpenID: "ojWb10M_8kV8NT0aZJa6A5umG1c8", + OpenID: "o2dL05DjZggIr2nStjgHWa9oqQBc", CheckName: "NO_CHECK", - Amount: 100, + Amount: 1, Desc: "测试", - SpbillCreateIP: "114.114.114.114", + SpbillCreateIP: "171.217.98.243", }) if err != nil { t.Fatal(err)