http.go 4.8 KB

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