Browse Source

调整pass防水墙的示例位置

Signed-off-by: allan716 <[email protected]>
allan716 4 years ago
parent
commit
310f7a5c7f
4 changed files with 118 additions and 98 deletions
  1. 1 0
      .gitignore
  2. 109 0
      common/pass_water_wall.go
  3. 8 0
      common/pass_water_wall_test.go
  4. 0 98
      sub_supplier/subhd/subhd.go

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 /.idea
 /sub_supplier/subhd/result.png
+/common/result.png

+ 109 - 0
common/pass_water_wall.go

@@ -0,0 +1,109 @@
+package common
+
+import (
+	"bytes"
+	"fmt"
+	"github.com/nfnt/resize"
+	"image/jpeg"
+	"math"
+	"strings"
+	"time"
+)
+
+// SimulationTest 模拟滑动过防水墙
+func SimulationTest() {
+	// 感谢 https://www.bigs3.com/article/gorod-crack-slider-captcha/
+	page, err := NewBrowserLoadPage("https://007.qq.com/online.html", "", 10*time.Second, 5)
+	if err != nil {
+		println(err.Error())
+		return
+	}
+	// 切换到可疑用户
+	page.MustElement("#app > section.wp-on-online > div > div > div > div.wp-on-box.col-md-5.col-md-offset-1 > div.wp-onb-tit > a:nth-child(2)").MustClick()
+	//模擬Click點擊 "體驗驗證碼" 按鈕
+	page.MustElement("#code").MustClick()
+	//等待驗證碼窗體載入
+	page.MustElement("#tcaptcha_iframe").MustWaitLoad()
+	//進入到iframe
+	iframe := page.MustElement("#tcaptcha_iframe").MustFrame()
+	//等待拖動條加載, 延遲500秒檢測變化, 以確認加載完畢
+	iframe.MustElement("#tcaptcha_drag_button").WaitStable(500 * time.Millisecond)
+	//等待缺口圖像載入
+	iframe.MustElement("#slideBg").MustWaitLoad()
+
+
+	//取得帶缺口圖像
+	shadowbg := iframe.MustElement("#slideBg").MustResource()
+	//取得原始圖像
+	src := iframe.MustElement("#slideBg").MustProperty("src")
+	fullbg, fileName, err := DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
+	if err != nil {
+		return
+	}
+	println(fileName)
+	//取得img展示的真實尺寸
+	bgbox := iframe.MustElement("#slideBg").MustShape().Box()
+	height, width := uint(math.Round(bgbox.Height)), uint(math.Round(bgbox.Width))
+	//裁剪圖像
+	shadowbg_img, _ := jpeg.Decode(bytes.NewReader(shadowbg))
+	shadowbg_img = resize.Resize(width, height, shadowbg_img, resize.Lanczos3)
+	fullbg_img, _ := jpeg.Decode(bytes.NewReader(fullbg))
+	fullbg_img = resize.Resize(width, height, fullbg_img, resize.Lanczos3)
+
+	//啓始left,排除干擾部份,所以右移10個像素
+	left := fullbg_img.Bounds().Min.X + 10
+
+	//啓始top, 排除干擾部份, 所以下移10個像素
+	top := fullbg_img.Bounds().Min.Y + 10
+
+	//最大left, 排除干擾部份, 所以左移10個像素
+	maxleft := fullbg_img.Bounds().Max.X - 10
+
+	//最大top, 排除干擾部份, 所以上移10個像素
+	maxtop := fullbg_img.Bounds().Max.Y - 10
+
+	//rgb比较阈值, 超出此阈值及代表找到缺口位置
+	threshold := 20
+
+	//缺口偏移, 拖動按鈕初始會偏移27.5
+	distance := -27.5
+
+	//取絕對值方法
+	abs := func(n int) int {
+		if n < 0 {
+			return -n
+		}
+		return n
+	}
+search:
+	for i := left; i <= maxleft; i++ {
+		for j := top; j <= maxtop; j++ {
+			color_a_R, color_a_G, color_a_B, _ := fullbg_img.At(i, j).RGBA()
+			color_b_R, color_b_G, color_b_B, _ := shadowbg_img.At(i, j).RGBA()
+			color_a_R, color_a_G, color_a_B = color_a_R >> 8, color_a_G >> 8, color_a_B >> 8
+			color_b_R, color_b_G, color_b_B = color_b_R >> 8, color_b_G >> 8, color_b_B >> 8
+			if abs(int(color_a_R) - int(color_b_R)) > threshold ||
+				abs(int(color_a_G) - int(color_b_G)) > threshold ||
+				abs(int(color_a_B) - int(color_b_B)) > threshold {
+				distance += float64(i)
+				fmt.Printf("info: 對比完畢, 偏移量: %v\n", distance)
+				break search
+			}
+		}
+	}
+
+	//獲取拖動按鈕形狀
+	dragbtnbox := iframe.MustElement("#tcaptcha_drag_thumb").MustShape().Box()
+	//启用滑鼠功能
+	mouse := page.Mouse
+	//模擬滑鼠移動至拖動按鈕處, 右移3的原因: 拖動按鈕比滑塊圖大3個像素
+	mouse.MustMove(dragbtnbox.X + 3, dragbtnbox.Y + (dragbtnbox.Height / 2))
+	//按下滑鼠左鍵
+	mouse.MustDown("left")
+	//開始拖動
+	mouse.Move(dragbtnbox.X + distance, dragbtnbox.Y + (dragbtnbox.Height / 2), 20)
+	//鬆開滑鼠左鍵, 拖动完毕
+	mouse.MustUp("left")
+	//截圖保存
+	page.MustScreenshot("result.png")
+}

