gocaptcha

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 12 Imported by: 0

README

gocaptcha

An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

Installation

go get github.com/justhyped/gocaptcha

Support

Type 2Captcha AntiCaptcha
RecaptchaV2
RecaptchaV3
Image Captcha
HCaptcha
Turnstile

Software like XEVil and CapMonster are also supported. You can also implement your own provider by using the IProvider interface.

Usage

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AntiCaptcha

type AntiCaptcha struct {
	// contains filtered or unexported fields
}

func NewAntiCaptcha

func NewAntiCaptcha(apiKey string) *AntiCaptcha

func NewCapMonsterCloud added in v1.0.2

func NewCapMonsterCloud(apiKey string) *AntiCaptcha

func NewCustomAntiCaptcha

func NewCustomAntiCaptcha(baseUrl, apiKey string) *AntiCaptcha

NewCustomAntiCaptcha can be used to change the baseUrl, some providers such as CapMonster, XEVil and CapSolver have the exact same API as AntiCaptcha, thus allowing you to use these providers with ease.

func (*AntiCaptcha) SolveHCaptcha

func (a *AntiCaptcha) SolveHCaptcha(ctx context.Context, settings *Settings, payload *HCaptchaPayload) (ICaptchaResponse, error)

func (*AntiCaptcha) SolveImageCaptcha

func (a *AntiCaptcha) SolveImageCaptcha(ctx context.Context, settings *Settings, payload *ImageCaptchaPayload) (ICaptchaResponse, error)

func (*AntiCaptcha) SolveRecaptchaV2

func (a *AntiCaptcha) SolveRecaptchaV2(ctx context.Context, settings *Settings, payload *RecaptchaV2Payload) (ICaptchaResponse, error)

func (*AntiCaptcha) SolveRecaptchaV3

func (a *AntiCaptcha) SolveRecaptchaV3(ctx context.Context, settings *Settings, payload *RecaptchaV3Payload) (ICaptchaResponse, error)

func (*AntiCaptcha) SolveTurnstile

func (a *AntiCaptcha) SolveTurnstile(ctx context.Context, settings *Settings, payload *TurnstilePayload) (ICaptchaResponse, error)

type CaptchaResponse

type CaptchaResponse struct {
	// contains filtered or unexported fields
}

func (*CaptchaResponse) ReportBad

func (a *CaptchaResponse) ReportBad(ctx context.Context) error

func (*CaptchaResponse) ReportGood

func (a *CaptchaResponse) ReportGood(ctx context.Context) error

func (*CaptchaResponse) Solution

func (a *CaptchaResponse) Solution() string

type CaptchaSolver

type CaptchaSolver struct {
	// contains filtered or unexported fields
}

func NewCaptchaSolver

func NewCaptchaSolver(provider IProvider) *CaptchaSolver

func (*CaptchaSolver) SetClient

func (c *CaptchaSolver) SetClient(client *http.Client)

SetClient will set the client that is used when interacting with APIs of providers.

func (*CaptchaSolver) SetInitialWaitTime

func (c *CaptchaSolver) SetInitialWaitTime(waitTime time.Duration)

SetInitialWaitTime sets the time that is being waited after submitting a task to a provider before polling

func (*CaptchaSolver) SetMaxRetries

func (c *CaptchaSolver) SetMaxRetries(maxRetries int)

SetMaxRetries sets the maximum amount of polling

func (*CaptchaSolver) SetPollInterval

func (c *CaptchaSolver) SetPollInterval(interval time.Duration)

SetPollInterval sets the time that is being waited in between result polls

func (*CaptchaSolver) SolveHCaptcha

func (c *CaptchaSolver) SolveHCaptcha(ctx context.Context, payload *HCaptchaPayload) (ICaptchaResponse, error)

SolveHCaptcha uses the provider to fetch the solution of a captcha.

The function returns ICaptchaResponse that has .Solution(), .ReportBad() and .ReportGood() that can be used to get the answer or report the quality of the captcha to the provider.

func (*CaptchaSolver) SolveImageCaptcha

func (c *CaptchaSolver) SolveImageCaptcha(ctx context.Context, payload *ImageCaptchaPayload) (ICaptchaResponse, error)

SolveImageCaptcha uses the provider to fetch the solution of a captcha.

The function returns ICaptchaResponse that has .Solution(), .ReportBad() and .ReportGood() that can be used to get the answer or report the quality of the captcha to the provider.

func (*CaptchaSolver) SolveRecaptchaV2

func (c *CaptchaSolver) SolveRecaptchaV2(ctx context.Context, payload *RecaptchaV2Payload) (ICaptchaResponse, error)

SolveRecaptchaV2 uses the provider to fetch the solution of a captcha.

The function returns ICaptchaResponse that has .Solution(), .ReportBad() and .ReportGood() that can be used to get the answer or report the quality of the captcha to the provider.

func (*CaptchaSolver) SolveRecaptchaV3

func (c *CaptchaSolver) SolveRecaptchaV3(ctx context.Context, payload *RecaptchaV3Payload) (ICaptchaResponse, error)

SolveRecaptchaV3 uses the provider to fetch the solution of a captcha.

The function returns ICaptchaResponse that has .Solution(), .ReportBad() and .ReportGood() that can be used to get the answer or report the quality of the captcha to the provider.

func (*CaptchaSolver) SolveTurnstile

func (c *CaptchaSolver) SolveTurnstile(ctx context.Context, payload *TurnstilePayload) (ICaptchaResponse, error)

