advert.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/interface/main/dm2/model"
  7. "go-common/library/ecode"
  8. "go-common/library/net/metadata"
  9. "github.com/pkg/errors"
  10. )
  11. const (
  12. _adURL = "/bce/api/bce/wise"
  13. )
  14. func (d *Dao) adURI() string {
  15. return d.conf.Host.Advert + _adURL
  16. }
  17. // DMAdvert dm advert.
  18. func (d *Dao) DMAdvert(c context.Context, aid, cid, mid, build int64, buvid, mobiApp, adExtra string) (data *model.AD, err error) {
  19. var (
  20. res *struct {
  21. Code int `json:"code"`
  22. Data *model.AD `json:"data"`
  23. }
  24. )
  25. ip := metadata.String(c, metadata.RemoteIP)
  26. params := url.Values{}
  27. params.Set("aid", fmt.Sprint(aid))
  28. params.Set("cid", fmt.Sprint(cid))
  29. params.Set("buvid", buvid)
  30. params.Set("resource", model.Resource(mobiApp))
  31. params.Set("mobi_app", mobiApp)
  32. params.Set("build", fmt.Sprint(build))
  33. params.Set("ip", ip)
  34. params.Set("ad_extra", adExtra)
  35. if mid != 0 {
  36. params.Set("mid", fmt.Sprint(mid))
  37. }
  38. if err = d.httpCli.Get(c, d.adURI(), ip, params, &res); err != nil {
  39. return
  40. }
  41. if res.Code != ecode.OK.Code() {
  42. err = errors.Wrap(ecode.Int(res.Code), d.adURI()+"?"+params.Encode())
  43. return
  44. }
  45. data = res.Data
  46. return
  47. }