+ 8 - 0
common/pass_water_wall_test.go

@@ -0,0 +1,8 @@
+package common
+
+import "testing"
+
+func TestSimulationTest(t *testing.T) {
+
+	SimulationTest()
+}

+ 0 - 98
sub_supplier/subhd/subhd.go

@@ -370,104 +370,6 @@ func (s Supplier) httpPost(url string, postData map[string]string, referer strin
 	return resp.String(), nil
 }
 
-// SimulationTest 模拟滑动过防水墙
-func (s Supplier) SimulationTest() {
-	// 感谢 https://www.bigs3.com/article/gorod-crack-slider-captcha/
-	page, err := common.NewBrowserLoadPage("https://007.qq.com/online.html", "", 10*time.Second, 5)
-	if err != nil {
-		println(err.Error())
-		return
-	}
-	// 切换到可疑用户
-	page.MustElement("#app > section.wp-on-online > div > div > div > div.wp-on-box.col-md-5.col-md-offset-1 > div.wp-onb-tit > a:nth-child(2)").MustClick()
-	//模擬Click點擊 "體驗驗證碼" 按鈕
-	page.MustElement("#code").MustClick()
-	//等待驗證碼窗體載入
-	page.MustElement("#tcaptcha_iframe").MustWaitLoad()
-	//進入到iframe
-	iframe := page.MustElement("#tcaptcha_iframe").MustFrame()
-	//等待拖動條加載, 延遲500秒檢測變化, 以確認加載完畢
-	iframe.MustElement("#tcaptcha_drag_button").WaitStable(500 * time.Millisecond)
-	//等待缺口圖像載入
-	iframe.MustElement("#slideBg").MustWaitLoad()
-
-
-	//取得帶缺口圖像
-	shadowbg := iframe.MustElement("#slideBg").MustResource()
-	//取得原始圖像
-	src := iframe.MustElement("#slideBg").MustProperty("src")
-	fullbg, fileName, err := common.DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
-	if err != nil {
-		return
-	}
-	println(fileName)
-	//取得img展示的真實尺寸
-	bgbox := iframe.MustElement("#slideBg").MustShape().Box()
-	height, width := uint(math.Round(bgbox.Height)), uint(math.Round(bgbox.Width))
-	//裁剪圖像
-	shadowbg_img, _ := jpeg.Decode(bytes.NewReader(shadowbg))
-	shadowbg_img = resize.Resize(width, height, shadowbg_img, resize.Lanczos3)
-	fullbg_img, _ := jpeg.Decode(bytes.NewReader(fullbg))
-	fullbg_img = resize.Resize(width, height, fullbg_img, resize.Lanczos3)
-
-	//啓始left,排除干擾部份,所以右移10個像素
-	left := fullbg_img.Bounds().Min.X + 10
-
-	//啓始top, 排除干擾部份, 所以下移10個像素
-	top := fullbg_img.Bounds().Min.Y + 10
-
-	//最大left, 排除干擾部份, 所以左移10個像素
-	maxleft := fullbg_img.Bounds().Max.X - 10
-
-	//最大top, 排除干擾部份, 所以上移10個像素
-	maxtop := fullbg_img.Bounds().Max.Y - 10
-
-	//rgb比较阈值, 超出此阈值及代表找到缺口位置
-	threshold := 20
-
-	//缺口偏移, 拖動按鈕初始會偏移27.5
-	distance := -27.5
-
-	//取絕對值方法
-	abs := func(n int) int {
-		if n < 0 {
-			return -n
-		}
-		return n
-	}
-	search:
-	for i := left; i <= maxleft; i++ {
-		for j := top; j <= maxtop; j++ {
-			color_a_R, color_a_G, color_a_B, _ := fullbg_img.At(i, j).RGBA()
-			color_b_R, color_b_G, color_b_B, _ := shadowbg_img.At(i, j).RGBA()
-			color_a_R, color_a_G, color_a_B = color_a_R >> 8, color_a_G >> 8, color_a_B >> 8
-			color_b_R, color_b_G, color_b_B = color_b_R >> 8, color_b_G >> 8, color_b_B >> 8
-			if abs(int(color_a_R) - int(color_b_R)) > threshold ||
-				abs(int(color_a_G) - int(color_b_G)) > threshold ||
-				abs(int(color_a_B) - int(color_b_B)) > threshold {
-				distance += float64(i)
-				fmt.Printf("info: 對比完畢, 偏移量: %v\n", distance)
-				break search
-			}
-		}
-	}
-
-	//獲取拖動按鈕形狀
-	dragbtnbox := iframe.MustElement("#tcaptcha_drag_thumb").MustShape().Box()
-	//启用滑鼠功能
-	mouse := page.Mouse
-	//模擬滑鼠移動至拖動按鈕處, 右移3的原因: 拖動按鈕比滑塊圖大3個像素
-	mouse.MustMove(dragbtnbox.X + 3, dragbtnbox.Y + (dragbtnbox.Height / 2))
-	//按下滑鼠左鍵
-	mouse.MustDown("left")
-	//開始拖動
-	mouse.Move(dragbtnbox.X + distance, dragbtnbox.Y + (dragbtnbox.Height / 2), 20)
-	//鬆開滑鼠左鍵, 拖动完毕
-	mouse.MustUp("left")
-	//截圖保存
-	page.MustScreenshot("result.png")
-}
-
 type HdListItem struct {
 	Url        string `json:"url"`
 	BaseUrl    string `json:"baseUrl"`