12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package middleware
- import (
- "eta_gn/eta_bridge/controller/resp"
- "eta_gn/eta_bridge/global"
- "eta_gn/eta_bridge/utils"
- "fmt"
- "github.com/gin-gonic/gin"
- )
- func Token() gin.HandlerFunc {
- return func(c *gin.Context) {
- token := c.Request.Header.Get("Authorization")
- if token == "" {
- token = c.DefaultQuery("authorization", "")
- if token == "" {
- token = c.DefaultQuery("Authorization", "")
- }
- }
- if token == "" {
- resp.TokenError(nil, "非法访问", "非法访问", c)
- c.Abort()
- return
- }
- if token != utils.CrmEtaAuthorization {
- resp.TokenError(nil, "非法访问", "非法访问", c)
- c.Abort()
- return
- }
- c.Next()
- }
- }
- func InternalToken() gin.HandlerFunc {
- return func(c *gin.Context) {
- token := c.Request.Header.Get("Authorization")
- if token == "" {
- token = c.DefaultQuery("authorization", "")
- if token == "" {
- token = c.DefaultQuery("Authorization", "")
- }
- }
- if token == "" {
- resp.TokenError(nil, "非法访问", "非法访问", c)
- c.Abort()
- return
- }
- checkToken := utils.MD5(global.CONFIG.Serve.AppNameEn + global.CONFIG.Serve.Md5Key)
- if token != checkToken {
- resp.TokenError(nil, "非法访问", "非法访问", c)
- c.Abort()
- return
- }
- utils.SetBridgeLogListByClaims(c, fmt.Sprint("Token:", token))
- c.Next()
- }
- }
|