bobocup commited on
Commit
76e3d93
·
verified ·
1 Parent(s): 14e5d69

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +36 -35
index.js CHANGED
@@ -98,17 +98,29 @@ class CapsolverClient {
98
  }
99
 
100
  async createTask(websiteURL, websiteKey, extraParams = {}) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  const requestBody = JSON.stringify({
102
  clientKey: this.apiKey,
103
  task: {
104
- type: "AwsWafToken",
105
  websiteURL: websiteURL,
106
- websiteKey: websiteKey,
107
- metadata: {
108
- gokuProps: extraParams.gokuProps,
109
- captchaUrl: extraParams.captchaUrl,
110
- challengeUrl: extraParams.challengeUrl
111
- }
112
  }
113
  });
114
 
@@ -130,40 +142,29 @@ class CapsolverClient {
130
  throw new Error(`Capsolver API 请求失败: ${response.status}`);
131
  }
132
 
133
- return await response.json();
134
- } catch (error) {
135
- console.error('调用 Capsolver API 时出错:', error);
136
- throw error;
137
- }
138
- }
139
 
140
- async getTaskResult(taskId) {
141
- try {
142
- const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/getTaskResult`, {
143
- method: 'POST',
144
- headers: {
145
- 'Content-Type': 'application/json',
146
- 'Accept': 'application/json'
147
- },
148
- body: JSON.stringify({
149
- clientKey: this.apiKey,
150
- taskId: taskId
151
- })
152
- });
153
 
154
- if (!response.ok) {
155
- console.error('获取任务结果失败:', response.status);
156
- const errorText = await response.text();
157
- console.error('错误响应内容:', errorText);
158
- throw new Error(`获取任务结果失败: ${response.status}`);
159
  }
160
 
161
- const result = await response.json();
162
- console.log('获取任务结果响应:', result);
163
  return result;
164
-
165
  } catch (error) {
166
- console.error('获取任务结果时出错:', error);
167
  throw error;
168
  }
169
  }
 
98
  }
99
 
100
  async createTask(websiteURL, websiteKey, extraParams = {}) {
101
+ // 首先获取验证码图片
102
+ const captchaResponse = await fetch(extraParams.captchaUrl, {
103
+ headers: {
104
+ 'Referer': 'https://partyrock.aws/',
105
+ 'Origin': 'https://partyrock.aws',
106
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
107
+ }
108
+ });
109
+
110
+ if (!captchaResponse.ok) {
111
+ throw new Error('获取验证码失败');
112
+ }
113
+
114
+ const captchaData = await captchaResponse.json();
115
+ console.log('验证码数据:', captchaData);
116
+
117
  const requestBody = JSON.stringify({
118
  clientKey: this.apiKey,
119
  task: {
120
+ type: "AwsWafClassification",
121
  websiteURL: websiteURL,
122
+ images: captchaData.images || [],
123
+ question: captchaData.question || "aws:grid:bed" // 默认值,应该从验证码响应中获取
 
 
 
 
124
  }
125
  });
126
 
 
142
  throw new Error(`Capsolver API 请求失败: ${response.status}`);
143
  }
144
 
145
+ const result = await response.json();
146
+ console.log('Capsolver API 响应:', result);
 
 
 
 
147
 
148
+ // 如果成功识别,提交验证结果
149
+ if (result.status === 'ready') {
150
+ const verifyResponse = await fetch(extraParams.captchaUrl + '/verify', {
151
+ method: 'POST',
152
+ headers: {
153
+ 'Content-Type': 'application/json',
154
+ 'Referer': 'https://partyrock.aws/',
155
+ 'Origin': 'https://partyrock.aws'
156
+ },
157
+ body: JSON.stringify({
158
+ solution: result.solution
159
+ })
160
+ });
161
 
162
+ return await verifyResponse.json();
 
 
 
 
163
  }
164
 
 
 
165
  return result;
 
166
  } catch (error) {
167
+ console.error('调用 Capsolver API 时出错:', error);
168
  throw error;
169
  }
170
  }