bullet_chat.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package bullet_chat
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "hongze/hongze_yb/controller/response"
  6. "hongze/hongze_yb/models/request"
  7. responseModel "hongze/hongze_yb/models/response"
  8. "hongze/hongze_yb/services/bullet_chat"
  9. "hongze/hongze_yb/services/user"
  10. "hongze/hongze_yb/services/wx_app"
  11. "strconv"
  12. )
  13. // Add
  14. // @Description 新增弹幕
  15. // @Success 200 {string} string "操作成功"
  16. // @Router /bullet_chat/add [post]
  17. func Add(c *gin.Context) {
  18. userInfo := user.GetInfoByClaims(c)
  19. if userInfo.UserID <= 0 {
  20. response.Fail("请登录后操作", c)
  21. return
  22. }
  23. var req request.BulletChatAddReq
  24. if c.ShouldBind(&req) != nil {
  25. response.Fail("参数有误", c)
  26. return
  27. }
  28. if req.PrimaryId <= 0 {
  29. response.Fail("参数有误", c)
  30. return
  31. }
  32. if req.Content == "" {
  33. response.Fail("内容不可为空", c)
  34. return
  35. }
  36. if len([]rune(req.Content)) > 50 {
  37. response.Fail("内容不可超过50个字", c)
  38. return
  39. }
  40. // 敏感词校验
  41. // TODO:如果备用小程序提上master的话,此处要有调整(2022/11/08)
  42. if userInfo.RecordInfo.OpenID != "" && userInfo.RecordInfo.CreatePlatform == 6 {
  43. checkResult, e := wx_app.MsgSecCheck(userInfo.RecordInfo.OpenID, req.Content)
  44. if e == nil {
  45. if checkResult.Result != nil && checkResult.Result.Suggest != "pass" {
  46. errMsg := "含有违禁词, 不允许发布: " + checkResult.Result.Suggest + ", 命中标签: " + strconv.Itoa(checkResult.Result.Label)
  47. response.FailMsg("内容含有违禁词, 不允许发布", errMsg, c)
  48. return
  49. }
  50. }
  51. }
  52. bc, e := bullet_chat.CreateBulletChat(int(userInfo.UserID), req.PrimaryId, req.Source, req.SourceAgent, req.Seconds, req.Content)
  53. if e != nil {
  54. response.FailMsg("发布失败", "新增弹幕失败, Err: "+e.Error(), c)
  55. return
  56. }
  57. resp := new(responseModel.BulletChatItem)
  58. resp.Id = bc.ID
  59. resp.UserId = bc.UserID
  60. resp.Content = bc.Content
  61. resp.Seconds = fmt.Sprint(bc.Seconds)
  62. resp.Color = bc.Color
  63. response.OkData("操作成功", resp, c)
  64. }