Pārlūkot izejas kodu

修改获取验证码方法、新增附件下载方法

maxiaoshan 3 gadi atpakaļ
vecāks
revīzija
bfc02e30d8
2 mainītis faili ar 50 papildinājumiem un 4 dzēšanām
  1. 1 1
      src/config.json
  2. 49 3
      src/spider/script.go

+ 1 - 1
src/config.json

@@ -56,7 +56,7 @@
         }
     },
     "oss":{
-    	"ossEndpoint":"oss-cn-beijing-internal.aliyuncs.com",
+    	"ossEndpoint":"oss-cn-beijing.aliyuncs.com",
 		"ossAccessKeyId":"LTAI4G5x9aoZx8dDamQ7vfZi",  
 		"ossAccessKeySecret":"Bk98FsbPYXcJe72n1bG3Ssf73acuNh",
 		"ossBucketName":"jy-editor",

+ 49 - 3
src/spider/script.go

@@ -547,18 +547,22 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 
 	//获取验证码
 	s.L.SetGlobal("getCodeByPath", s.L.NewFunction(func(S *lua.LState) int {
-		head := S.ToTable(-1)
-		cookie := S.ToString(-2)
+		cookie := S.ToString(-1)
+		head := S.ToTable(-2)
 		stype := S.ToString(-3)
 		path := S.ToString(-4)
 		headMap := util.GetTable(head)
-		qu.Debug("cookie", cookie)
+		//qu.Debug("cookie----------", cookie)
+		//qu.Debug("headMap----------", headMap)
 		headJsonStr := ""
 		headByte, err := json.Marshal(headMap)
 		if err == nil {
 			headJsonStr = string(headByte)
 		}
 		code, respHead, respCookie := codegrpc.GetCodeByPath(path, stype, headJsonStr, cookie)
+		//qu.Debug("code====", code)
+		//qu.Debug("respHead====", respHead)
+		//qu.Debug("respCookie====", respCookie)
 		S.Push(lua.LString(code))
 		respHeadMap := map[string]interface{}{}
 		json.Unmarshal([]byte(respHead), &respHeadMap)
@@ -567,6 +571,48 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 		S.Push(lua.LString(respCookie))
 		return 3
 	}))
+	s.L.SetGlobal("newDownloadFile", s.L.NewFunction(func(S *lua.LState) int {
+		cookie := S.ToString(-1)
+		head := S.ToTable(-2)
+		param := S.ToTable(-3)
+		method := S.ToString(-4)
+		url := S.ToString(-5)
+		fileName := S.ToString(-6)
+		ishttps := strings.Contains(url, "https")
+		var mycookie []*http.Cookie
+		if cookie != "{}" {
+			json.Unmarshal([]byte(cookie), &mycookie)
+		} else {
+			mycookie = make([]*http.Cookie, 0)
+		}
+		fileName = strings.TrimSpace(fileName)
+		url = strings.TrimSpace(url)
+		ret := NewDownloadFile(s.Downloader, url, method, util.GetTable(param), util.GetTable(head), mycookie, s.Encoding, false, ishttps, "", s.Timeout, false)
+
+		name, size, ftype, fid := "", "", "", ""
+		qu.Debug(GarbledCodeReg.FindAllString(string(ret), -1), len(ret))
+		if ret == nil || len(ret) < 1024*5 {
+			qu.Debug("下载文件出错!")
+		} else {
+			ftype = qu.GetFileType(ret)
+			if (ftype == "docx" || ftype == "doc") && len(GarbledCodeReg.FindAllString(string(ret), -1)) > 10 {
+				url, name, size, ftype, fid = "附件中含有乱码", "附件中含有乱码", "", "", ""
+			} else {
+				url, name, size, ftype, fid = util.UploadFile(s.SCode, fileName, url, ret)
+			}
+		}
+		if strings.TrimSpace(ftype) == "" {
+			if len(path.Ext(name)) > 0 {
+				ftype = path.Ext(name)[1:]
+			}
+		}
+		S.Push(lua.LString(url))
+		S.Push(lua.LString(name))
+		S.Push(lua.LString(size))
+		S.Push(lua.LString(ftype))
+		S.Push(lua.LString(fid))
+		return 5
+	}))
 }
 
 //