|
@@ -2,15 +2,18 @@ package middleware
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
- "github.com/gin-gonic/gin"
|
|
|
|
- "go.uber.org/zap"
|
|
|
|
"sfbase/global"
|
|
"sfbase/global"
|
|
sutils "sfbase/utils"
|
|
sutils "sfbase/utils"
|
|
|
|
+
|
|
|
|
+ // "sfis/model"
|
|
"sfis/model/response"
|
|
"sfis/model/response"
|
|
"sfis/utils"
|
|
"sfis/utils"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
+
|
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
|
+ "go.uber.org/zap"
|
|
)
|
|
)
|
|
|
|
|
|
const TimestampExpireTime = 600 //单位秒,header里的时间戳超时时间 10分钟
|
|
const TimestampExpireTime = 600 //单位秒,header里的时间戳超时时间 10分钟
|
|
@@ -29,13 +32,13 @@ func TokenAuth() gin.HandlerFunc {
|
|
requestUrl = strings.Split(requestUrl, "?")[0]
|
|
requestUrl = strings.Split(requestUrl, "?")[0]
|
|
a := strings.Split(requestUrl, "/")
|
|
a := strings.Split(requestUrl, "/")
|
|
requestUrl = a[4]
|
|
requestUrl = a[4]
|
|
- /*if p, ok := utils.ApiUrlCache.Load(requestUrl); ok {
|
|
|
|
- productID = p.(*model.Product).ID
|
|
|
|
- } else {
|
|
|
|
- response.FailWithDetailed(response.ParamError, nil, "url错误", context)
|
|
|
|
- context.Abort()
|
|
|
|
- return
|
|
|
|
- }*/
|
|
|
|
|
|
+ // if p, ok := utils.ApiUrlCache.Load(requestUrl); ok {
|
|
|
|
+ // productID = p.(*model.Product).ID
|
|
|
|
+ // } else {
|
|
|
|
+ // response.FailWithDetailed(response.ParamError, nil, "url错误", context)
|
|
|
|
+ // context.Abort()
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
productID = 1000
|
|
productID = 1000
|
|
token = context.Request.Header.Get("token")
|
|
token = context.Request.Header.Get("token")
|
|
timestamp = context.Request.Header.Get("timestamp")
|
|
timestamp = context.Request.Header.Get("timestamp")
|
|
@@ -53,7 +56,11 @@ func TokenAuth() gin.HandlerFunc {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
- if now-_timestamp > TimestampExpireTime {
|
|
|
|
|
|
+ TimestampExpire := now - _timestamp
|
|
|
|
+ if TimestampExpire < 0 {
|
|
|
|
+ TimestampExpire = -TimestampExpire
|
|
|
|
+ }
|
|
|
|
+ if TimestampExpire > TimestampExpireTime {
|
|
//token时间验证 十分钟
|
|
//token时间验证 十分钟
|
|
response.FailWithDetailed(response.TokenExpired, nil, "签名过期", context)
|
|
response.FailWithDetailed(response.TokenExpired, nil, "签名过期", context)
|
|
context.Abort()
|
|
context.Abort()
|
|
@@ -68,8 +75,8 @@ func TokenAuth() gin.HandlerFunc {
|
|
/**
|
|
/**
|
|
第一步:ip白名单校验
|
|
第一步:ip白名单校验
|
|
*/
|
|
*/
|
|
|
|
+ requestIP = utils.GetIp(context.Request)
|
|
if ipWhiteList != "*" {
|
|
if ipWhiteList != "*" {
|
|
- requestIP = utils.GetIp(context.Request)
|
|
|
|
if strings.Index(ipWhiteList, requestIP) < 0 {
|
|
if strings.Index(ipWhiteList, requestIP) < 0 {
|
|
response.FailWithDetailed(response.IpInvalid, nil, "ip不在白名单", context)
|
|
response.FailWithDetailed(response.IpInvalid, nil, "ip不在白名单", context)
|
|
context.Abort()
|
|
context.Abort()
|