maxiaoshan 2 лет назад
Родитель
Сommit
81bbdb4603
4 измененных файлов с 23 добавлено и 12 удалено
  1. 15 7
      src/analysiscode/server.go
  2. 1 1
      src/spiderutil/oss.go
  3. 6 3
      src/spiderutil/sysconfig.go
  4. 1 1
      src/spiderutil/upload.go

+ 15 - 7
src/analysiscode/server.go

@@ -56,16 +56,16 @@ func (cs *CodeService) GetCodeByImgPath(ctx context.Context, req *proto.GetCodeb
 func getCode(path, stype, head, cookie string) (code string, respheader http.Header, respcookie []*http.Cookie) {
 	//先用免费,为识别再用收费
 	coderesp := &req.Response{}
-	code, respheader, respcookie, coderesp = getCodeByFree(path, head, cookie) //自己的服务
+	code, respheader, respcookie, coderesp = getCodeByFree(path, stype, head, cookie) //自己的服务
 	util.Debug("Get Code By Free Result:", code)
-	if len(code) < 4 { //免费的未能识别使用超级鹰
+	if util.IntAll(stype) > 0 && len(code) < 4 { //免费的未能识别使用超级鹰
 		savefile(path, coderesp)                                               //保存图片
 		code, respheader, respcookie = getCodeByPay(path, stype, head, cookie) //超级鹰收费
 	}
 	return
 }
 
-func getCodeByFree(path, head, cookie string) (code string, respheader http.Header, respcookie []*http.Cookie, getCodeResp *req.Response) {
+func getCodeByFree(path, stype, head, cookie string) (code string, respheader http.Header, respcookie []*http.Cookie, getCodeResp *req.Response) {
 	defer util.Catch()
 	client := req.C().SetTimeout(spiderutil.Config.TimeOut * time.Second)
 	headers := map[string]string{}
@@ -86,7 +86,13 @@ func getCodeByFree(path, head, cookie string) (code string, respheader http.Head
 		}
 		//下载验证码图片
 		var err error
-		getCodeResp, err = request.Get(path)
+		var resultByte []byte
+		if stype == "-1" { //传base64的图片
+			resultByte = []byte(path)
+		} else { //通过请求图片地址返回的byte
+			getCodeResp, err = request.Get(path)
+			resultByte = getCodeResp.Bytes()
+		}
 		if err != nil {
 			util.Debug("Get Code By Path Error: ", err)
 			continue
@@ -94,7 +100,7 @@ func getCodeByFree(path, head, cookie string) (code string, respheader http.Head
 		//解析验证码
 		codeResp, err := client.R().
 			SetHeader("accept", "application/json").
-			SetFileReader("file", "1", bytes.NewReader(getCodeResp.Bytes())).
+			SetFileReader("file", "1", bytes.NewReader(resultByte)).
 			Post(spiderutil.Config.ServerCodefreeAddress)
 		if err != nil {
 			util.Debug("analysis code by path err: ", err)
@@ -106,8 +112,10 @@ func getCodeByFree(path, head, cookie string) (code string, respheader http.Head
 		yzm := util.ObjToString(yzmResult["r"].(map[string]interface{})["code"])
 		if yzm != "" && len(yzm) >= 4 {
 			code = yzm //长度小于4的视为识别错误
-			respheader = getCodeResp.Header
-			respcookie = getCodeResp.Cookies()
+			if getCodeResp != nil {
+				respheader = getCodeResp.Header
+				respcookie = getCodeResp.Cookies()
+			}
 			return
 		}
 	}

+ 1 - 1
src/spiderutil/oss.go

@@ -97,7 +97,7 @@ func demoDownFile(filename string, objectName string) {
 	}
 }
 
-func getHashKey(bs []byte) string {
+func GetHashKey(bs []byte) string {
 	util.Catch()
 	ha := sha256.New()
 	ha.Write(bs)

+ 6 - 3
src/spiderutil/sysconfig.go

@@ -101,12 +101,15 @@ type config struct {
 	SystemDB dbInfo `json:"systemdb"`
 	//基本数据库
 	DataDB dbInfo `json:"datadb"`
+	//spider数据库
+	LuaSpiderDB dbInfo `json:"luaspiderdb"`
 }
 
 type flow struct {
-	Memo string `json:"memo"`
-	Addr string `json:"addr"`
-	Port int    `json:"port"`
+	Memo  string `json:"memo"`
+	Addr  string `json:"addr"`
+	Port  int    `json:"port"`
+	Stype string `json:"stype"`
 }
 
 type dbInfo struct {

+ 1 - 1
src/spiderutil/upload.go

@@ -108,7 +108,7 @@ func UploadFile(code, fileName, url string, bt []byte) (string, string, string,
 	// } else {
 	// 	fileName = name
 	// }
-	key := getHashKey(bt) + TypeByExt(fileName)
+	key := GetHashKey(bt) + TypeByExt(fileName)
 	b, _ := OssPutObject(key, io.MultiReader(bs))
 	if b {
 		logger.Debug("上传文件成功!", code, "	", url, "	", key, "	", fileName, size)