edHttpClient.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package thirdparty
  2. import (
  3. "gd_management/common.in/httpClient"
  4. "gd_management/common.in/utils"
  5. "fmt"
  6. "go.uber.org/zap"
  7. )
  8. var (
  9. edHost = "https://api.edaishen.net"
  10. edApiPrefix = "oapi/store/oindex.php"
  11. )
  12. func edFullUrl() string {
  13. return fmt.Sprintf("%s/%s", edHost, edApiPrefix)
  14. }
  15. func EdSetHost(host string) {
  16. edHost = host
  17. }
  18. func EdPost(host string, route string, token string, data []byte) (result []byte, err error) {
  19. url := fmt.Sprintf("%s?route=%s&access_token=%s", host, route, token)
  20. defer func() {
  21. if l == nil {
  22. return
  23. }
  24. l.Info("thirdparty",
  25. zap.String("api", url),
  26. zap.String("request", utils.MarshalJsonString(data)),
  27. zap.String("response", string(result)))
  28. }()
  29. result, err = httpClient.HttpPostBytes(url, data)
  30. return result, err
  31. }
  32. func EdGet(host string, data map[string]string) (result []byte, err error) {
  33. defer func() {
  34. l.Info("thirdparty",
  35. zap.String("api", host),
  36. zap.String("request", utils.MarshalJsonString(data)),
  37. zap.String("response", string(result)))
  38. }()
  39. result, err = httpClient.HttpGet(host, data)
  40. return result, err
  41. }