From 50ef2fd13a92682420b60fdf1b600dc400575967 Mon Sep 17 00:00:00 2001 From: Rzy <465386466@qq.com> Date: Fri, 9 Aug 2024 10:08:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=88=86=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E8=AE=B0=E5=BD=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/middlewares/base.go | 28 +++++++++++++++++++--------- app/http/requestmapping/front.go | 7 ++++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/http/middlewares/base.go b/app/http/middlewares/base.go index 0f80b8e..1af7e68 100644 --- a/app/http/middlewares/base.go +++ b/app/http/middlewares/base.go @@ -129,8 +129,13 @@ func ValidateRequest() gin.HandlerFunc { func ValidatePayRequest() gin.HandlerFunc { return func(c *gin.Context) { - var path = c.FullPath() - var handler func() interface{} + var ( + path = c.FullPath() + code int + log_id int64 + ) + + var handler func() (interface{}, bool) requestData, err := utils.SonicApiDataToStruct(controllers.GetRequest(c), &front.RequestBody{}) if err != nil { controllers.ApiRes(c, nil, errorcode.ParamError) @@ -157,12 +162,7 @@ func ValidatePayRequest() gin.HandlerFunc { controllers.ApiRes(c, nil, errCode) return } - //记录请求日志 - id, code := services.AddRequestLog(dataByte, c.ClientIP(), path) - if code != errorcode.Success { - controllers.ApiRes(c, nil, errCode) - } - c.Set("log", id) + //检查解密后的数据是否与请求一致 reCheck := appCheck.ReCheckAfterDecrypt(dataByte, requestDataStruct) if !reCheck { @@ -170,8 +170,18 @@ func ValidatePayRequest() gin.HandlerFunc { return } //表单验证 + handler = requestmapping.FrontRequestMap[path] - v := handler() + v, isSaveLog := handler() + if isSaveLog { + //记录请求日志 + log_id, code = services.AddRequestLog(dataByte, c.ClientIP(), path) + if code != errorcode.Success { + controllers.ApiRes(c, nil, errCode) + } + } + + c.Set("log", log_id) msg, err := controllers.ValidApiData(dataByte, v) if err != nil { utils.Log(c, "参数错误", "path=", path, "err=", err.Error(), "msg=", msg) diff --git a/app/http/requestmapping/front.go b/app/http/requestmapping/front.go index 5acf719..1d87d3d 100644 --- a/app/http/requestmapping/front.go +++ b/app/http/requestmapping/front.go @@ -5,9 +5,10 @@ import ( "PaymentCenter/app/http/entities/front" ) -var FrontRequestMap = map[string]func() interface{}{ - common.FRONT_V1 + "/pay/url": func() interface{} { return new(front.PayReqs) }, - common.FRONT_V1 + "/pay/refund": func() interface{} { return new(front.RefundReqs) }, +var FrontRequestMap = map[string]func() (validForm interface{}, isSaveLog bool){ + common.FRONT_V1 + "/pay/url": func() (interface{}, bool) { return new(front.PayReqs), true }, + common.FRONT_V1 + "/pay/refund": func() (interface{}, bool) { return new(front.RefundReqs), true }, + common.FRONT_V1 + "/pay/query": func() (interface{}, bool) { return new(front.QueryReqs), false }, } var FrontRequestMapBeforeDecrypt = map[string]func() interface{}{