cxyHttpClient.go 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package thirdparty
  2. import (
  3. "gd_management/common.in/config"
  4. "gd_management/common.in/utils"
  5. "go.uber.org/zap"
  6. "io/ioutil"
  7. "net/http"
  8. "time"
  9. )
  10. func CxyHttpGet(api string, data map[string]string) (result []byte, err error) {
  11. defer func() {
  12. l.Info("thirdparty",
  13. zap.String("api", api),
  14. zap.String("request", utils.MarshalJsonString(data)),
  15. zap.String("response", utils.MarshalJsonString(result)))
  16. }()
  17. if data == nil {
  18. data = make(map[string]string)
  19. }
  20. /*data["userid"] = "yiborantest"
  21. data["userpwd"] = "EC26E0A72785474884D04EC4ADA8837B"
  22. */
  23. data["userid"] = config.Conf.ThirdPart.CxyUserName
  24. data["userpwd"] = config.Conf.ThirdPart.CxyUserPasswd
  25. client := &http.Client{}
  26. client.Timeout = 60 * time.Second
  27. req, err := http.NewRequest("GET", concatGetURL(api, data), nil)
  28. if err != nil {
  29. return nil, err
  30. }
  31. resp, err := client.Do(req)
  32. if err != nil {
  33. return nil, err
  34. }
  35. defer resp.Body.Close()
  36. result, err = ioutil.ReadAll(resp.Body)
  37. return
  38. }