package captchasolver import ( "io" "log" "net/http" "time" ) func Provider2CaptchaCreateCaptchaRequestV3(apiKey string, url string, googleKey string, googleAction string) string { client := &http.Client{} req, err := http.NewRequest("GET", "https://2captcha.com/in.php", nil) if err != nil { log.Print(err) return "" } q := req.URL.Query() q.Add("key", apiKey) q.Add("method", "userrecaptcha") q.Add("version", "3") q.Add("action", googleAction) q.Add("min_score", "0.3") q.Add("googlekey", googleKey) q.Add("pageurl", url) req.URL.RawQuery = q.Encode() res, err := client.Do(req) if err != nil { log.Print(err) return "" } respBody, _ := io.ReadAll(res.Body) respBodyStr := string(respBody) return respBodyStr[3:] } func Provider2CaptchaCreateCaptchaRequestV2(apiKey string, url string, googleKey string) string { client := &http.Client{} req, err := http.NewRequest("GET", "https://2captcha.com/in.php", nil) if err != nil { log.Print(err) return "" } q := req.URL.Query() q.Add("key", apiKey) q.Add("method", "userrecaptcha") q.Add("googlekey", googleKey) q.Add("pageurl", url) req.URL.RawQuery = q.Encode() res, err := client.Do(req) if err != nil { log.Print(err) return "" } respBody, _ := io.ReadAll(res.Body) respBodyStr := string(respBody) return respBodyStr[3:] } func Provider2CaptchaGetCaptchaResult(apiKey string, captchaID string) string { client := &http.Client{} req, err := http.NewRequest("GET", "http://2captcha.com/res.php", nil) if err != nil { log.Print(err) return "" } q := req.URL.Query() q.Add("key", apiKey) q.Add("action", "get") q.Add("id", captchaID) req.URL.RawQuery = q.Encode() res, err := client.Do(req) if err != nil { log.Print(err) return "" } respBody, _ := io.ReadAll(res.Body) respBodyStr := string(respBody) return respBodyStr } func Provider2CaptchaV2E2E(apiKey string, url string, dataSiteKey string) string { captchaReqID := Provider2CaptchaCreateCaptchaRequestV2(apiKey, url, dataSiteKey) log.Println(captchaReqID) captchaAnswer := "CAPCHA_NOT_READY" for captchaAnswer == "CAPCHA_NOT_READY" { time.Sleep(500 * time.Millisecond) captchaAnswer = Provider2CaptchaGetCaptchaResult(apiKey, captchaReqID) } log.Printf("Captcha ID: %s; Captcha Answer: %s\n", captchaReqID, captchaAnswer) captchaAnswer = captchaAnswer[3:] return captchaAnswer }