geetest.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package http
  2. import (
  3. "strings"
  4. "go-common/app/interface/main/account/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // getChallenge get geetest params gt ,challenge
  9. func getChallenge(c *bm.Context) {
  10. params := new(model.GeeCaptchaRequest)
  11. var (
  12. mid, ok = c.Get("mid")
  13. mobile = strings.Contains(c.Request.UserAgent(), model.MobileUserAgentFlag)
  14. )
  15. if !ok {
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. if mobile {
  20. params.ClientType = model.PlatH5
  21. } else {
  22. params.ClientType = model.PlatPC
  23. }
  24. params.MID = mid.(int64)
  25. c.JSON(geetestSvr.PreProcess(c, params))
  26. }
  27. func geetestValidate(c *bm.Context) {
  28. params := new(model.GeeCheckRequest)
  29. if err := c.Bind(params); err != nil {
  30. return
  31. }
  32. mid, ok := c.Get("mid")
  33. if !ok {
  34. c.JSON(nil, ecode.RequestErr)
  35. return
  36. }
  37. params.MID = mid.(int64)
  38. if params.MID == 0 {
  39. c.JSON(nil, ecode.RequestErr)
  40. }
  41. if strings.Contains(c.Request.UserAgent(), model.MobileUserAgentFlag) {
  42. params.ClientType = model.PlatH5
  43. } else {
  44. params.ClientType = model.PlatPC
  45. }
  46. c.JSON(geetestSvr.Validate(c, params), nil)
  47. }