什么是腾讯验证码(TenDI)以及如何解决它?
腾讯验证码 是由腾讯开发的自动化防护系统。它广泛应用于各种在线平台,如网上购物、社交媒体和金融服务,以防止垃圾信息、欺诈和其他类型的滥用行为。
主要的腾讯验证码检查器类型是一个滑动条,它提示用户移动滑动条以使拼图元素合在一起

还有图形验证码,需要按顺序点击所需的元素:

或者,用户被要求解码音频验证码:

腾讯还提供了智能验证(或“智能验证”),类似于许多其他系统(如谷歌的reCAPTCHA)。这种智能验证使用机器学习算法和用户行为分析来判断在网络资源上的行为是真实的还是自动攻击。
CapMonster云服务可以帮助解决大多数不同类型的验证码,包括腾讯验证码。为此,你需要使用POST方法以JSON格式向服务器发送请求,如下所示:
{
"clientKey": "dce6bcbb1a728ea8d871de6d169a2057",
"task": {
"type": "CustomTask",
"class": "TenDI",
"websiteURL": "https://domain.com",
"websiteKey": "189123456",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
}
}
请求中使用的参数:
参数 | 类型 | 必需 | 值 |
---|---|---|---|
type | String | 是 | CustomTask |
class | String | 是 | TenDI |
websiteURL | String | 是 | 解决验证码的主页面地址。 |
websiteKey | String | 是 | captchaAppId。例如,“websiteKey”: “189123456” - 你网站的唯一参数,可以从包含验证码的HTML页面或流量中获取。 |
userAgent | String | 否 | 浏览器的User-Agent。仅传递来自Windows操作系统的当前UA。 |
成功解决验证码的响应示例如下(也是JSON格式):
{
"errorId": 0,
"taskId": 407533072
}
获取解决方案的示例:
使用getTaskResult
:
{
"errorId": 0,
"status": "ready",
"solution": {
"data": {
"randstr": "@EcL",
"ticket": "tr03lHU nuW3neJZu.....7LrIbs*"
},
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
}
}
}
randstr
是腾讯验证码解决方案的一部分,用于识别和验证验证码解决方案。
ticket
是一个唯一标识符,也是验证码解决方案的一部分,用于验证验证码解决方案的正确性并访问受保护的内容或功能。
要发送请求到服务器以进行自动解决,你需要事先知道唯一的验证码标识符。这很容易找到:在浏览器中加载包含验证码的页面,调用验证码本身并打开开发者工具。在“网络”选项卡中,在请求中找到包含关键字“aid”的一行 - 这是该页面上的验证码标识符。它看起来像这样:

以下是使用JavaScript和Python在CapMonster云服务器上解决这种验证码的示例脚本。
// 创建发送到服务器的任务
async function solveTencentCaptcha(apiKey, pageUrl, captchaKey) {
const solveUrl = 'https://api.capmonster.cloud/createTask';
// 准备任务数据
const taskData = {
clientKey: apiKey,
task: {
type: 'CustomTask',
class: 'TenDI',
websiteURL: pageUrl,
websiteKey: captchaKey,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
}
};
try {
// 发送POST请求以创建任务
const responseData = await postJson(solveUrl, taskData);
// 提取验证码ID
return responseData.taskId;
} catch (error) {
// 发送请求时的错误处理
console.error('请求时出错:', error.message);
return null;
}
}
async function getCaptchaSolution(apiKey, taskId) {
// 请求任务结果的URL
const resultUrl = 'https://api.capmonster.cloud/getTaskResult';
// 准备请求结果的数据
const resultData = { clientKey: apiKey, taskId: taskId };
// 限制15次尝试的任务结果查询循环
for (let i = 0; i < 15; i++) {
try {
// 发送POST请求以获取任务结果
const responseData = await postJson(resultUrl, resultData);
// 检查任务状态
if (responseData.status === 'ready') return responseData;
} catch (error) {
// 获取结果时处理错误
console.error('接收结果时出错:', error.message);
}
// 在下一次尝试前等待1秒
await sleep(1000);
}
// 如果无法在15次尝试中获取结果,则显示错误消息
console.error('在15次尝试中未能获取结果');
return null;
}
// 用于发送带有JSON数据的POST请求的函数
async function postJson(url, data) {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
return response.json();
}
// 用于暂停执行指定时间的函数
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// 启动验证码解决过程的主函数
async function main() {
const apiKey = 'YOUR_CAPMONSTER_API';
const pageUrl = 'https://example.com';
const captchaKey = '189939991';
// 验证码解决
const taskId = await solveTencentCaptcha(apiKey, pageUrl, captchaKey);
console.log("任务ID:", taskId);
if (taskId) {
// 获取任务结果
const resultData = await getCaptchaSolution(apiKey, taskId);
if (resultData) console.log("结果:", resultData);
}
}
main();
# 导入必要的库
import requests
import time
# 用于发送请求以创建验证码解决任务的函数
def solve_tencent_captcha(api_key, page_url, captcha_key):
# 创建任务请求的URL
solve_url = 'https://api.capmonster.cloud/createTask'
# 准备任务数据
task_data = {
"clientKey": api_key,
"task": {
"type": "CustomTask",
"class": "TenDI",
"websiteURL": page_url,
"websiteKey": captcha_key,
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
}
}
# 发送POST请求
response = requests.post(solve_url, json=task_data)
# 从响应中检索数据并返回任务标识符
response_data = response.json()
task_id = response_data.get('taskId')
return task_id
# 获取验证码解决方案的函数
def get_captcha_solution(api_key, task_id):
# 任务结果检索的URL
result_url = 'https://api.capmonster.cloud/getTaskResult'
# 准备结果请求的数据
result_data = {
"clientKey": api_key,
"taskId": task_id
}
# 限制获取结果的尝试次数
attempts = 0
max_attempts = 15
# 重复结果请求的循环
while attempts < max_attempts:
# 发送POST请求以获取结果
response = requests.post(result_url, json=result_data)
response_data = response.json()
# 检查响应状态
if response_data['status'] == 'ready':
return response_data
# 在下一次请求前等待1秒
time.sleep(1)
attempts += 1
# 如果超过最大尝试次数,显示消息
print("获取结果的尝试次数已超出")
return None
# 主函数
def main():
api_key = 'YOUR_CAPMONSTER_API'
page_url = 'https://example.com'
captcha_key = '189939991'
# 解决验证码并获取任务ID
task_id = solve_tencent_captcha(api_key, page_url, captcha_key)
print("任务ID:", task_id)
# 如果任务成功创建,则重复查询以获取结果
if task_id:
result_data = get_captcha_solution(api_key, task_id)
print("结果:", result_data)
# 脚本启动时运行主函数
if __name__ == "__main__":
main()
查看我们轻松解决腾讯验证码和其他类型验证码的工具和解决方案:
- CapMonster Cloud API
- CapMonster Cloud浏览器扩展程序 Chrome / Firefox
注意:我们提醒你,该产品用于在你自己的网站和你有合法访问权的网站上自动化测试。