作者 yangfu

增加 uuid查重 防止接口重新访问

@@ -138,14 +138,14 @@ func FilterComm(ctx *context.Context) { @@ -138,14 +138,14 @@ func FilterComm(ctx *context.Context) {
138 //if !CheckSign(ctx) { 138 //if !CheckSign(ctx) {
139 // return 139 // return
140 //} 140 //}
  141 + //3.查重uuid
  142 + if !CheckUuid(ctx) {
  143 + return
  144 + }
141 //2.检查token是否有效 145 //2.检查token是否有效
142 if !CheckToken(ctx) { 146 if !CheckToken(ctx) {
143 return 147 return
144 } 148 }
145 - //3.查重uuid  
146 - //if !CheckUuid(ctx) {  
147 - // return  
148 - //}  
149 return 149 return
150 } 150 }
151 151
@@ -284,18 +284,21 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe @@ -284,18 +284,21 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
284 284
285 //检查uuid 是否重复 285 //检查uuid 是否重复
286 func CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) { 286 func CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) {
287 - //var (  
288 - // logUuid *models.LogUuid  
289 - //)  
290 - //if len(request.Uuid) == 0 {  
291 - // err = common.NewErrorWithMsg(4142, "uuid not empty")  
292 - //}  
293 - //logUuid, err = models.GetLogUuidByUuid(request.Uuid)  
294 - //if err == nil && logUuid != nil {  
295 - // err = common.NewErrorWithMsg(4142, "uuid not valid")  
296 - //}  
297 - //models.AddLogUuid(&models.LogUuid{Uuid: request.Uuid})  
298 - //rsp = &protocol.CheckUuidResponse{} 287 + var ()
  288 + rsp = &protocol.CheckUuidResponse{}
  289 + if len(request.Uuid) == 0 || (request.Uuid == "123456" && beego.BConfig.RunMode != "prod") {
  290 + return
  291 + }
  292 + if redis.Hexists(protocol.RedisKey(protocol.HashUuid), request.Uuid) {
  293 + err = protocol.NewErrWithMessage(4142)
  294 + log.Error("[CheckUuid] 存在:", request.Uuid, err)
  295 + return
  296 + }
  297 + if e := redis.Hset(protocol.RedisKey(protocol.HashUuid), request.Uuid, request.Uuid, 3600*2); e == nil {
  298 + err = protocol.NewErrWithMessage(4142)
  299 + log.Error("[CheckUuid] 设置:", request.Uuid, e)
  300 + return
  301 + }
299 return 302 return
300 } 303 }
301 304