微信支付付款接口 Golang 如何添加https证书
我添加方法如下,但是请求一直报这个错误,确认了证书是没问题的。 CA_ERROR 证书出错,请登录微信支付商户平台下载证书
代码如下: transport := &http.Transport{
DialContext: (&net.Dialer{
Timeout: 500 * time.MillSecond,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: gConf.HTTP.MaxIdelConns,
IdleConnTimeout: 3 * time.Minute,
TLSHandshakeTimeout: 3 * time.Second,
MaxIdleConnsPerHost: gConf.HTTP.MaxIdelConns,
}
certP12, err := ioutil.ReadFile("apiclient_cert.p12")
if err != nil {
panic(err)
}
blocks, err := pkcs12.ToPEM(certP12, "100000001")
if err != nil {
panic(err)
}
var pemData []byte
for _, b := range blocks {
pemData = append(pemData, pem.EncodeToMemory(b)...)
}
cert, err := tls.X509KeyPair(pemData, pemData)
if err != nil {
panic(err)
}
transport.TLSClientConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
}
httpClient := &http.Client{Transport: transport}
}