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

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
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. "hudongzhuanjia/utils/define"
  8. "net/http"
  9. )
  10. // 配置 client
  11. func Client() (*core.Client, error) {
  12. certP12, err := Asset("cacert/apiclient_cert.p12")
  13. if err != nil {
  14. return nil, err
  15. }
  16. certPem, err := Asset("cacert/apiclient_cert.pem")
  17. if err != nil {
  18. return nil, err
  19. }
  20. keyPem, err := Asset("cacert/apiclient_key.pem")
  21. if err != nil {
  22. return nil, err
  23. }
  24. pkcsPool := x509.NewCertPool()
  25. pkcsPool.AppendCertsFromPEM(certP12)
  26. certificate, err := tls.X509KeyPair(certPem, keyPem)
  27. if err != nil {
  28. return nil, fmt.Errorf("tls.LoadX509KeyPair:%s", err)
  29. }
  30. tlsConfig := &tls.Config{
  31. Certificates: []tls.Certificate{certificate},
  32. RootCAs: pkcsPool,
  33. InsecureSkipVerify: true,
  34. }
  35. httpClient := &http.Client{
  36. Transport: &http.Transport{
  37. TLSClientConfig: tlsConfig,
  38. DisableKeepAlives: true,
  39. },
  40. }
  41. return core.NewSubMchClient(define.AppId, define.MchId, define.ApiKey, "", define.SubMchId, httpClient), nil
  42. }