geetest.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. "go-common/library/net/metadata"
  6. "strconv"
  7. )
  8. func gtPreProcessAdd(c *bm.Context) {
  9. ip := metadata.String(c, metadata.RemoteIP)
  10. midI, ok := c.Get("mid")
  11. if !ok {
  12. c.JSON(nil, ecode.NoLogin)
  13. return
  14. }
  15. mid, _ := midI.(int64)
  16. process, err := gtSvc.PreProcessAdd(c, mid, ip, "web", 1)
  17. if err != nil {
  18. c.JSON(nil, ecode.RequestErr)
  19. return
  20. }
  21. c.JSON(process, nil)
  22. }
  23. func gtPreProcess(c *bm.Context) {
  24. ip := metadata.String(c, metadata.RemoteIP)
  25. midI, ok := c.Get("mid")
  26. if !ok {
  27. c.JSON(nil, ecode.NoLogin)
  28. return
  29. }
  30. mid, _ := midI.(int64)
  31. process, err := gtSvc.PreProcess(c, mid, ip, "web", 1)
  32. if err != nil {
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. c.JSON(process, nil)
  37. }
  38. func gtValidate(c *bm.Context) {
  39. req := c.Request
  40. ip := metadata.String(c, metadata.RemoteIP)
  41. midI, ok := c.Get("mid")
  42. if !ok {
  43. c.JSON(nil, ecode.NoLogin)
  44. return
  45. }
  46. mid, _ := midI.(int64)
  47. challenge := req.Form.Get("geetest_challenge")
  48. validate := req.Form.Get("geetest_validate")
  49. seccode := req.Form.Get("geetest_seccode")
  50. success := req.Form.Get("geetest_success")
  51. successi, err := strconv.Atoi(success)
  52. if err != nil {
  53. successi = 1
  54. }
  55. status := gtSvc.Validate(c, challenge, validate, seccode, "web", ip, successi, mid)
  56. if !status {
  57. c.JSON(nil, ecode.CreativeGeetestErr)
  58. }
  59. c.JSON(nil, nil)
  60. }