Skip to content

Commit b4d9aad

Browse files
committed
added kasada support for capsolver.com
1 parent 1debda9 commit b4d9aad

File tree

3 files changed

+111
-10
lines changed

3 files changed

+111
-10
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ go get github.com/median/captchago
99
```
1010

1111
## Supported Services
12-
- [x] [2captcha (ruCaptcha)](https://2captcha.com)
1312
- [x] [AntiCaptcha](http://getcaptchasolution.com/ielxn7dpk3)
13+
- [x] [CapSolver](https://dashboard.capsolver.com/passport/register?inviteCode=G0LMAKBIuoJp)
1414
- [x] [CapMonster](https://capmonster.cloud)
15+
- [x] [2captcha (ruCaptcha)](https://2captcha.com)
1516
- [x] [AnyCaptcha](https://anycaptcha.com)
16-
- [x] [CapSolver](https://capsolver.com)
1717
- [x] Any other services that use the same API format as one above
1818

1919
## Methods
2020
- [x] Recaptcha V2
2121
- [x] Recaptcha V3
2222
- [x] HCaptcha
2323
- [x] FunCaptcha
24+
- [x] Kasada Anti-Bot ([CapSolver](https://dashboard.capsolver.com/passport/register?inviteCode=G0LMAKBIuoJp) only)
2425
- [x] Get Balance

acmethods.go

+66-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
3838
payload["softId"] = 1080
3939
} else if strings.Contains(d, "capmonster.cloud") {
4040
payload["softId"] = 59
41+
} else if strings.Contains(d, "capsolver.com") {
42+
payload["appId"] = "B7E57F27-0AD3-434D-A5B7-CF9EE7D093EF"
4143
}
4244

4345
body, err := postJSON(d+"/createTask", payload)
@@ -93,16 +95,20 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
9395
case "processing":
9496
continue
9597
case "ready":
96-
solution, hasSolution := body["solution"]
98+
solution, hasSolution := body["solution"].(map[string]interface{})
9799
if !hasSolution {
98100
return nil, errors.New("no solution")
99101
}
100102

101103
// response can either be gRecaptchaResponse or token
102-
response := solution.(map[string]interface{})["gRecaptchaResponse"]
104+
response := solution["gRecaptchaResponse"]
103105

104106
if response == nil {
105-
response = solution.(map[string]interface{})["token"]
107+
response = solution["token"]
108+
}
109+
110+
if response == nil {
111+
response = solution["x-kpsdk-ct"]
106112
}
107113

108114
if response == nil {
@@ -127,10 +133,11 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
127133
}
128134

129135
return &Solution{
130-
TaskId: taskId,
131-
Text: response.(string),
132-
IP: ip,
133-
Cost: cost,
136+
TaskId: taskId,
137+
Text: response.(string),
138+
RawSolution: solution,
139+
IP: ip,
140+
Cost: cost,
134141
}, nil
135142
default:
136143
return nil, errors.New("unknown status")
@@ -183,7 +190,7 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
183190
data["proxyType"] = t
184191
}
185192

186-
return &solveMethods{
193+
methods := &solveMethods{
187194
GetBalance: func() (float64, error) {
188195
d := domain()
189196

@@ -317,4 +324,55 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
317324
return createResponse(taskData)
318325
},
319326
}
327+
328+
// kasada method
329+
if solver.service == CapSolver {
330+
methods.Kasada = func(o KasadaOptions) (*KasadaSolution, error) {
331+
taskData := map[string]interface{}{
332+
"type": "AntiKasadaTask",
333+
"pageURL": o.PageURL,
334+
"cd": o.DetailedCD,
335+
"onlyCD": o.OnlyCD,
336+
"version": o.Version,
337+
"userAgent": o.UserAgent,
338+
}
339+
340+
if o.Proxy != nil {
341+
taskData["proxy"] = o.Proxy.String()
342+
}
343+
344+
sol, err := createResponse(taskData)
345+
if err != nil {
346+
return nil, err
347+
}
348+
349+
kpsdkCD := ""
350+
kpsdkCT := ""
351+
userAgent := ""
352+
353+
raw := sol.RawSolution["x-kpsdk-cd"]
354+
if raw != nil {
355+
kpsdkCD = raw.(string)
356+
}
357+
358+
raw = sol.RawSolution["x-kpsdk-ct"]
359+
if raw != nil {
360+
kpsdkCT = raw.(string)
361+
}
362+
363+
raw = sol.RawSolution["user-agent"]
364+
if raw != nil {
365+
userAgent = raw.(string)
366+
}
367+
368+
return &KasadaSolution{
369+
Solution: sol,
370+
KpsdkCD: kpsdkCD,
371+
KpsdkCT: kpsdkCT,
372+
UserAgent: userAgent,
373+
}, nil
374+
}
375+
}
376+
377+
return methods
320378
}

captchas.go

+42
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type solveMethods struct {
1010
RecaptchaV3 func(RecaptchaV3Options) (*Solution, error)
1111
HCaptcha func(HCaptchaOptions) (*Solution, error)
1212
FunCaptcha func(FunCaptchaOptions) (*Solution, error)
13+
Kasada func(KasadaOptions) (*KasadaSolution, error)
1314
}
1415

1516
// GetBalance returns the balance of the account
@@ -49,6 +50,14 @@ func (s *Solver) FunCaptcha(o FunCaptchaOptions) (*Solution, error) {
4950
return s.methods.FunCaptcha(o)
5051
}
5152

53+
// Kasada is only supported with capsolver.com
54+
func (s *Solver) Kasada(o KasadaOptions) (*KasadaSolution, error) {
55+
if s.methods.Kasada == nil {
56+
return nil, errors.New("service does not support kasada")
57+
}
58+
return s.methods.Kasada(o)
59+
}
60+
5261
// RecaptchaV3Options All fields are required
5362
type RecaptchaV3Options struct {
5463
PageURL string
@@ -79,6 +88,23 @@ type FunCaptchaOptions struct {
7988
Data string
8089
}
8190

91+
type KasadaOptions struct {
92+
PageURL string
93+
Proxy *Proxy
94+
95+
// DetailedCD Enable if you need more detailed x-kpsdk-cd, including params such as duration, st and rst
96+
DetailedCD bool
97+
98+
// OnlyCD Enable if the solution contains only x-kpsdk-cd
99+
OnlyCD bool
100+
101+
// Version Currently supports 2.0 and 3.0, default is 3.0
102+
Version string
103+
104+
// UserAgent Browser's User-Agent which is used in emulation. Default is random
105+
UserAgent string
106+
}
107+
82108
type HCaptchaOptions struct {
83109
PageURL string
84110
SiteKey string
@@ -122,6 +148,9 @@ type Solution struct {
122148
Text string
123149
TaskId int
124150

151+
// RawSolution not supported on 2captcha methods
152+
RawSolution map[string]interface{}
153+
125154
// Speed the time in milliseconds that the captcha took to solve
126155
Speed int64
127156

@@ -134,3 +163,16 @@ type Solution struct {
134163
// IP can be "" if the service does not return IP
135164
IP string
136165
}
166+
167+
type KasadaSolution struct {
168+
*Solution
169+
170+
// KpsdkCT is the 'x-kpsdk-ct' header
171+
KpsdkCT string
172+
173+
// KpsdkCD is the 'x-kpsdk-cd' header
174+
KpsdkCD string
175+
176+
// UserAgent is the user agent used to solve the captcha
177+
UserAgent string
178+
}

0 commit comments

Comments
 (0)