From bfde7176ebaa67ae9b33c6822fc1eb0673c963fd Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 12 Jun 2024 17:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98=EF=BC=8C=E7=94=A8=E6=88=B7=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/user.go | 7 ++++++- main.go | 7 ++++++- worker/redis.go | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/handler/user.go b/handler/user.go index bced773..7079247 100644 --- a/handler/user.go +++ b/handler/user.go @@ -47,7 +47,8 @@ func ScanUUID(c *gin.Context) { id := uuid.New() res := worker.SetHash(id.String(), map[string]interface{}{"status": "0", "address": ReqData.Address, "ip": c.ClientIP()}) if res { - c.JSON(200, gin.H{"code": 0, "message": "success", "data": id.String()}) + data := worker.GetHashAll(id.String()) + c.JSON(200, gin.H{"code": 0, "message": data, "data": id.String()}) } else { c.JSON(200, gin.H{"code": 8, "message": "qr code invalid", "data": "1"}) } @@ -56,6 +57,10 @@ func ScanUUID(c *gin.Context) { func SetQRStatus(c *gin.Context) { var qrsetReq QRReq if err := c.ShouldBind(&qrsetReq); err == nil || qrsetReq.UUID != "" { + if worker.IsContainKey(qrsetReq.UUID) == false { + c.JSON(200, gin.H{"code": 18, "message": "uuid not found", "data": "0"}) + return + } res := worker.SetHashWithField(qrsetReq.UUID, "status", "1") if res { data := worker.GetHashAll(qrsetReq.UUID) diff --git a/main.go b/main.go index 87504a9..58d286b 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,12 @@ func writeLogger(c *gin.Context) { params = c.Request.URL.RawQuery } if method == "POST" { - params = c.Request.PostForm.Encode() + var data interface{} + err := c.ShouldBind(&data) + if err != nil { + fmt.Println("bind json failed") + } + params = fmt.Sprintf("%v", data) } res := dao.InsertLogToDB(path, ip, method, params) if res == 0 { diff --git a/worker/redis.go b/worker/redis.go index 57852f0..6fd1c37 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -35,7 +35,7 @@ func CloseRedis() { } } -func isContainKey(key string) bool { +func IsContainKey(key string) bool { ctx := context.Background() val, err := redisClient.Exists(ctx, key).Result() // 检查键是否存在, 如果存在则返回 1, 否则返回 0 if err != nil {