You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.0 KiB
49 lines
1.0 KiB
package pay_service
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"crypto/x509"
|
|
"fmt"
|
|
"github.com/chanxuehong/wechat/mch/core"
|
|
"hudongzhuanjia/utils/define"
|
|
"net/http"
|
|
)
|
|
|
|
// 配置 client
|
|
func Client() (*core.Client, error) {
|
|
|
|
certP12, err := Asset("cacert/apiclient_cert.p12")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
certPem, err := Asset("cacert/apiclient_cert.pem")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
keyPem, err := Asset("cacert/apiclient_key.pem")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pkcsPool := x509.NewCertPool()
|
|
pkcsPool.AppendCertsFromPEM(certP12)
|
|
certificate, err := tls.X509KeyPair(certPem, keyPem)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("tls.LoadX509KeyPair:%s", err)
|
|
}
|
|
|
|
tlsConfig := &tls.Config{
|
|
Certificates: []tls.Certificate{certificate},
|
|
RootCAs: pkcsPool,
|
|
InsecureSkipVerify: true,
|
|
}
|
|
|
|
httpClient := &http.Client{
|
|
Transport: &http.Transport{
|
|
TLSClientConfig: tlsConfig,
|
|
DisableKeepAlives: true,
|
|
},
|
|
}
|
|
|
|
return core.NewSubMchClient(define.AppId, define.MchId, define.ApiKey, "", define.SubMchId, httpClient), nil
|
|
}
|