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{}{