|
@@ -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 {
|
|
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)
|
|
stype := S.ToString(-3)
|
|
path := S.ToString(-4)
|
|
path := S.ToString(-4)
|
|
headMap := util.GetTable(head)
|
|
headMap := util.GetTable(head)
|
|
- qu.Debug("cookie", cookie)
|
|
|
|
|
|
+ //qu.Debug("cookie----------", cookie)
|
|
|
|
+ //qu.Debug("headMap----------", headMap)
|
|
headJsonStr := ""
|
|
headJsonStr := ""
|
|
headByte, err := json.Marshal(headMap)
|
|
headByte, err := json.Marshal(headMap)
|
|
if err == nil {
|
|
if err == nil {
|
|
headJsonStr = string(headByte)
|
|
headJsonStr = string(headByte)
|
|
}
|
|
}
|
|
code, respHead, respCookie := codegrpc.GetCodeByPath(path, stype, headJsonStr, cookie)
|
|
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))
|
|
S.Push(lua.LString(code))
|
|
respHeadMap := map[string]interface{}{}
|
|
respHeadMap := map[string]interface{}{}
|
|
json.Unmarshal([]byte(respHead), &respHeadMap)
|
|
json.Unmarshal([]byte(respHead), &respHeadMap)
|
|
@@ -567,6 +571,48 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
|
|
S.Push(lua.LString(respCookie))
|
|
S.Push(lua.LString(respCookie))
|
|
return 3
|
|
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
|
|
|
|
+ }))
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|