http.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package block
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strings"
  7. "time"
  8. model "go-common/app/admin/main/member/model/block"
  9. "go-common/library/ecode"
  10. "github.com/pkg/errors"
  11. )
  12. // BlackhouseBlock .
  13. func (d *Dao) BlackhouseBlock(c context.Context, p *model.ParamBatchBlock) (err error) {
  14. midStrs := make([]string, len(p.MIDs))
  15. for i, mid := range p.MIDs {
  16. midStrs[i] = fmt.Sprintf("%d", mid)
  17. }
  18. params := url.Values{}
  19. params.Set("mids", strings.Join(midStrs, ","))
  20. params.Set("oper_id", fmt.Sprintf("%d", p.AdminID))
  21. params.Set("operator_name", p.AdminName)
  22. params.Set("blocked_days", fmt.Sprintf("%d", p.Duration))
  23. switch p.Action {
  24. case model.BlockActionForever:
  25. params.Set("blocked_forever", "1")
  26. params.Set("punish_type", "3")
  27. default:
  28. params.Set("blocked_forever", "0")
  29. params.Set("punish_type", "2")
  30. }
  31. params.Set("blocked_remark", p.Comment)
  32. params.Set("origin_type", fmt.Sprintf("%d", p.Area))
  33. params.Set("punish_time", fmt.Sprintf("%d", time.Now().Unix()))
  34. params.Set("reason_type", fmt.Sprintf("%d", parseReasonType(p.Reason)))
  35. var res struct {
  36. Code int `json:"code"`
  37. }
  38. if err = d.httpClient.Post(c, d.conf.BlockProperty.BlackHouseURL, "", params, &res); err != nil {
  39. err = errors.WithStack(err)
  40. return
  41. }
  42. if res.Code != 0 {
  43. err = errors.WithStack(ecode.Int(res.Code))
  44. return
  45. }
  46. return
  47. }
  48. func parseReasonType(msg string) (t int) {
  49. switch msg {
  50. case "刷屏":
  51. t = 1
  52. case "抢楼":
  53. t = 2
  54. case "发布色情低俗信息":
  55. t = 3
  56. case "发布赌博诈骗信息":
  57. t = 4
  58. case "发布违禁相关信息", "发布违禁信息":
  59. t = 5
  60. case "发布垃圾广告信息":
  61. t = 6
  62. case "发布人身攻击言论":
  63. t = 7
  64. case "发布侵犯他人隐私信息":
  65. t = 8
  66. case "发布引战言论":
  67. t = 9
  68. case "发布剧透信息":
  69. t = 10
  70. case "恶意添加无关标签":
  71. t = 11
  72. case "恶意删除他人标签":
  73. t = 12
  74. case "发布色情信息":
  75. t = 13
  76. case "发布低俗信息":
  77. t = 14
  78. case "发布暴力血腥信息":
  79. t = 15
  80. case "涉及恶意投稿行为":
  81. t = 16
  82. case "发布非法网站信息":
  83. t = 17
  84. case "发布传播不实信息":
  85. t = 18
  86. case "发布怂恿教唆信息":
  87. t = 19
  88. case "恶意刷屏":
  89. t = 20
  90. case "账号违规":
  91. t = 21
  92. case "恶意抄袭":
  93. t = 22
  94. case "冒充自制原创":
  95. t = 23
  96. case "发布青少年不良内容":
  97. t = 24
  98. case "破坏网络安全":
  99. t = 25
  100. case "发布虚假误导信息":
  101. t = 26
  102. case "仿冒官方认证账号":
  103. t = 27
  104. case "发布不适宜内容":
  105. t = 28
  106. case "违反运营规则":
  107. t = 29
  108. case "恶意创建话题":
  109. t = 30
  110. case "发布违规抽奖":
  111. t = 31
  112. case "恶意冒充他人":
  113. t = 32
  114. default:
  115. t = 0
  116. }
  117. return
  118. }
  119. // SendSysMsg send sys msg.
  120. func (d *Dao) SendSysMsg(c context.Context, code string, mids []int64, title string, content string, remoteIP string) (err error) {
  121. params := url.Values{}
  122. params.Set("mc", code)
  123. params.Set("title", title)
  124. params.Set("data_type", "4")
  125. params.Set("context", content)
  126. params.Set("mid_list", midsToParam(mids))
  127. var res struct {
  128. Code int `json:"code"`
  129. Data *struct {
  130. Status int8 `json:"status"`
  131. Remark string `json:"remark"`
  132. } `json:"data"`
  133. }
  134. if err = d.httpClient.Post(c, d.conf.BlockProperty.MSGURL, remoteIP, params, &res); err != nil {
  135. err = errors.WithStack(err)
  136. return
  137. }
  138. if res.Code != 0 {
  139. err = errors.WithStack(ecode.Int(res.Code))
  140. return
  141. }
  142. return
  143. }
  144. func midsToParam(mids []int64) (str string) {
  145. strs := make([]string, 0, len(mids))
  146. for _, mid := range mids {
  147. strs = append(strs, fmt.Sprintf("%d", mid))
  148. }
  149. return strings.Join(strs, ",")
  150. }
  151. // TelInfo tel info.
  152. func (d *Dao) TelInfo(c context.Context, mid int64) (tel string, err error) {
  153. params := url.Values{}
  154. params.Set("mid", fmt.Sprintf("%d", mid))
  155. var resp struct {
  156. Code int `json:"code"`
  157. Data struct {
  158. Mid int64 `json:"mid"`
  159. Tel string `json:"tel"`
  160. JoinIP string `json:"join_ip"`
  161. JoinTime int64 `json:"join_time"`
  162. } `json:"data"`
  163. }
  164. if err = d.httpClient.Get(c, d.conf.BlockProperty.TelURL, "", params, &resp); err != nil {
  165. err = errors.Wrapf(err, "telinfo : %d", mid)
  166. return
  167. }
  168. if resp.Code != 0 {
  169. err = errors.Errorf("telinfo url(%s) res(%+v) err(%+v)", d.conf.BlockProperty.TelURL+"?"+params.Encode(), resp, ecode.Int(resp.Code))
  170. return
  171. }
  172. tel = resp.Data.Tel
  173. return
  174. }
  175. // MailInfo .
  176. func (d *Dao) MailInfo(c context.Context, mid int64) (mail string, err error) {
  177. params := url.Values{}
  178. params.Set("mid", fmt.Sprintf("%d", mid))
  179. var resp struct {
  180. Code int `json:"code"`
  181. Data string `json:"data"`
  182. }
  183. if err = d.httpClient.Get(c, d.conf.BlockProperty.MailURL, "", params, &resp); err != nil {
  184. err = errors.Wrapf(err, "mailinfo : %d", mid)
  185. return
  186. }
  187. if resp.Code != 0 {
  188. err = errors.Errorf("mailinfo url(%s) res(%+v) err(%+v)", d.conf.BlockProperty.MailURL+"?"+params.Encode(), resp, ecode.Int(resp.Code))
  189. return
  190. }
  191. mail = resp.Data
  192. return
  193. }