base_lib.go 888 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package services
  2. import (
  3. "eta/eta_mini_api/utils"
  4. "io"
  5. "net/http"
  6. "time"
  7. )
  8. func HttpGet(url string) (body []byte, err error) {
  9. client := &http.Client{}
  10. req, err := http.NewRequest("GET", url, nil)
  11. if err != nil {
  12. return
  13. }
  14. nonce := utils.GetRandStringNoSpecialChar(16)
  15. timestamp := time.Now().Format(utils.FormatDateTimeUnSpace)
  16. signature := utils.GetSign(nonce, timestamp, utils.ETA_MINI_APPID, utils.ETA_MINI_APP_SECRET)
  17. //增加header选项
  18. req.Header.Add("Nonce", nonce)
  19. req.Header.Add("Timestamp", timestamp)
  20. req.Header.Add("Appid", utils.ETA_MINI_APPID)
  21. req.Header.Add("Signature", signature)
  22. req.Header.Set("Content-Type", "application/json")
  23. response, err := client.Do(req)
  24. if err != nil {
  25. return
  26. }
  27. defer response.Body.Close()
  28. body, err = io.ReadAll(response.Body)
  29. if err != nil {
  30. return
  31. }
  32. utils.FileLog.Info("result:" + string(body))
  33. return
  34. }