Ver código fonte

change chrome - 4

abiao 2 anos atrás
pai
commit
6b0221ed35

+ 2 - 2
go/gopath/src/fohow.com/apps/controllers/tool_controller/init.go

@@ -15,8 +15,8 @@ import (
 )
 
 var (
-	exceptCheckUserLoginAction   = []string{"GetQrcode", "GetHaibao", "GetHaibaoWithGoogle", "Monitor", "GetExpressCompany", "GetExpressInfo"}
-	exceptCheckWxUserLoginAction = []string{"GetQrcode", "GetHaibao", "GetHaibaoWithGoogle", "Monitor", "GetExpressCompany", "GetExpressInfo"}
+	exceptCheckUserLoginAction   = []string{"GetQrcode", "GetHaibao", "GetOtherHaibaoWithGoogle", "GetHaibaoWithGoogle", "Monitor", "GetExpressCompany", "GetExpressInfo"}
+	exceptCheckWxUserLoginAction = []string{"GetQrcode", "GetHaibao", "GetOtherHaibaoWithGoogle", "GetHaibaoWithGoogle", "Monitor", "GetExpressCompany", "GetExpressInfo"}
 )
 
 type ToolController struct {

+ 50 - 0
go/gopath/src/fohow.com/apps/controllers/tool_controller/qrcode_controller.go

@@ -103,6 +103,56 @@ func (self *ToolController) GetHaibaoWithGoogle() {
 	//log.Println("Screenshot saved as screenshot.png")
 }
 
+func (self *ToolController) GetOtherHaibaoWithGoogle() {
+	uri := self.GetString("url")
+	fmt.Println("url:", uri)
+
+	// URL 解码
+	decodedUri, err := url.QueryUnescape(uri)
+	if err != nil {
+		fmt.Println("Error in decoding:", err)
+		log.Fatal(err)
+	}
+
+	fmt.Println("Decoded URI:", decodedUri)
+	//title := self.GetString("title")
+	// 创建上下文
+	ctx, cancel := chromedp.NewContext(context.Background())
+	defer cancel()
+
+	// 设置超时时间
+	ctx, cancel = context.WithTimeout(ctx, 60*time.Second)
+	defer cancel()
+
+	// 运行任务(导航到网页,并捕获屏幕截图)
+	var buf []byte
+	err = chromedp.Run(ctx,
+		chromedp.EmulateViewport(1400, 800),          // 设置视口宽度为 1400,高度为 800
+		chromedp.Navigate(decodedUri),                // 替换为你想截图的网页地址
+		chromedp.WaitReady("body", chromedp.ByQuery), // 等待页面的 <body> 元素加载完成
+		//chromedp.WaitReady("#overload", chromedp.ByID),
+		chromedp.Sleep(5*time.Second),
+		chromedp.FullScreenshot(&buf, 90), // 调整质量参数
+	)
+	if err != nil {
+		fmt.Println("error occured!")
+		log.Fatal(err)
+	}
+
+	//fileName := fmt.Sprintf("%s.png", "shot_screen")
+	//// 将截图保存到文件
+	//err = ioutil.WriteFile(fileName, buf, 0644)
+	//if err != nil {
+	//	log.Fatal(err)
+	//}
+
+	//fmt.Println("image buf:", buf)
+	self.Ctx.Output.Header("Content-Type", "image/png")
+	self.Ctx.Output.Body(buf)
+
+	//log.Println("Screenshot saved as screenshot.png")
+}
+
 func (self *ToolController) GetQrcode() {
 	uri := self.GetString("url")
 	// if !isWhiteUrl(uri) {

+ 2 - 0
go/gopath/src/fohow.com/routers/routes.go

@@ -267,6 +267,8 @@ func init() {
 
 	// 一些通用工具
 	beego.Router("/v1/tool/haibao", &tool_controller.ToolController{}, "get:GetHaibaoWithGoogle")
+	beego.Router("/v1/tool/other_haibao", &tool_controller.ToolController{}, "get:GetOtherHaibaoWithGoogle")
+
 	beego.Router("/v1/tool/qrcode", &tool_controller.ToolController{}, "get:GetQrcode")
 	//监控服务器状态接口
 	beego.Router("/v1/tool/monitor", &tool_controller.ToolController{}, "get:Monitor")