bangumi.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/interface/main/spread/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. // BangumiContent .
  12. func (d *Dao) BangumiContent(c context.Context, pn, ps int, typ int8, appkey string) (resp model.BangumiResp, err error) {
  13. params := url.Values{}
  14. params.Set("page_no", strconv.Itoa(pn))
  15. params.Set("page_size", strconv.Itoa(ps))
  16. params.Set("season_type", strconv.Itoa(int(typ)))
  17. params.Set("bsource", appkey)
  18. err = d.httpClient.Get(c, d.c.Spread.BangumiContentURL, "", params, &resp)
  19. u := fmt.Sprintf("%s?%s", d.c.Spread.BangumiContentURL, params.Encode())
  20. if err != nil {
  21. PromError("bangumi:content接口")
  22. log.Errorv(c, log.KV("err", err), log.KV("url", u))
  23. return
  24. }
  25. if resp.Code != 0 {
  26. PromError("bangumi:content接口")
  27. log.Errorv(c, log.KV("res", resp), log.KV("url", u))
  28. err = ecode.Int(resp.Code)
  29. return
  30. }
  31. return
  32. }
  33. // BangumiOff .
  34. func (d *Dao) BangumiOff(c context.Context, pn, ps int, typ int8, appkey string, ts int64) (resp model.BangumiOffResp, err error) {
  35. params := url.Values{}
  36. params.Set("page_no", strconv.Itoa(pn))
  37. params.Set("page_size", strconv.Itoa(ps))
  38. params.Set("timestamp", strconv.FormatInt(ts, 10))
  39. params.Set("season_type", strconv.Itoa(int(typ)))
  40. params.Set("bsource", appkey)
  41. err = d.httpClient.Get(c, d.c.Spread.BangumiOffURL, "", params, &resp)
  42. u := fmt.Sprintf("%s?%s", d.c.Spread.BangumiOffURL, params.Encode())
  43. if err != nil {
  44. PromError("bangumi:off接口")
  45. log.Errorv(c, log.KV("err", err), log.KV("url", u))
  46. return
  47. }
  48. if resp.Code != 0 {
  49. PromError("bangumi:off接口")
  50. log.Errorv(c, log.KV("res", resp), log.KV("url", u))
  51. err = ecode.Int(resp.Code)
  52. return
  53. }
  54. return
  55. }