reply.go 938 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. )
  8. const (
  9. _replyType = "18"
  10. _replyState = "0" // 0: open, 1: close
  11. _replyURL = "http://api.bilibili.co/x/internal/v2/reply/subject/regist"
  12. )
  13. // RegReply opens playlist's reply.
  14. func (d *Dao) RegReply(c context.Context, pid, mid int64) (err error) {
  15. params := url.Values{}
  16. params.Set("mid", strconv.FormatInt(mid, 10))
  17. params.Set("oid", strconv.FormatInt(pid, 10))
  18. params.Set("type", _replyType)
  19. params.Set("state", _replyState)
  20. var res struct {
  21. Code int `json:"code"`
  22. }
  23. if err = d.http.Post(c, _replyURL, "", params, &res); err != nil {
  24. PromError("reply:打开评论", "d.http.Post(%s) error(%v)", _replyURL+"?"+params.Encode(), err)
  25. return
  26. }
  27. if res.Code != ecode.OK.Code() {
  28. PromError("reply:打开评论状态码异常", "d.http.Post(%s) error(%v)", _replyURL+"?"+params.Encode(), err)
  29. err = ecode.Int(res.Code)
  30. }
  31. return
  32. }