Update index.js
Browse files
index.js
CHANGED
|
@@ -98,15 +98,12 @@ class CapsolverClient {
|
|
| 98 |
}
|
| 99 |
|
| 100 |
async createTask(websiteURL, websiteKey, extraParams = {}) {
|
| 101 |
-
|
| 102 |
clientKey: this.apiKey,
|
| 103 |
task: {
|
| 104 |
type: "AwsWafToken",
|
| 105 |
websiteURL: websiteURL,
|
| 106 |
websiteKey: websiteKey,
|
| 107 |
-
proxy: {
|
| 108 |
-
// 如果需要代理可以在这里配置
|
| 109 |
-
},
|
| 110 |
metadata: {
|
| 111 |
gokuProps: extraParams.gokuProps,
|
| 112 |
captchaUrl: extraParams.captchaUrl,
|
|
@@ -115,26 +112,15 @@ class CapsolverClient {
|
|
| 115 |
}
|
| 116 |
});
|
| 117 |
|
|
|
|
|
|
|
| 118 |
try {
|
| 119 |
const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/createTask`, {
|
| 120 |
method: 'POST',
|
| 121 |
headers: {
|
| 122 |
-
'Content-Type': 'application/json'
|
| 123 |
-
'Accept': 'application/json'
|
| 124 |
},
|
| 125 |
-
body:
|
| 126 |
-
clientKey: this.apiKey,
|
| 127 |
-
task: {
|
| 128 |
-
type: "AwsWafToken",
|
| 129 |
-
websiteURL: websiteURL,
|
| 130 |
-
websiteKey: websiteKey,
|
| 131 |
-
metadata: {
|
| 132 |
-
gokuProps: extraParams.gokuProps,
|
| 133 |
-
captchaUrl: extraParams.captchaUrl,
|
| 134 |
-
challengeUrl: extraParams.challengeUrl
|
| 135 |
-
}
|
| 136 |
-
}
|
| 137 |
-
})
|
| 138 |
});
|
| 139 |
|
| 140 |
if (!response.ok) {
|
|
@@ -144,57 +130,7 @@ class CapsolverClient {
|
|
| 144 |
throw new Error(`Capsolver API 请求失败: ${response.status}`);
|
| 145 |
}
|
| 146 |
|
| 147 |
-
|
| 148 |
-
console.log('Capsolver API 响应:', result);
|
| 149 |
-
|
| 150 |
-
if (result.status === 'ready' && result.solution) {
|
| 151 |
-
// 提交验证结果
|
| 152 |
-
const verifyResponse = await fetch(extraParams.captchaUrl + '/verify', {
|
| 153 |
-
method: 'POST',
|
| 154 |
-
headers: {
|
| 155 |
-
'Content-Type': 'application/json',
|
| 156 |
-
'Referer': 'https://partyrock.aws/',
|
| 157 |
-
'Origin': 'https://partyrock.aws'
|
| 158 |
-
},
|
| 159 |
-
body: JSON.stringify({
|
| 160 |
-
state: result.solution.state,
|
| 161 |
-
key: result.solution.key,
|
| 162 |
-
hmac_tag: result.solution.hmac_tag,
|
| 163 |
-
client_solution: result.solution.client_solution,
|
| 164 |
-
metrics: {
|
| 165 |
-
solve_time_millis: result.solution.solve_time || 18000
|
| 166 |
-
},
|
| 167 |
-
api_key: result.solution.api_key,
|
| 168 |
-
locale: "zh-cn"
|
| 169 |
-
})
|
| 170 |
-
});
|
| 171 |
-
|
| 172 |
-
if (!verifyResponse.ok) {
|
| 173 |
-
throw new Error('验证提交失败');
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
const verifyResult = await verifyResponse.json();
|
| 177 |
-
|
| 178 |
-
// 获取 voucher
|
| 179 |
-
if (verifyResult.captcha_voucher) {
|
| 180 |
-
const voucherResponse = await fetch(extraParams.challengeUrl + '/voucher', {
|
| 181 |
-
method: 'POST',
|
| 182 |
-
headers: {
|
| 183 |
-
'Content-Type': 'application/json',
|
| 184 |
-
'Referer': 'https://partyrock.aws/',
|
| 185 |
-
'Origin': 'https://partyrock.aws'
|
| 186 |
-
},
|
| 187 |
-
body: JSON.stringify({
|
| 188 |
-
captcha_voucher: verifyResult.captcha_voucher,
|
| 189 |
-
existing_token: verifyResult.existing_token
|
| 190 |
-
})
|
| 191 |
-
});
|
| 192 |
-
|
| 193 |
-
return await voucherResponse.json();
|
| 194 |
-
}
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
return result;
|
| 198 |
} catch (error) {
|
| 199 |
console.error('调用 Capsolver API 时出错:', error);
|
| 200 |
throw error;
|
|
|
|
| 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,
|
|
|
|
| 112 |
}
|
| 113 |
});
|
| 114 |
|
| 115 |
+
console.log('发送到Capsolver的数据:', requestBody);
|
| 116 |
+
|
| 117 |
try {
|
| 118 |
const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/createTask`, {
|
| 119 |
method: 'POST',
|
| 120 |
headers: {
|
| 121 |
+
'Content-Type': 'application/json'
|
|
|
|
| 122 |
},
|
| 123 |
+
body: requestBody
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
});
|
| 125 |
|
| 126 |
if (!response.ok) {
|
|
|
|
| 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;
|