-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.go
306 lines (281 loc) · 10.1 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package anticaptcha
import (
"encoding/base64"
"io/ioutil"
"net/http"
)
type Task_ImageToText struct {
Type string `json:"type"`
Body string `json:"body"`
Phrase bool `json:"phrase,omitempty"`
Case bool `json:"case,omitempty"`
Numeric bool `json:"numeric,omitempty"`
Math int `json:"math,omitempty"`
MinLength int `json:"minLength,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
}
type Task_NoCaptcha struct {
Type string `json:"type"` //Yes NoCaptchaTask
WebsiteURL string `json:"websiteURL"` //Yes Address of target web page
WebsiteKey string `json:"websiteKey"` //Yes Recaptcha website key
WebsiteSToken string `json:"websiteSToken,omitempty"` //No
ProxyType string `json:"proxyType"` //Yes
ProxyAddress string `json:"proxyAddress"` //Yes
ProxyPort int `json:"proxyPort"` //Yes
ProxyLogin string `json:"proxyLogin,omitempty"` //No
ProxyPassword string `json:"proxyPassword,omitempty"` //No
UserAgent string `json:"userAgent"` //Yes
Cookies string `json:"cookies,omitempty"` //No
IsInvisible bool `json:"isInvisible,omitempty"` //Specify if Recaptcha is invisible.
}
type Task_NoCaptchaProxyless struct {
Type string `json:"type"` //Yes NoCaptchaTask
WebsiteURL string `json:"websiteURL"` //Yes Address of target web page
WebsiteKey string `json:"websiteKey"` //Yes Recaptcha website key
WebsiteSToken string `json:"websiteSToken,omitempty"` //No
IsInvisible bool `json:"isInvisible,omitempty"` //Specify if Recaptcha is invisible.
}
type Task_FunCaptcha struct {
Type string `json:"type"`
WebsiteURL string `json:"websiteURL"`
FuncaptchaAPIJSSubdomain string `json:"funcaptchaApiJSSubdomain"`
WebsitePublicKey string `json:"websitePublicKey"`
ProxyType string `json:"proxyType"` //Yes
ProxyAddress string `json:"proxyAddress"` //Yes
ProxyPort int `json:"proxyPort"` //Yes
ProxyLogin string `json:"proxyLogin,omitempty"` //No
ProxyPassword string `json:"proxyPassword,omitempty"` //No
UserAgent string `json:"userAgent"` //Yes
Cookies string `json:"cookies,omitempty"` //No
}
type Task_FunCaptchaTaskProxyless struct {
Type string `json:"type"`
WebsiteURL string `json:"websiteURL"`
FuncaptchaAPIJSSubdomain string `json:"funcaptchaApiJSSubdomain,omitempty"`
WebsitePublicKey string `json:"websitePublicKey"`
}
type Task_GeeTest struct {
Type string `json:"type"`
WebsiteURL string `json:"websiteURL"`
Gt string `json:"gt"`
Challenge string `json:"challenge"`
GeetestApiServerSubdomain string `json:"geetestApiServerSubdomain,omitempty"`
ProxyType string `json:"proxyType"`
ProxyAddress string `json:"proxyAddress"`
ProxyPort int `json:"proxyPort"`
ProxyLogin string `json:"proxyLogin,omitempty"`
ProxyPassword string `json:"proxyPassword,omitempty"`
UserAgent string `json:"userAgent"`
Cookies string `json:"cookies,omitempty"`
}
type Task_GeeTestProxyless struct {
Type string `json:"type"`
WebsiteURL string `json:"websiteURL"`
Gt string `json:"gt"`
Challenge string `json:"challenge"`
GeetestApiServerSubdomain string `json:"geetestApiServerSubdomain,omitempty"`
}
type Task_CustomCaptcha struct {
Type string `json:"type"`
ImageURL string `json:"imageUrl"`
Assignment string `json:"assignment"`
Forms []struct {
Label string `json:"label"`
LabelHint string `json:"labelHint"`
ContentType string `json:"contentType,omitempty"`
Content interface{} `json:"contentType,omitempty"`
Name string `json:"name"`
InputType string `json:"inputType"`
InputOptions struct {
Width string `json:"width"`
Rows string `json:"rows,omitempty"`
PlaceHolder string `json:"placeHolder"`
} `json:"inputOptions"`
} `json:"forms"`
}
type Task_SquareNetText struct {
Type string `json:"type"`
Body string `json:"body"`
ObjectName string `json:"objectName"`
RowsCount int `json:"rowsCount"`
ColumnsCount int `json:"columnsCount"`
}
// NewTask_ImageFromFile
func NewTask_ImageFromFile(file string) (task Task_ImageToText, err error) {
task = Task_ImageToText{}
b, err := ioutil.ReadFile(file)
if err != nil {
return task, err
}
encoded := base64.StdEncoding.EncodeToString(b)
task.Type = Type_ImageToText
task.Body = encoded
return task, err
}
// NewTask_ImageFromURL
func NewTask_ImageFromURL(url string) (task Task_ImageToText, err error) {
task = Task_ImageToText{}
resp, err := http.Get(url)
if err != nil {
return task, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return task, err
}
encoded := base64.StdEncoding.EncodeToString(b)
task.Type = Type_ImageToText
task.Body = encoded
return task, err
}
// NewTask_ImageFromBytes
func NewTaskImageFromBytes(b []byte) Task_ImageToText {
encoded := base64.StdEncoding.EncodeToString(b)
return Task_ImageToText{
Type: Type_ImageToText,
Body: encoded,
}
}
// NewTask_NoCaptcha
func NewTask_NoCaptcha(websiteURL, websiteKey, proxyType, proxyAddress string, proxyPort int, userAgent string) Task_NoCaptcha {
return Task_NoCaptcha{
Type: Type_NoCaptcha,
WebsiteURL: websiteURL,
WebsiteKey: websiteKey,
ProxyType: proxyType,
ProxyAddress: proxyAddress,
ProxyPort: proxyPort,
UserAgent: userAgent,
}
}
// NewNoCaptchaProxyless
func NewTask_NoCaptchaProxyless(websiteURL, websiteKey string) Task_NoCaptchaProxyless {
return Task_NoCaptchaProxyless{
Type: Type_NoCaptchaProxyless,
WebsiteURL: websiteURL,
WebsiteKey: websiteKey,
}
}
// NewTask_FunCaptcha
func NewTask_FunCaptcha(websiteURL, WebsitePublicKey, proxyType, proxyAddress string, proxyPort int, userAgent string) Task_FunCaptcha {
return Task_FunCaptcha{
Type: Type_FunCaptcha,
WebsiteURL: websiteURL,
WebsitePublicKey: WebsitePublicKey,
ProxyType: proxyType,
ProxyAddress: proxyAddress,
ProxyPort: proxyPort,
UserAgent: userAgent,
}
}
// NewTask_FunCaptchaProxyless
func NewTask_FunCaptchaProxyless(websiteURL, WebsitePublicKey string) Task_FunCaptchaTaskProxyless {
return Task_FunCaptchaTaskProxyless{
Type: Type_FunCaptchaProxyless,
WebsiteURL: websiteURL,
WebsitePublicKey: WebsitePublicKey,
}
}
// NewTask_SquareNetTextFromFile
func NewTask_SquareNetTextFromFile(file, objectName string, rowsCount, columnsCount int) (task Task_SquareNetText, err error) {
task = Task_SquareNetText{}
b, err := ioutil.ReadFile(file)
if err != nil {
return task, err
}
encoded := base64.StdEncoding.EncodeToString(b)
task.Type = Type_SquareNetText
task.Body = encoded
task.ObjectName = objectName
task.RowsCount = rowsCount
task.ColumnsCount = columnsCount
return task, err
}
// NewTask_SquareNetTextFromURL
func NewTask_SquareNetTextFromURL(url, objectName string, rowsCount, columnsCount int) (task Task_SquareNetText, err error) {
task = Task_SquareNetText{}
resp, err := http.Get(url)
if err != nil {
return task, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return task, err
}
encoded := base64.StdEncoding.EncodeToString(b)
task.Type = Type_SquareNetText
task.Body = encoded
task.ObjectName = objectName
task.RowsCount = rowsCount
task.ColumnsCount = columnsCount
return task, err
}
// NewTask_SquareNetTextFromBytes
func NewTask_SquareNetTextFromBytes(b []byte, objectName string, rowsCount, columnsCount int) Task_SquareNetText {
encoded := base64.StdEncoding.EncodeToString(b)
return Task_SquareNetText{
Type: Type_SquareNetText,
Body: encoded,
ObjectName: objectName,
RowsCount: rowsCount,
ColumnsCount: columnsCount,
}
}
// NewTask_GeeTest
func NewTaskGeeTest(websiteURL, gt, challenge, proxyType, proxyAddress string, proxyPort int, userAgent string) Task_GeeTest {
return Task_GeeTest{
Type: Type_GeeTest,
WebsiteURL: websiteURL,
Gt: gt,
Challenge: challenge,
ProxyType: proxyType,
ProxyAddress: proxyAddress,
ProxyPort: proxyPort,
UserAgent: userAgent,
}
}
// NewTask_GeeTestProxyless
func NewTaskGeeTestProxyless(websiteURL, gt, challenge string) Task_GeeTestProxyless {
return Task_GeeTestProxyless{
Type: Type_GeeTestProxyless,
WebsiteURL: websiteURL,
Gt: gt,
Challenge: challenge,
}
}
// NewTask_CustomCaptcha
func NewTask_CustomCaptcha(imageUrl string) Task_CustomCaptcha {
return Task_CustomCaptcha{
Type: Type_CustomCaptcha,
ImageURL: imageUrl,
}
}
// CreateTask
// This method creates a task for solving selected captcha type.
func (c *Client) CreateTask(task interface{}) (*Response_CreateTask, *Error) {
req := &Reqest{}
req.Task = task
res := &Response_CreateTask{}
err := c.request(c.URL+EP_createTask, req, res)
return res, err
}
// GetTaskResult
// request task result
func (c *Client) GetTaskResult(taskId int) (*Response_GetTaskResult, *Error) {
req := &Reqest{}
req.TaskID = taskId
res := &Response_GetTaskResult{}
err := c.request(c.URL+EP_getTaskResult, req, res)
return res, err
}
// ReportIncorrectImageCaptcha
//Complaints are accepted only for image captchas. Your complaint will be checked by 5 workers, 3 of them must confirm it. Only then you get full refund. If you have less than 20% confirmation ratio, your reports will be ignored.
func (c *Client) ReportIncorrectImageCaptcha(taskId int) (*ResponseReportIncorrectImageCaptcha, *Error) {
req := &Reqest{}
req.TaskID = taskId
res := &ResponseReportIncorrectImageCaptcha{}
err := c.request(c.URL+EP_reportIncorrectImageCaptcha, req, res)
return res, err
}