Skip to content

Commit 1debda9

Browse files
committed
improved code and added another example
1 parent 83ba51b commit 1debda9

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CaptchaGO
2-
Easily integrate and support many different captcha APIs in your Go project.
2+
Easily integrate and support many captcha services in your Go project.
33

44
[View usage examples](examples)
55

@@ -10,7 +10,7 @@ go get github.com/median/captchago
1010

1111
## Supported Services
1212
- [x] [2captcha (ruCaptcha)](https://2captcha.com)
13-
- [x] [AntiCaptcha](https://anti-captcha.com)
13+
- [x] [AntiCaptcha](http://getcaptchasolution.com/ielxn7dpk3)
1414
- [x] [CapMonster](https://capmonster.cloud)
1515
- [x] [AnyCaptcha](https://anycaptcha.com)
1616
- [x] [CapSolver](https://capsolver.com)
@@ -21,3 +21,4 @@ go get github.com/median/captchago
2121
- [x] Recaptcha V3
2222
- [x] HCaptcha
2323
- [x] FunCaptcha
24+
- [x] Get Balance

acmethods.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
1414
r = solver.ForcedDomain
1515
}
1616

17-
// detects if it's an ip or a domain
18-
if strings.Contains(r, ":") || strings.Count(r, ".") == 4 {
19-
r = "http://" + r
20-
} else {
21-
r = "https://" + r
17+
if !strings.Contains(r, "://") {
18+
// detects if it's an ip or a domain
19+
if strings.Contains(r, ":") || strings.Count(r, ".") == 4 {
20+
r = "http://" + r
21+
} else {
22+
r = "https://" + r
23+
}
2224
}
2325

2426
return r
@@ -33,13 +35,9 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
3335
}
3436

3537
if strings.Contains(d, "anti-captcha.com") {
36-
payload["softId"] = 1029
38+
payload["softId"] = 1080
3739
} else if strings.Contains(d, "capmonster.cloud") {
3840
payload["softId"] = 59
39-
} else if strings.Contains(d, "api.capsolver.com") {
40-
payload["softId"] = 1029 // TODO: get softId for capsolver
41-
} else if strings.Contains(d, "api.anycaptcha.com") {
42-
payload["softId"] = 1029 // TODO: get softId for anycaptcha
4341
}
4442

4543
body, err := postJSON(d+"/createTask", payload)

examples/custom_service.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/median/captchago"
6+
)
7+
8+
func main() {
9+
// when setting captchago.AntiCaptcha as service, it will use the same API format as anti-captcha.com
10+
// but after setting a forced domain it will just replace anti-captcha.com with the domain you set
11+
solver, err := captchago.New(captchago.AntiCaptcha, "YOUR_API_KEY")
12+
if err != nil {
13+
panic(err)
14+
}
15+
16+
solver.ForcedDomain = "http://custom-service.com"
17+
18+
sol, err := solver.HCaptcha(captchago.HCaptchaOptions{
19+
PageURL: "https://www.hcaptcha.com/demo",
20+
SiteKey: "10000000-ffff-ffff-ffff-000000000001",
21+
})
22+
23+
if err != nil {
24+
panic(err)
25+
}
26+
27+
fmt.Println(sol.Text)
28+
fmt.Println(fmt.Sprintf("Solved in %v ms", sol.Speed))
29+
}

solver.go

+16
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,29 @@ func (s *Solver) SetService(service SolveService) error {
5555
return nil
5656
}
5757

58+
func (s *Solver) IsValidService(service SolveService) bool {
59+
service = formatService(service)
60+
61+
switch service {
62+
case AntiCaptcha, AnyCaptcha, CapMonster, CapSolver, TwoCaptcha:
63+
return true
64+
}
65+
66+
return false
67+
}
68+
5869
func (s *Solver) GetService() SolveService {
5970
return s.service
6071
}
6172

6273
// formatService formats the service name to reduce the chance of human errors
6374
func formatService(s SolveService) SolveService {
75+
// remove spaces, dashes, and tlds
6476
s = strings.ReplaceAll(strings.ReplaceAll(strings.ToLower(s), " ", ""), "-", "")
77+
s = strings.Split(s, ".")[0]
78+
if strings.Contains(s, "://") {
79+
s = strings.Split(s, "://")[1]
80+
}
6581

6682
// rucaptcha uses same api as 2captcha, its just different name
6783
if s == "rucaptcha" {

0 commit comments

Comments
 (0)