1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

cmd/gocq: support select ticket input method

This commit is contained in:
wdvxdr 2023-02-19 15:00:19 +08:00
parent 0e5f3ed555
commit 811cfdca98

View File

@ -225,25 +225,29 @@ func loginResponseProcessor(res *client.LoginResponse) error {
} }
} }
func getTicket(u string) (str string) { func getTicket(u string) string {
log.Warnf("请选择提交滑块ticket方式:")
log.Warnf("1. 自动提交")
log.Warnf("2. 手动抓取提交")
log.Warn("请输入(1 - 2)")
text := readLine()
id := utils.RandomString(8) id := utils.RandomString(8)
log.Warnf("请前往该地址验证 -> %v <- 或输入手动抓取的 ticketEnter 提交)", strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id))) auto := !strings.Contains(text, "2")
manual := make(chan string, 1) if auto {
go func() { u = strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id))
manual <- readLine() }
}() log.Warnf("请前往该地址验证 -> %v ", u)
ticker := time.NewTicker(time.Second) if !auto {
defer ticker.Stop() log.Warn("请输入ticket (Enter 提交)")
return readLine()
}
for count := 120; count > 0; count-- { for count := 120; count > 0; count-- {
select { str := fetchCaptcha(id)
case <-ticker.C:
str = fetchCaptcha(id)
if str != "" { if str != "" {
return return str
}
case str = <-manual:
return
} }
time.Sleep(time.Second)
} }
log.Warnf("验证超时") log.Warnf("验证超时")
return "" return ""