|
@@ -3,6 +3,8 @@ package common
|
|
|
import (
|
|
|
"errors"
|
|
|
"git.listensoft.net/tool/jspkit/common/lxrod"
|
|
|
+ "git.listensoft.net/tool/jspkit/common/models"
|
|
|
+ "git.listensoft.net/tool/jspkit/common/watermark"
|
|
|
"git.listensoft.net/tool/jspkit/logger"
|
|
|
"git.listensoft.net/tool/jspkit/taxerr"
|
|
|
"github.com/go-rod/rod"
|
|
@@ -10,6 +12,7 @@ import (
|
|
|
"github.com/go-rod/rod/lib/proto"
|
|
|
"github.com/go-rod/rod/lib/utils"
|
|
|
"go.uber.org/zap"
|
|
|
+ "os"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -350,3 +353,76 @@ func WaitHasX(page *rod.Page, xpath string) (x bool) {
|
|
|
}
|
|
|
return x
|
|
|
}
|
|
|
+
|
|
|
+func SaveErrImg(p *rod.Page, info models.CompanyInfo) string {
|
|
|
+ var check_path string
|
|
|
+ check_path = "./data/sbImg/" + info.TaxNo + "/"
|
|
|
+ if !PathExists(check_path) {
|
|
|
+ os.MkdirAll(check_path, os.ModePerm)
|
|
|
+ }
|
|
|
+ check_path = check_path + info.Period + "-" + time.Now().Format("2006-01-02-15-04-05") + ".png"
|
|
|
+ check_path2 := ""
|
|
|
+ _ = rod.Try(func() {
|
|
|
+ p.Timeout(ClickTimeOut).MustScreenshot(check_path)
|
|
|
+ watermark.Add(check_path)
|
|
|
+ check_path2 = PostSbjt(info.TaxNo, info.Period, check_path)
|
|
|
+ os.Remove(check_path)
|
|
|
+ })
|
|
|
+ return check_path2
|
|
|
+}
|
|
|
+
|
|
|
+// InputWithTimeout 规定时间内填入输入值,默认5s
|
|
|
+func InputWithTimeout(p *rod.Page, selector, inputVal string, timeout ...int64) {
|
|
|
+ var t int64
|
|
|
+ if len(timeout) == 0 {
|
|
|
+ t = 5
|
|
|
+ } else {
|
|
|
+ t = timeout[0]
|
|
|
+ }
|
|
|
+ p.Timeout(time.Duration(t) * time.Second).MustSearch(selector).MustSelectAllText().MustInput(inputVal)
|
|
|
+}
|
|
|
+
|
|
|
+func SaveErrImgTask(p *rod.Page, info *models.TaxTask) string {
|
|
|
+ var check_path string
|
|
|
+ check_path = "./data/sbImg/" + info.TaxNo + "/"
|
|
|
+ if !PathExists(check_path) {
|
|
|
+ os.MkdirAll(check_path, os.ModePerm)
|
|
|
+ }
|
|
|
+ check_path = check_path + info.Period + "-" + time.Now().Format("2006-01-02-15-04-05") + ".png"
|
|
|
+ var check_path2 string
|
|
|
+ _ = rod.Try(func() {
|
|
|
+ p.Timeout(ClickTimeOut).MustScreenshot(check_path)
|
|
|
+ watermark.Add(check_path)
|
|
|
+ check_path2 = PostSbjt(info.TaxNo, info.Period, check_path)
|
|
|
+ os.Remove(check_path)
|
|
|
+ })
|
|
|
+ return check_path2
|
|
|
+}
|
|
|
+
|
|
|
+// 使用键盘模拟输入
|
|
|
+func InputStrNew(page *rod.Page, el *rod.Element, str string) {
|
|
|
+ el.MustScrollIntoView()
|
|
|
+ box := el.MustShape().Box()
|
|
|
+ Click(page, box.X+(box.Width/2), box.Y+(box.Height/2))
|
|
|
+ time.Sleep(time.Millisecond * 100)
|
|
|
+ selectAll2(page)
|
|
|
+ time.Sleep(time.Millisecond * 100)
|
|
|
+ _ = page.Keyboard.Type(input.Delete)
|
|
|
+ _ = page.Keyboard.Type(input.Backspace)
|
|
|
+ time.Sleep(time.Millisecond * 100)
|
|
|
+ _ = page.Keyboard.Type(input.Backspace)
|
|
|
+ for _, v := range str {
|
|
|
+ _ = page.Keyboard.Type(input.Key(v))
|
|
|
+ time.Sleep(time.Millisecond * 100)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func Click(page *rod.Page, x, y float64) {
|
|
|
+ page.Mouse.MustMoveTo(x, y)
|
|
|
+ time.Sleep(time.Millisecond * 100)
|
|
|
+ page.Mouse.MustDown("left")
|
|
|
+ page.Mouse.MustUp("left")
|
|
|
+}
|
|
|
+func selectAll2(page *rod.Page) {
|
|
|
+ page.Keyboard.MustType(input.ControlLeft).MustType('a').MustType('a').MustType(input.ControlLeft)
|
|
|
+}
|