block.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/admin/main/reply/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _blockURL string = "http://account.bilibili.co/api/member/blockAccountWithTime"
  13. _transferURL string = "http://api.bilibili.co/x/internal/credit/blocked/case/add"
  14. )
  15. // BlockAccount ban an account.
  16. func (d *Dao) BlockAccount(c context.Context, mid int64, ftime int64, notify bool, freason int32, originTitle string, originContent string, redirectURL string, adname string, remark string) (err error) {
  17. params := url.Values{}
  18. params.Set("mid", strconv.FormatInt(mid, 10))
  19. if ftime == -1 {
  20. params.Set("blockTimeLength", "0")
  21. params.Set("blockForever", "1")
  22. } else {
  23. params.Set("blockForever", "0")
  24. params.Set("blockTimeLength", strconv.FormatInt(ftime, 10))
  25. }
  26. params.Set("blockRemark", remark)
  27. params.Set("operator", adname)
  28. params.Set("originType", "1")
  29. params.Set("originContent", originContent)
  30. params.Set("reasonType", strconv.FormatInt(int64(freason), 10))
  31. if notify {
  32. params.Set("isNotify", "1")
  33. } else {
  34. params.Set("isNotify", "0")
  35. }
  36. params.Set("originTitle", originTitle)
  37. params.Set("originUrl", redirectURL)
  38. var res struct {
  39. Code int `json:"code"`
  40. }
  41. if err = d.httpClient.Post(c, _blockURL, "", params, &res); err != nil {
  42. log.Error("sendMsg error(%v)", err)
  43. return
  44. }
  45. if res.Code != ecode.OK.Code() {
  46. err = model.ErrMsgSend
  47. log.Error("sendMsg failed(%v) error(%v)", _apiMsgSend+"?"+params.Encode(), res.Code)
  48. }
  49. return
  50. }
  51. // TransferData transefer data
  52. type TransferData struct {
  53. Oid int64 `json:"oid"`
  54. Type int32 `json:"type"`
  55. Mid int64 `json:"mid"`
  56. RpID int64 `json:"rp_id"`
  57. Operator string `json:"operator"`
  58. OperatorID int64 `json:"oper_id"`
  59. Content string `json:"origin_content"`
  60. Reason int32 `json:"reason_type"`
  61. Title string `json:"origin_title"`
  62. Link string `json:"origin_url"`
  63. Ctime int64 `json:"business_time"`
  64. OriginType int32 `json:"origin_type"`
  65. }
  66. // TransferArbitration transfer report to Arbitration.
  67. func (d *Dao) TransferArbitration(c context.Context, rps map[int64]*model.Reply, rpts map[int64]*model.Report, adid int64, adname string, titles map[int64]string, links map[int64]string) (err error) {
  68. var data []TransferData
  69. for _, rp := range rps {
  70. if rpts[rp.ID] == nil {
  71. continue
  72. }
  73. rpt := rpts[rp.ID]
  74. d := TransferData{
  75. RpID: rp.ID,
  76. Oid: rp.Oid,
  77. Type: rp.Type,
  78. Mid: rp.Mid,
  79. Operator: adname,
  80. OperatorID: adid,
  81. Content: rp.Content.Message,
  82. Reason: rpt.Reason,
  83. Ctime: int64(rp.CTime),
  84. OriginType: 1,
  85. Title: titles[rp.ID],
  86. Link: links[rp.ID],
  87. }
  88. data = append(data, d)
  89. }
  90. content, err := json.Marshal(data)
  91. if err != nil {
  92. return
  93. }
  94. params := url.Values{}
  95. params.Set("data", string(content))
  96. var res struct {
  97. Code int `json:"code"`
  98. }
  99. if err = d.httpClient.Post(c, _transferURL, "", params, &res); err != nil {
  100. log.Error("sendMsg error(%v)", err)
  101. return
  102. }
  103. if res.Code != ecode.OK.Code() {
  104. err = model.ErrMsgSend
  105. log.Error("sendMsg failed(%v) error(%v)", _transferURL+"?"+params.Encode(), res.Code)
  106. }
  107. return
  108. }