token.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package middleware
  2. import (
  3. "eta/eta_bridge/controller/resp"
  4. "eta/eta_bridge/global"
  5. "eta/eta_bridge/utils"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func Token() gin.HandlerFunc {
  9. return func(c *gin.Context) {
  10. token := c.Request.Header.Get("Authorization")
  11. if token == "" {
  12. token = c.DefaultQuery("authorization", "")
  13. if token == "" {
  14. token = c.DefaultQuery("Authorization", "")
  15. }
  16. }
  17. if token == "" {
  18. resp.TokenError(nil, "非法访问", "非法访问", c)
  19. c.Abort()
  20. return
  21. }
  22. if token != utils.CrmEtaAuthorization {
  23. resp.TokenError(nil, "非法访问", "非法访问", c)
  24. c.Abort()
  25. return
  26. }
  27. c.Next()
  28. }
  29. }
  30. func InternalToken() gin.HandlerFunc {
  31. return func(c *gin.Context) {
  32. token := c.Request.Header.Get("Authorization")
  33. if token == "" {
  34. token = c.DefaultQuery("authorization", "")
  35. if token == "" {
  36. token = c.DefaultQuery("Authorization", "")
  37. }
  38. }
  39. if token == "" {
  40. resp.TokenError(nil, "非法访问", "非法访问", c)
  41. c.Abort()
  42. return
  43. }
  44. checkToken := utils.MD5(global.CONFIG.Serve.AppNameEn + global.CONFIG.Serve.Md5Key)
  45. if token != checkToken {
  46. resp.TokenError(nil, "非法访问", "非法访问", c)
  47. c.Abort()
  48. return
  49. }
  50. c.Next()
  51. }
  52. }