<feat>区分是否需要记录日志
This commit is contained in:
		
							parent
							
								
									b3d8acba93
								
							
						
					
					
						commit
						50ef2fd13a
					
				|  | @ -129,8 +129,13 @@ func ValidateRequest() gin.HandlerFunc { | ||||||
| 
 | 
 | ||||||
| func ValidatePayRequest() gin.HandlerFunc { | func ValidatePayRequest() gin.HandlerFunc { | ||||||
| 	return func(c *gin.Context) { | 	return func(c *gin.Context) { | ||||||
| 		var path = c.FullPath() | 		var ( | ||||||
| 		var handler func() interface{} | 			path   = c.FullPath() | ||||||
|  | 			code   int | ||||||
|  | 			log_id int64 | ||||||
|  | 		) | ||||||
|  | 
 | ||||||
|  | 		var handler func() (interface{}, bool) | ||||||
| 		requestData, err := utils.SonicApiDataToStruct(controllers.GetRequest(c), &front.RequestBody{}) | 		requestData, err := utils.SonicApiDataToStruct(controllers.GetRequest(c), &front.RequestBody{}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			controllers.ApiRes(c, nil, errorcode.ParamError) | 			controllers.ApiRes(c, nil, errorcode.ParamError) | ||||||
|  | @ -157,12 +162,7 @@ func ValidatePayRequest() gin.HandlerFunc { | ||||||
| 			controllers.ApiRes(c, nil, errCode) | 			controllers.ApiRes(c, nil, errCode) | ||||||
| 			return | 			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) | 		reCheck := appCheck.ReCheckAfterDecrypt(dataByte, requestDataStruct) | ||||||
| 		if !reCheck { | 		if !reCheck { | ||||||
|  | @ -170,8 +170,18 @@ func ValidatePayRequest() gin.HandlerFunc { | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 		//表单验证
 | 		//表单验证
 | ||||||
|  | 
 | ||||||
| 		handler = requestmapping.FrontRequestMap[path] | 		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) | 		msg, err := controllers.ValidApiData(dataByte, v) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			utils.Log(c, "参数错误", "path=", path, "err=", err.Error(), "msg=", msg) | 			utils.Log(c, "参数错误", "path=", path, "err=", err.Error(), "msg=", msg) | ||||||
|  |  | ||||||
|  | @ -5,9 +5,10 @@ import ( | ||||||
| 	"PaymentCenter/app/http/entities/front" | 	"PaymentCenter/app/http/entities/front" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var FrontRequestMap = map[string]func() interface{}{ | var FrontRequestMap = map[string]func() (validForm interface{}, isSaveLog bool){ | ||||||
| 	common.FRONT_V1 + "/pay/url":    func() interface{} { return new(front.PayReqs) }, | 	common.FRONT_V1 + "/pay/url":    func() (interface{}, bool) { return new(front.PayReqs), true }, | ||||||
| 	common.FRONT_V1 + "/pay/refund": func() interface{} { return new(front.RefundReqs) }, | 	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{}{ | var FrontRequestMapBeforeDecrypt = map[string]func() interface{}{ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue