bobocup commited on
Commit
e78424d
·
verified ·
1 Parent(s): fbc33ab

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +73 -31
index.js CHANGED
@@ -98,43 +98,85 @@ class CapsolverClient {
98
  }
99
 
100
  async createTask(websiteURL, websiteKey, extraParams = {}) {
101
- const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/createTask`, {
102
- method: 'POST',
103
- headers: {
104
- 'Content-Type': 'application/json'
105
- },
106
- body: JSON.stringify({
107
- clientKey: this.apiKey,
108
- task: {
109
- type: "AwsWafCaptcha",
110
- websiteURL: websiteURL,
111
- websiteKey: websiteKey,
112
- gokuProps: extraParams.gokuProps,
113
- captchaUrl: extraParams.captchaUrl,
114
- challengeUrl: extraParams.challengeUrl,
115
- proxy: {
116
- // 如果需要代理可以在这里配置
117
- }
118
- }
119
- })
120
  });
121
 
122
- return await response.json();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  }
124
 
125
  async getTaskResult(taskId) {
126
- const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/getTaskResult`, {
127
- method: 'POST',
128
- headers: {
129
- 'Content-Type': 'application/json'
130
- },
131
- body: JSON.stringify({
132
- clientKey: this.apiKey,
133
- taskId: taskId
134
- })
135
- });
 
 
 
 
 
 
 
 
 
136
 
137
- return await response.json();
 
 
 
 
 
 
 
138
  }
139
  }
140
 
 
98
  }
99
 
100
  async createTask(websiteURL, websiteKey, extraParams = {}) {
101
+ console.log('发送到Capsolver的数据:', {
102
+ clientKey: this.apiKey,
103
+ task: {
104
+ type: "AwsWafCaptcha",
105
+ websiteURL: websiteURL,
106
+ websiteKey: websiteKey,
107
+ gokuProps: extraParams.gokuProps,
108
+ captchaUrl: extraParams.captchaUrl,
109
+ challengeUrl: extraParams.challengeUrl
110
+ }
 
 
 
 
 
 
 
 
 
111
  });
112
 
113
+ try {
114
+ const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/createTask`, {
115
+ method: 'POST',
116
+ headers: {
117
+ 'Content-Type': 'application/json',
118
+ 'Accept': 'application/json'
119
+ },
120
+ body: JSON.stringify({
121
+ clientKey: this.apiKey,
122
+ appId: "E9C7B482-6D47-4BF7-ABFA-E88D49F57929",
123
+ task: {
124
+ type: "AwsWafCaptcha",
125
+ websiteURL: websiteURL,
126
+ websiteKey: websiteKey,
127
+ gokuProps: JSON.stringify(extraParams.gokuProps), // 确保 gokuProps 被序列化
128
+ captchaUrl: extraParams.captchaUrl,
129
+ challengeUrl: extraParams.challengeUrl
130
+ }
131
+ })
132
+ });
133
+
134
+ if (!response.ok) {
135
+ console.error('Capsolver API 响应不成功:', response.status);
136
+ const errorText = await response.text();
137
+ console.error('错误响应内容:', errorText);
138
+ throw new Error(`Capsolver API 请求失败: ${response.status}`);
139
+ }
140
+
141
+ const result = await response.json();
142
+ console.log('Capsolver API 响应:', result);
143
+ return result;
144
+
145
+ } catch (error) {
146
+ console.error('调用 Capsolver API 时出错:', error);
147
+ throw error;
148
+ }
149
  }
150
 
151
  async getTaskResult(taskId) {
152
+ try {
153
+ const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/getTaskResult`, {
154
+ method: 'POST',
155
+ headers: {
156
+ 'Content-Type': 'application/json',
157
+ 'Accept': 'application/json'
158
+ },
159
+ body: JSON.stringify({
160
+ clientKey: this.apiKey,
161
+ taskId: taskId
162
+ })
163
+ });
164
+
165
+ if (!response.ok) {
166
+ console.error('获取任务结果失败:', response.status);
167
+ const errorText = await response.text();
168
+ console.error('错误响应内容:', errorText);
169
+ throw new Error(`获取任务结果失败: ${response.status}`);
170
+ }
171
 
172
+ const result = await response.json();
173
+ console.log('获取任务结果响应:', result);
174
+ return result;
175
+
176
+ } catch (error) {
177
+ console.error('获取任务结果时出错:', error);
178
+ throw error;
179
+ }
180
  }
181
  }
182