maxiaoshan 2 年之前
父节点
当前提交
0c57d26e55
共有 2 个文件被更改,包括 12 次插入0 次删除
  1. 3 0
      src/main.go
  2. 9 0
      src/spider/script.go

+ 3 - 0
src/main.go

@@ -4,6 +4,7 @@ import (
 	codegrpc "analysiscode/client"
 	_ "filter"
 	"fmt"
+	gojs "gorunjs/client"
 	"io/ioutil"
 	"os"
 	"spider"
@@ -33,6 +34,8 @@ func init() {
 	spider.InitOther() //加载其他信息
 	//验证码识别client
 	codegrpc.InitCodeGrpcClient()
+	//go执行js服务
+	gojs.InitGoRunJsClient()
 	//InitRedis(Config.Redisservers) //初始化Redis
 	//redis集群
 	InitRedisCluster(Config.RedisClusterAddrs)

+ 9 - 0
src/spider/script.go

@@ -14,6 +14,7 @@ import (
 	"encoding/base64"
 	"encoding/json"
 	"github.com/shopspring/decimal"
+	gojs "gorunjs/client"
 	"io/ioutil"
 	mu "mfw/util"
 	"net/http"
@@ -906,6 +907,14 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
 		S.Push(lua.LString(respCookie))
 		return 3
 	}))
+	s.L.SetGlobal("goRunJs", s.L.NewFunction(func(S *lua.LState) int {
+		param := S.ToString(-2) //list or detail
+		step := S.ToString(-1)  //参数
+		result := gojs.GoRunJsGetResult(s.SCode, param, step)
+		qu.Debug("Go Run Js Result:", param, step, result)
+		S.Push(lua.LString(result))
+		return 1
+	}))
 	s.L.SetGlobal("newDownloadFile", s.L.NewFunction(func(S *lua.LState) int {
 		cookie := S.ToString(-1)
 		head := S.ToTable(-2)