From 1debda964be45aaa5c7eacafdab7382100d378b3 Mon Sep 17 00:00:00 2001 From: GenixZero <70934040+median@users.noreply.github.com> Date: Mon, 6 Feb 2023 09:24:47 +1100 Subject: [PATCH] improved code and added another example --- README.md | 5 +++-- acmethods.go | 18 ++++++++---------- examples/custom_service.go | 29 +++++++++++++++++++++++++++++ solver.go | 16 ++++++++++++++++ 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 examples/custom_service.go diff --git a/README.md b/README.md index fd68373..f0c0b8a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # CaptchaGO -Easily integrate and support many different captcha APIs in your Go project. +Easily integrate and support many captcha services in your Go project. [View usage examples](examples) @@ -10,7 +10,7 @@ go get github.com/median/captchago ## Supported Services - [x] [2captcha (ruCaptcha)](https://2captcha.com) -- [x] [AntiCaptcha](https://anti-captcha.com) +- [x] [AntiCaptcha](http://getcaptchasolution.com/ielxn7dpk3) - [x] [CapMonster](https://capmonster.cloud) - [x] [AnyCaptcha](https://anycaptcha.com) - [x] [CapSolver](https://capsolver.com) @@ -21,3 +21,4 @@ go get github.com/median/captchago - [x] Recaptcha V3 - [x] HCaptcha - [x] FunCaptcha +- [x] Get Balance diff --git a/acmethods.go b/acmethods.go index 0b72f5b..f9080c9 100644 --- a/acmethods.go +++ b/acmethods.go @@ -14,11 +14,13 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods { r = solver.ForcedDomain } - // detects if it's an ip or a domain - if strings.Contains(r, ":") || strings.Count(r, ".") == 4 { - r = "http://" + r - } else { - r = "https://" + r + if !strings.Contains(r, "://") { + // detects if it's an ip or a domain + if strings.Contains(r, ":") || strings.Count(r, ".") == 4 { + r = "http://" + r + } else { + r = "https://" + r + } } return r @@ -33,13 +35,9 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods { } if strings.Contains(d, "anti-captcha.com") { - payload["softId"] = 1029 + payload["softId"] = 1080 } else if strings.Contains(d, "capmonster.cloud") { payload["softId"] = 59 - } else if strings.Contains(d, "api.capsolver.com") { - payload["softId"] = 1029 // TODO: get softId for capsolver - } else if strings.Contains(d, "api.anycaptcha.com") { - payload["softId"] = 1029 // TODO: get softId for anycaptcha } body, err := postJSON(d+"/createTask", payload) diff --git a/examples/custom_service.go b/examples/custom_service.go new file mode 100644 index 0000000..a669b82 --- /dev/null +++ b/examples/custom_service.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/median/captchago" +) + +func main() { + // when setting captchago.AntiCaptcha as service, it will use the same API format as anti-captcha.com + // but after setting a forced domain it will just replace anti-captcha.com with the domain you set + solver, err := captchago.New(captchago.AntiCaptcha, "YOUR_API_KEY") + if err != nil { + panic(err) + } + + solver.ForcedDomain = "http://custom-service.com" + + sol, err := solver.HCaptcha(captchago.HCaptchaOptions{ + PageURL: "https://www.hcaptcha.com/demo", + SiteKey: "10000000-ffff-ffff-ffff-000000000001", + }) + + if err != nil { + panic(err) + } + + fmt.Println(sol.Text) + fmt.Println(fmt.Sprintf("Solved in %v ms", sol.Speed)) +} diff --git a/solver.go b/solver.go index ca73d71..aaddd82 100644 --- a/solver.go +++ b/solver.go @@ -55,13 +55,29 @@ func (s *Solver) SetService(service SolveService) error { return nil } +func (s *Solver) IsValidService(service SolveService) bool { + service = formatService(service) + + switch service { + case AntiCaptcha, AnyCaptcha, CapMonster, CapSolver, TwoCaptcha: + return true + } + + return false +} + func (s *Solver) GetService() SolveService { return s.service } // formatService formats the service name to reduce the chance of human errors func formatService(s SolveService) SolveService { + // remove spaces, dashes, and tlds s = strings.ReplaceAll(strings.ReplaceAll(strings.ToLower(s), " ", ""), "-", "") + s = strings.Split(s, ".")[0] + if strings.Contains(s, "://") { + s = strings.Split(s, "://")[1] + } // rucaptcha uses same api as 2captcha, its just different name if s == "rucaptcha" {