SolveTurnstile uses the provider to fetch the solution of a captcha.

The function returns ICaptchaResponse that has .Solution(), .ReportBad() and .ReportGood() that can be used to get the answer or report the quality of the captcha to the provider.

type HCaptchaPayload

type HCaptchaPayload struct {
	// EndpointUrl is the endpoint that has Recaptcha Protection
	EndpointUrl string

	// EndpointKey is the HCaptcha Key
	// Can be found on the Endpoint URL page
	EndpointKey string
}

type ICaptchaResponse

type ICaptchaResponse interface {
	// Solution will return the solution of the captcha as a string
	Solution() string

	// ReportBad reports the captcha to be invalid if the provider and captcha type support it.
	ReportBad(ctx context.Context) error

	// ReportGood reports the captcha to be valid if the provider and captcha type support it.
	ReportGood(ctx context.Context) error
}

type IProvider

type IProvider interface {
	// SolveImageCaptcha is the implementation of getting the response of an image captcha
	SolveImageCaptcha(ctx context.Context, settings *Settings, payload *ImageCaptchaPayload) (ICaptchaResponse, error)

	// SolveRecaptchaV2 is the implementation of getting the response of a version 2 recaptcha
	SolveRecaptchaV2(ctx context.Context, settings *Settings, payload *RecaptchaV2Payload) (ICaptchaResponse, error)

	// SolveRecaptchaV3 is the implementation of getting the response of a version 3 recaptcha
	SolveRecaptchaV3(ctx context.Context, settings *Settings, payload *RecaptchaV3Payload) (ICaptchaResponse, error)

	// SolveHCaptcha is the implementation of getting the response of an HCaptcha captcha
	SolveHCaptcha(ctx context.Context, settings *Settings, payload *HCaptchaPayload) (ICaptchaResponse, error)

	// SolveTurnstile is the implementation of getting a turnstile token
	SolveTurnstile(ctx context.Context, settings *Settings, payload *TurnstilePayload) (ICaptchaResponse, error)
}

type ImageCaptchaPayload

type ImageCaptchaPayload struct {
	// Base64String is the base64 representation of the image
	Base64String string

	// CaseSensitive should be set to true if captcha is case-sensitive
	CaseSensitive bool

	// InstructionsForSolver should be set if the human solver needs additional information
	// about how to solve the captcha
	InstructionsForSolver string
}

type RecaptchaV2Payload

type RecaptchaV2Payload struct {
	// EndpointUrl is the endpoint that has Recaptcha Protection
	EndpointUrl string

	// EndpointKey is the Recaptcha Key
	// Can be found on the Endpoint URL page
	EndpointKey string

	// IsInvisibleCaptcha Enable if endpoint has invisible Recaptcha V2
	IsInvisibleCaptcha bool
}

type RecaptchaV3Payload

type RecaptchaV3Payload struct {
	// EndpointUrl is the endpoint that has Recaptcha Protection
	EndpointUrl string

	// EndpointKey is the Recaptcha Key
	// Can be found on the Endpoint URL page
	EndpointKey string

	// Action is the action name of the recaptcha, you can find it in source code of site
	Action string

	// IsEnterprise should be set if V3 Enterprise is used
	IsEnterprise bool

	// MinScore defaults to 0.3, accepted values are 0.3, 0.6, 0.9
	MinScore float32
}

type Settings

type Settings struct {
	// contains filtered or unexported fields
}

func NewSettings

func NewSettings() *Settings

type TurnstilePayload

type TurnstilePayload struct {
	// EndpointUrl is the endpoint that has FunCaptcha Protection
	EndpointUrl string

	// EndpointKey is the Recaptcha Key
	// Can be found on the Endpoint URL page
	EndpointKey string
}

type TwoCaptcha

type TwoCaptcha struct {
	// contains filtered or unexported fields
}

func NewCustomTwoCaptcha

func NewCustomTwoCaptcha(baseUrl, apiKey string) *TwoCaptcha

NewCustomTwoCaptcha can be used to change the baseUrl, some providers such as CapMonster, XEVil and CapSolver have the exact same API as AntiCaptcha, thus allowing you to use these providers with ease.

func NewTwoCaptcha

func NewTwoCaptcha(apiKey string) *TwoCaptcha

func (*TwoCaptcha) SolveHCaptcha

func (t *TwoCaptcha) SolveHCaptcha(ctx context.Context, settings *Settings, payload *HCaptchaPayload) (ICaptchaResponse, error)

func (*TwoCaptcha) SolveImageCaptcha

func (t *TwoCaptcha) SolveImageCaptcha(ctx context.Context, settings *Settings, payload *ImageCaptchaPayload) (ICaptchaResponse, error)

func (*TwoCaptcha) SolveRecaptchaV2

func (t *TwoCaptcha) SolveRecaptchaV2(ctx context.Context, settings *Settings, payload *RecaptchaV2Payload) (ICaptchaResponse, error)

func (*TwoCaptcha) SolveRecaptchaV3

func (t *TwoCaptcha) SolveRecaptchaV3(ctx context.Context, settings *Settings, payload *RecaptchaV3Payload) (ICaptchaResponse, error)

func (*TwoCaptcha) SolveTurnstile

func (t *TwoCaptcha) SolveTurnstile(ctx context.Context, settings *Settings, payload *TurnstilePayload) (ICaptchaResponse, error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL