Update index.js
Browse files
index.js
CHANGED
|
@@ -98,75 +98,97 @@ class CapsolverClient {
|
|
| 98 |
}
|
| 99 |
|
| 100 |
async createTask(websiteURL, websiteKey, extraParams = {}) {
|
| 101 |
-
//
|
| 102 |
-
const
|
|
|
|
| 103 |
headers: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
'Referer': 'https://partyrock.aws/',
|
| 105 |
-
'Origin': 'https://partyrock.aws'
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
| 108 |
});
|
| 109 |
|
| 110 |
-
if (!
|
| 111 |
-
|
|
|
|
| 112 |
}
|
| 113 |
|
| 114 |
-
const
|
| 115 |
-
console.log('验证码数据:',
|
| 116 |
|
|
|
|
| 117 |
const requestBody = JSON.stringify({
|
| 118 |
clientKey: this.apiKey,
|
| 119 |
task: {
|
| 120 |
type: "AwsWafClassification",
|
| 121 |
websiteURL: websiteURL,
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
}
|
| 125 |
});
|
| 126 |
|
| 127 |
console.log('发送到Capsolver的数据:', requestBody);
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
method: 'POST',
|
| 132 |
headers: {
|
| 133 |
-
'Content-Type': 'application/json'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
},
|
| 135 |
-
body:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
});
|
| 137 |
|
| 138 |
-
if (!
|
| 139 |
-
|
| 140 |
-
const errorText = await response.text();
|
| 141 |
-
console.error('错误响应内容:', errorText);
|
| 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
|
| 166 |
-
} catch (error) {
|
| 167 |
-
console.error('调用 Capsolver API 时出错:', error);
|
| 168 |
-
throw error;
|
| 169 |
}
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
}
|
| 172 |
|
|
|
|
| 98 |
}
|
| 99 |
|
| 100 |
async createTask(websiteURL, websiteKey, extraParams = {}) {
|
| 101 |
+
// 第一步:发送初始化请求获取验证码
|
| 102 |
+
const initResponse = await fetch(extraParams.captchaUrl + '/init', {
|
| 103 |
+
method: 'POST',
|
| 104 |
headers: {
|
| 105 |
+
'Content-Type': 'application/json',
|
| 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 |
+
'sec-ch-ua': '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
|
| 108 |
+
'sec-ch-ua-platform': '"Windows"',
|
| 109 |
+
'sec-ch-ua-mobile': '?0',
|
| 110 |
'Referer': 'https://partyrock.aws/',
|
| 111 |
+
'Origin': 'https://partyrock.aws'
|
| 112 |
+
},
|
| 113 |
+
body: JSON.stringify({
|
| 114 |
+
gokuProps: extraParams.gokuProps
|
| 115 |
+
})
|
| 116 |
});
|
| 117 |
|
| 118 |
+
if (!initResponse.ok) {
|
| 119 |
+
console.error('初始化验证码失败:', await initResponse.text());
|
| 120 |
+
throw new Error('初始化验证码失败');
|
| 121 |
}
|
| 122 |
|
| 123 |
+
const initData = await initResponse.json();
|
| 124 |
+
console.log('验证码初始化数据:', initData);
|
| 125 |
|
| 126 |
+
// 第二步:创建 Capsolver 任务
|
| 127 |
const requestBody = JSON.stringify({
|
| 128 |
clientKey: this.apiKey,
|
| 129 |
task: {
|
| 130 |
type: "AwsWafClassification",
|
| 131 |
websiteURL: websiteURL,
|
| 132 |
+
websiteKey: websiteKey,
|
| 133 |
+
metadata: {
|
| 134 |
+
images: initData.images || [],
|
| 135 |
+
question: initData.question || '',
|
| 136 |
+
context: extraParams.gokuProps.context,
|
| 137 |
+
iv: extraParams.gokuProps.iv,
|
| 138 |
+
key: extraParams.gokuProps.key
|
| 139 |
+
}
|
| 140 |
}
|
| 141 |
});
|
| 142 |
|
| 143 |
console.log('发送到Capsolver的数据:', requestBody);
|
| 144 |
|
| 145 |
+
const response = await fetch(`${CAPSOLVER_CONFIG.API_URL}/createTask`, {
|
| 146 |
+
method: 'POST',
|
| 147 |
+
headers: {
|
| 148 |
+
'Content-Type': 'application/json'
|
| 149 |
+
},
|
| 150 |
+
body: requestBody
|
| 151 |
+
});
|
| 152 |
+
|
| 153 |
+
if (!response.ok) {
|
| 154 |
+
console.error('Capsolver API 响应不成功:', response.status);
|
| 155 |
+
const errorText = await response.text();
|
| 156 |
+
console.error('错误响应内容:', errorText);
|
| 157 |
+
throw new Error(`Capsolver API 请求失败: ${response.status}`);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
const result = await response.json();
|
| 161 |
+
console.log('Capsolver 返回结果:', result);
|
| 162 |
+
|
| 163 |
+
// 第三步:提交验证结果
|
| 164 |
+
if (result.solution) {
|
| 165 |
+
const verifyResponse = await fetch(extraParams.captchaUrl + '/verify', {
|
| 166 |
method: 'POST',
|
| 167 |
headers: {
|
| 168 |
+
'Content-Type': 'application/json',
|
| 169 |
+
'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',
|
| 170 |
+
'sec-ch-ua': '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
|
| 171 |
+
'sec-ch-ua-platform': '"Windows"',
|
| 172 |
+
'sec-ch-ua-mobile': '?0',
|
| 173 |
+
'Referer': 'https://partyrock.aws/',
|
| 174 |
+
'Origin': 'https://partyrock.aws'
|
| 175 |
},
|
| 176 |
+
body: JSON.stringify({
|
| 177 |
+
solution: result.solution,
|
| 178 |
+
context: extraParams.gokuProps.context,
|
| 179 |
+
iv: extraParams.gokuProps.iv,
|
| 180 |
+
key: extraParams.gokuProps.key
|
| 181 |
+
})
|
| 182 |
});
|
| 183 |
|
| 184 |
+
if (!verifyResponse.ok) {
|
| 185 |
+
throw new Error('验证提交失败');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
|
| 188 |
+
return await verifyResponse.json();
|
|
|
|
|
|
|
|
|
|
| 189 |
}
|
| 190 |
+
|
| 191 |
+
return result;
|
| 192 |
}
|
| 193 |
}
|
| 194 |
|