Update index.js
Browse files
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: "
|
| 105 |
websiteURL: websiteURL,
|
| 106 |
-
|
| 107 |
-
|
| 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 |
-
|
| 134 |
-
|
| 135 |
-
console.error('调用 Capsolver API 时出错:', error);
|
| 136 |
-
throw error;
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
|
| 154 |
-
|
| 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('
|
| 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 |
}
|