zhih_httpclient.go 978 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 ZhihHttpGet(api string, data map[string]string) (result []byte, err error) {
  11. //fullApi := che300FullURL(api)
  12. defer func() {
  13. l.Info("thirdparty",
  14. zap.String("api", api),
  15. zap.String("request", utils.MarshalJsonString(data)),
  16. zap.String("response", utils.MarshalJsonString(result)))
  17. }()
  18. if data == nil {
  19. data = make(map[string]string)
  20. }
  21. data["User"] = config.Conf.ThirdPart.ZhUser
  22. data["Pwd"] = config.Conf.ThirdPart.ZhPwd
  23. client := &http.Client{}
  24. client.Timeout = 60 * time.Second
  25. req, err := http.NewRequest("GET", concatGetURL(api, data), nil)
  26. if err != nil {
  27. return nil, err
  28. }
  29. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  30. resp, err := client.Do(req)
  31. if err != nil {
  32. return nil, err
  33. }
  34. defer resp.Body.Close()
  35. result, err = ioutil.ReadAll(resp.Body)
  36. return
  37. }