validate.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package v1
  2. import (
  3. "encoding/json"
  4. v1pb "go-common/app/interface/live/app-room/api/http/v1"
  5. risk "go-common/app/service/live/live_riskcontrol/api/grpc/v1"
  6. xcaptcha "go-common/app/service/live/xcaptcha/api/grpc/v1"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/metadata"
  11. )
  12. type rbody struct {
  13. Roomid int64 `json:"roomid"`
  14. Msg string `json:"msg" `
  15. Rnd string `json:"rnd" `
  16. Fontsize int64 `json:"fontsize"`
  17. Mode int64 `json:"mode" `
  18. Color int64 `json:"color"`
  19. Bubble int64 `json:"bubble"`
  20. }
  21. func isriskcontrol(ctx *bm.Context, uid int64, r *v1pb.SendDMReq) (forbid bool, err *ecode.Status) {
  22. req := &risk.GetForbiddenReq{
  23. Uid: uid,
  24. Uri: "/xlive/app-room/v1/dM/sendmsg",
  25. Ip: metadata.String(ctx, metadata.RemoteIP),
  26. Method: "POST",
  27. Header: make(map[string]string),
  28. }
  29. for k := range ctx.Request.Header {
  30. req.Header[k] = ctx.Request.Header.Get(k)
  31. }
  32. rb := &rbody{
  33. Roomid: r.Roomid,
  34. Msg: r.Msg,
  35. Rnd: r.Rnd,
  36. Fontsize: r.Fontsize,
  37. Mode: r.Mode,
  38. Color: r.Color,
  39. Bubble: r.Bubble,
  40. }
  41. jb, _ := json.Marshal(rb)
  42. req.Body = string(jb)
  43. resp, rerr := riskClient.GetForbidden(ctx, req)
  44. if rerr != nil {
  45. log.Error("DM: riskcontrol err:%+v", rerr)
  46. return false, nil
  47. }
  48. switch resp.IsForbidden {
  49. case 0:
  50. return false, nil
  51. case 1:
  52. return true, ecode.Error(400, "访问被拒绝")
  53. case 2:
  54. return true, ecode.Error(1990000, "need a second time verify")
  55. }
  56. return false, nil
  57. }
  58. func checkVerify(ctx *bm.Context, anti string, uid int64, roomid int64) bool {
  59. req := &xcaptcha.XVerifyReq{
  60. Uid: uid,
  61. ClientIp: metadata.String(ctx, metadata.RemoteIP),
  62. XAnti: anti,
  63. RoomId: roomid,
  64. }
  65. if _, err := xcaptchaClient.Verify(ctx, req); err != nil {
  66. return false
  67. }
  68. return true
  69. }