mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
feat: slider captcha processor
This commit is contained in:
parent
ae7fefad13
commit
2a0babad99
@ -3,6 +3,7 @@ package gocq
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/png"
|
"image/png"
|
||||||
"os"
|
"os"
|
||||||
@ -10,9 +11,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
)
|
)
|
||||||
@ -142,7 +145,19 @@ func loginResponseProcessor(res *client.LoginResponse) error {
|
|||||||
var text string
|
var text string
|
||||||
switch res.Error {
|
switch res.Error {
|
||||||
case client.SliderNeededError:
|
case client.SliderNeededError:
|
||||||
log.Warnf("登录需要滑条验证码, 请使用手机QQ扫描二维码以继续登录.")
|
log.Warnf("登录需要滑条验证码, 请选择验证方式: ")
|
||||||
|
log.Warnf("1. 使用浏览器抓取滑条并登录")
|
||||||
|
log.Warnf("2. 使用手机QQ扫码验证 (需要手Q和gocq在同一网络下).")
|
||||||
|
log.Warn("请输入(1 - 2) (将在10秒后自动选择1):")
|
||||||
|
text = readLineTimeout(time.Second*10, "1")
|
||||||
|
if strings.Contains(text, "1") {
|
||||||
|
ticket := sliderCaptchaProcessor(res.VerifyUrl)
|
||||||
|
if ticket == "" {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
res, err = cli.SubmitTicket(ticket)
|
||||||
|
continue
|
||||||
|
}
|
||||||
cli.Disconnect()
|
cli.Disconnect()
|
||||||
cli.Release()
|
cli.Release()
|
||||||
cli = client.NewClientEmpty()
|
cli = client.NewClientEmpty()
|
||||||
@ -202,3 +217,23 @@ func loginResponseProcessor(res *client.LoginResponse) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sliderCaptchaProcessor(u string) string {
|
||||||
|
id := utils.RandomString(8)
|
||||||
|
log.Warnf("请前往该地址验证 -> %v", strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id)))
|
||||||
|
start := time.Now()
|
||||||
|
for time.Now().Sub(start).Minutes() < 2 {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
data, err := global.GetBytes("https://captcha.go-cqhttp.org/captcha/ticket?id=" + id)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("获取 Ticket 时出现错误: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
g := gjson.ParseBytes(data)
|
||||||
|
if g.Get("ticket").Exists() {
|
||||||
|
return g.Get("ticket").String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Warnf("验证超时")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.18
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Microsoft/go-winio v0.5.1
|
github.com/Microsoft/go-winio v0.5.1
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20220621055318-d1a66c42b67e
|
github.com/Mrs4s/MiraiGo v0.0.0-20220621083050-ae8c187aa59d
|
||||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c
|
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
|
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
|
||||||
github.com/fumiama/go-base16384 v1.5.2
|
github.com/fumiama/go-base16384 v1.5.2
|
||||||
|
4
go.sum
4
go.sum
@ -1,7 +1,7 @@
|
|||||||
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
|
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
|
||||||
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
|
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20220621055318-d1a66c42b67e h1:xPHtwF8AYB2N055t1sNPC6+2FMy2dujV2Rp7Bf928w4=
|
github.com/Mrs4s/MiraiGo v0.0.0-20220621083050-ae8c187aa59d h1:Cq8HMtyL3PRpvOynuwi9WSdek2+5UTOd0zJ+JTq5hPM=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20220621055318-d1a66c42b67e/go.mod h1:mZp8Lt7uqLCUwSLouB2yuiP467Cwl4mnG9IMAaXUKA0=
|
github.com/Mrs4s/MiraiGo v0.0.0-20220621083050-ae8c187aa59d/go.mod h1:mZp8Lt7uqLCUwSLouB2yuiP467Cwl4mnG9IMAaXUKA0=
|
||||||
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a h1:WIfEWYj82oEuPtm5pqlyQmCJCoiw00C6ugZFqHA0cC8=
|
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a h1:WIfEWYj82oEuPtm5pqlyQmCJCoiw00C6ugZFqHA0cC8=
|
||||||
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
|
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
|
||||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
|
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user