Procházet zdrojové kódy

wip:提交异常修改

wangkaiyue před 1 rokem
rodič
revize
44b2ec9293

+ 11 - 11
core/proxy/filterPoly/verifyDetail.go

@@ -5,19 +5,19 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/gateway/core/util"
 	"encoding/json"
 	"fmt"
+	"github.com/gogf/gf/v2/net/ghttp"
 	"github.com/gogf/gf/v2/util/gconv"
 	"math"
-	"net/http"
 	"strings"
 )
 
 // VerifyHandle 验证码处理
-func (a *ReqFilterPoly) VerifyHandle(req *http.Request, key string) map[string]interface{} {
+func (a *ReqFilterPoly) VerifyHandle(r *ghttp.Request, key string) map[string]interface{} {
 	//_ = req.ParseForm()
-	util.CopyReqAndFormData(req, false)
-	vc := req.Form.Get("antiVerifyCheck")
+	util.CopyReqAndFormData(r.Request, false)
+	vc := r.Request.Form.Get("antiVerifyCheck")
 	if vc == "" {
-		vc = req.Header.Get("antiVerifyCheck")
+		vc = r.Request.Header.Get("antiVerifyCheck")
 	}
 	vKey := fmt.Sprintf(VerifyRedisKey, key)
 	result := map[string]interface{}{
@@ -31,16 +31,16 @@ func (a *ReqFilterPoly) VerifyHandle(req *http.Request, key string) map[string]i
 			}
 			var result = [][]int{}
 			if err := json.Unmarshal(va, &result); err != nil {
-				log.WithContext(req.Context()).Errorf("%s Unmarshal 出错 %v\n", key, err)
+				log.WithContext(r.Context()).Errorf("%s Unmarshal 出错 %v\n", key, err)
 				return false
 			}
 			vcArr := strings.Split(vc, ";")
 			if len(vcArr) != len(result) {
-				log.WithContext(req.Context()).Infof("用户%s验证码校验失败 选择数量不足 \n正确坐标:%v\n输入坐标%v \n", key, result, vcArr)
+				log.WithContext(r.Context()).Infof("用户%s验证码校验失败 选择数量不足 \n正确坐标:%v\n输入坐标%v \n", key, result, vcArr)
 				return false
 			}
 
-			imgWidth := gconv.Int(req.Form.Get("imgw")) //app端图片宽度改变
+			imgWidth := gconv.Int(r.Request.Form.Get("imgw")) //app端图片宽度改变
 			for index, pos := range vcArr {
 				p := strings.Split(pos, ",")
 				if len(p) != 2 {
@@ -54,11 +54,11 @@ func (a *ReqFilterPoly) VerifyHandle(req *http.Request, key string) map[string]i
 				}
 
 				if d := Distance(px, py, result[index][0], result[index][1]); d > 15 {
-					log.WithContext(req.Context()).Infof("用户%s验证码校验失败 w:%d 第(%d)校验结果%f\n正确坐标:%v\n输入坐标%v \n", key, imgWidth, index, d, result, vcArr)
+					log.WithContext(r.Context()).Infof("用户%s验证码校验失败 w:%d 第(%d)校验结果%f\n正确坐标:%v\n输入坐标%v \n", key, imgWidth, index, d, result, vcArr)
 					return false
 				}
 			}
-			log.WithContext(req.Context()).Infof("用户%s验证码校验通过\n", key)
+			log.WithContext(r.Context()).Infof("用户%s验证码校验通过\n", key)
 			return true
 		}()
 		if ok {
@@ -79,7 +79,7 @@ func (a *ReqFilterPoly) VerifyHandle(req *http.Request, key string) map[string]i
 		result["imgData"] = checkVerify.imgBase64
 		result["textVerify"] = checkVerify.Key
 	}
-	req.Response.Header.Add("antiVerify", gconv.String(result["antiVerify"]))
+	r.Response.Header().Add("antiVerify", gconv.String(result["antiVerify"]))
 	return result
 }
 

+ 1 - 1
core/proxy/middleware/spiderPolyHandler.go

@@ -59,7 +59,7 @@ func FilterPolyHandler(r *ghttp.Request) {
 			return
 		}
 		if status == 2 { //处理验证码逻辑
-			rData := poly.VerifyHandle(r.Request, key)
+			rData := poly.VerifyHandle(r, key)
 			if !returnHtml {
 				r.Response.WriteJsonExit(rData)
 			} else {

+ 1 - 2
core/util/http.go

@@ -146,8 +146,7 @@ func ChangeResponse(resp *http.Response, fn func([]byte) ([]byte, error)) (err e
 	newContent, err = fn(content)
 	if err != nil {
 		g.Log().Errorf(ctx, "changeRes func %v err %v", fn, err)
-		//} else {
-		//	newContent = content
+		newContent = content
 	}
 
 	var zBuf bytes.Buffer