feedback.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/interface/main/web/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. "go-common/library/net/metadata"
  11. )
  12. const _platform = "web"
  13. // Feedback feedback http request.
  14. func (d *Dao) Feedback(c context.Context, feedParams *model.Feedback) (err error) {
  15. var (
  16. content []byte
  17. params = url.Values{}
  18. ip = metadata.String(c, metadata.RemoteIP)
  19. )
  20. if feedParams.Aid > 0 {
  21. params.Set("aid", strconv.FormatInt(feedParams.Aid, 10))
  22. }
  23. params.Set("mid", strconv.FormatInt(feedParams.Mid, 10))
  24. params.Set("tag_id", strconv.FormatInt(feedParams.TagID, 10))
  25. if content, err = json.Marshal(feedParams.Content); err != nil {
  26. log.Error("content json.Marshal(%+v) error(%v)", feedParams.Content, err)
  27. } else {
  28. params.Set("content", string(content))
  29. }
  30. params.Set("browser", feedParams.Browser)
  31. params.Set("version", feedParams.Version)
  32. params.Set("buvid", feedParams.Buvid)
  33. params.Set("platform", _platform)
  34. if feedParams.Email != "" {
  35. params.Set("email", feedParams.Email)
  36. }
  37. if feedParams.QQ != "" {
  38. params.Set("qq", feedParams.QQ)
  39. }
  40. var res struct {
  41. Code int `json:"code"`
  42. }
  43. if err = d.httpW.Post(c, d.feedbackURL, ip, params, &res); err != nil {
  44. log.Error("d.client.Post(%s) error(%v)", d.feedbackURL+"?"+params.Encode(), err)
  45. return
  46. }
  47. if res.Code != ecode.OK.Code() {
  48. log.Error("d.client.Post(%s) code(%d)", d.feedbackURL+"?"+params.Encode(), res.Code)
  49. err = ecode.Int(res.Code)
  50. }
  51. return
  52. }