|
|
@@ -1,7 +1,13 @@
|
|
|
package tool_controller
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"fmt"
|
|
|
+ "github.com/chromedp/chromedp"
|
|
|
+ "io/ioutil"
|
|
|
+ "log"
|
|
|
+ "time"
|
|
|
+
|
|
|
// "os"
|
|
|
"net/url"
|
|
|
// "strings"
|
|
|
@@ -48,6 +54,34 @@ func (self *ToolController) GetHaibao() {
|
|
|
self.Ctx.Output.Body(out)
|
|
|
}
|
|
|
|
|
|
+func (self *ToolController) GetHaibaoWithGoogle() {
|
|
|
+ // 创建上下文
|
|
|
+ ctx, cancel := chromedp.NewContext(context.Background())
|
|
|
+ defer cancel()
|
|
|
+
|
|
|
+ // 设置超时时间
|
|
|
+ ctx, cancel = context.WithTimeout(ctx, 15*time.Second)
|
|
|
+ defer cancel()
|
|
|
+
|
|
|
+ // 运行任务(导航到网页,并捕获屏幕截图)
|
|
|
+ var buf []byte
|
|
|
+ err := chromedp.Run(ctx,
|
|
|
+ chromedp.Navigate(`https://www.baidu.com`), // 替换为你想截图的网页地址
|
|
|
+ chromedp.FullScreenshot(&buf, 90), // 调整质量参数
|
|
|
+ )
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将截图保存到文件
|
|
|
+ err = ioutil.WriteFile("screenshot.png", buf, 0644)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Println("Screenshot saved as screenshot.png")
|
|
|
+}
|
|
|
+
|
|
|
func (self *ToolController) GetQrcode() {
|
|
|
uri := self.GetString("url")
|
|
|
// if !isWhiteUrl(uri) {
|
|
|
@@ -62,6 +96,7 @@ func (self *ToolController) GetQrcode() {
|
|
|
self.Ctx.Output.Header("Content-Type", "image/png; charset=utf-8")
|
|
|
self.Ctx.Output.Body(png)
|
|
|
}
|
|
|
+
|
|
|
func createQrcode(uri string, size int) ([]byte, error) {
|
|
|
png, err := qrcode.Encode(uri, qrcode.Medium, size)
|
|
|
return png, err
|