互动
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.

48 lines
989 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package pay_service
  2. import (
  3. "crypto/tls"
  4. "crypto/x509"
  5. "fmt"
  6. "github.com/chanxuehong/wechat/mch/core"
  7. "net/http"
  8. )
  9. // 配置 client
  10. func Client() (*core.Client, error) {
  11. certP12, err := Asset("cacert/apiclient_cert.p12")
  12. if err != nil {
  13. return nil, err
  14. }
  15. certPem, err := Asset("cacert/apiclient_cert.pem")
  16. if err != nil {
  17. return nil, err
  18. }
  19. keyPem, err := Asset("cacert/apiclient_key.pem")
  20. if err != nil {
  21. return nil, err
  22. }
  23. pkcsPool := x509.NewCertPool()
  24. pkcsPool.AppendCertsFromPEM(certP12)
  25. certificate, err := tls.X509KeyPair(certPem, keyPem)
  26. if err != nil {
  27. return nil, fmt.Errorf("tls.LoadX509KeyPair:%s", err)
  28. }
  29. tlsConfig := &tls.Config{
  30. Certificates: []tls.Certificate{certificate},
  31. RootCAs: pkcsPool,
  32. InsecureSkipVerify: true,
  33. }
  34. httpClient := &http.Client{
  35. Transport: &http.Transport{
  36. TLSClientConfig: tlsConfig,
  37. DisableKeepAlives: true,
  38. },
  39. }
  40. return core.NewClient(Appid, Mchid, ApiKey, httpClient), nil
  41. }