Skip to content

Commit

Permalink
feat: slider captcha processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Jun 21, 2022
1 parent ae7fefa commit 2a0baba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
37 changes: 36 additions & 1 deletion cmd/gocq/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package gocq
import (
"bufio"
"bytes"
"fmt"
"image"
"image/png"
"os"
"strings"
"time"

"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/mattn/go-colorable"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"

"github.com/Mrs4s/go-cqhttp/global"
)
Expand Down Expand Up @@ -142,7 +145,19 @@ func loginResponseProcessor(res *client.LoginResponse) error {
var text string
switch res.Error {
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.Release()
cli = client.NewClientEmpty()
Expand Down Expand Up @@ -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 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
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/websocket v1.4.3-0.20220123145318-307a86b127bc
github.com/fumiama/go-base16384 v1.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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/Mrs4s/MiraiGo v0.0.0-20220621055318-d1a66c42b67e h1:xPHtwF8AYB2N055t1sNPC6+2FMy2dujV2Rp7Bf928w4=
github.com/Mrs4s/MiraiGo v0.0.0-20220621055318-d1a66c42b67e/go.mod h1:mZp8Lt7uqLCUwSLouB2yuiP467Cwl4mnG9IMAaXUKA0=
github.com/Mrs4s/MiraiGo v0.0.0-20220621083050-ae8c187aa59d h1:Cq8HMtyL3PRpvOynuwi9WSdek2+5UTOd0zJ+JTq5hPM=
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/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
Expand Down

0 comments on commit 2a0baba

Please sign in to comment.