Skip to content

Commit

Permalink
update method
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Oct 24, 2024
1 parent 834105f commit 7485422
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ require (
github.com/go-pay/util v0.0.4
github.com/go-pay/xlog v0.0.3
github.com/go-pay/xtime v0.0.2
golang.org/x/crypto v0.27.0
golang.org/x/crypto v0.28.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ github.com/go-pay/xlog v0.0.3 h1:avyMhCL/JgBHreoGx/am/kHxfs1udDOAeVqbmzP/Yes=
github.com/go-pay/xlog v0.0.3/go.mod h1:mH47xbobrdsSHWsmFtSF5agWbMHFP+tK0ZbVCk5OAEw=
github.com/go-pay/xtime v0.0.2 h1:7YR4/iuELsEHpJ6LUO0SVK80hQxDO9MLCfuVYIiTCRM=
github.com/go-pay/xtime v0.0.2/go.mod h1:W1yRbJaSt4CSBcdAtLBQ8xajiN/Pl5hquGczUcUE9xE=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
13 changes: 10 additions & 3 deletions pkg/xhttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ func NewClient() (client *Client) {
return defaultClient()
}

func (c *Client) SetTransport(transport *http.Transport) (client *Client) {
func (c *Client) SetTransport(transport http.RoundTripper) (client *Client) {
c.HttpClient.Transport = transport
return c
}

func (c *Client) SetTLSConfig(tlsCfg *tls.Config) (client *Client) {
c.HttpClient.Transport.(*http.Transport).TLSClientConfig = tlsCfg
func (c *Client) SetHttpTransport(transport *http.Transport) (client *Client) {
c.HttpClient.Transport = transport
return c
}

func (c *Client) SetHttpTLSConfig(tlsCfg *tls.Config) (client *Client) {
if ht, ok := c.HttpClient.Transport.(*http.Transport); ok {
ht.TLSClientConfig = tlsCfg
}
return c
}

Expand Down
2 changes: 1 addition & 1 deletion qq/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (q *Client) PostQQAPISelf(ctx context.Context, bm gopay.BodyMap, url string
}
httpClient := xhttp.NewClient()
if q.IsProd && tlsConfig != nil {
httpClient.SetTLSConfig(tlsConfig)
httpClient.SetHttpTLSConfig(tlsConfig)
}
res, bs, err := httpClient.Req(xhttp.TypeXML).Post(url).SendString(req).EndBytes(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion qq/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (q *Client) AddCertFilePath(certFilePath, keyFilePath, pkcs12FilePath any)
if err != nil {
return
}
q.tlsHc.SetTLSConfig(config)
q.tlsHc.SetHttpTLSConfig(config)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion wechat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (w *Client) doProdPostSelf(ctx context.Context, bm gopay.BodyMap, path stri
}
httpClient := xhttp.NewClient()
if w.IsProd && tlsConfig != nil {
httpClient.SetTLSConfig(tlsConfig)
httpClient.SetHttpTLSConfig(tlsConfig)
}
res, bs, err := httpClient.Req(xhttp.TypeXML).Post(url).SendString(req).EndBytes(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion wechat/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (w *Client) addCertFileContentOrPath(certFile, keyFile, pkcs12File any) (er
if err != nil {
return
}
w.tlsHc.SetTLSConfig(config)
w.tlsHc.SetHttpTLSConfig(config)
return
}

Expand Down

0 comments on commit 7485422

Please sign in to comment.