CloudFlareTurnstile 任务
通过 createTask方法 创建识别任务,然后通过 getTaskResult 方法 获取识别结果
创建任务
通过以下方法创建任务
请求host: https://api.ez-captcha.com
请求api: https://api.ez-captcha.com/createTask
请求format:POST
application/json
参数
参数 | 类型 | 是否必须 | 描述 |
---|---|---|---|
clientKey | string | yes | 你的clientkey |
type | string | yes | CloudFlareTurnstileTask |
websiteURL | string | yes | 网站url |
websiteKey | string | yes | 网站key |
rqData | Object | optional | Turnstile 额外参数 (参考文档:Document) |
rqData.mode | string | optional | Turnstile元素的data-action属性的值(如果存在)。 |
rqData.metadataAction | string | optional | Turnstile元素的data-action属性的值(如果存在)。 |
rqData.metadataCdata | string | optional | Turnstile元素的data-action属性的值(如果存在)。 |
示例
POST https://api.ez-captcha.com/createTask
Content-Type: application/json
{
"clientKey": "YourClientKey",
"task": {
"websiteURL": "https://xxx.com",
"type": "CloudFlareTurnstileTask",
"websiteKey": "xxxx",
"rqData":{ //可选
"mode":"flexible",
"metadataAction":"signup",
"metadataCdata":""
},
}
}
返回示例
{
"errorId": 0,
"errorCode": "",
"errorDescription": "",
"taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006" // Please save this ID for next step
}
获取结果
使用 getTaskResult 方法获取结果
请求 host: https://api.ez-captcha.com
请求 api: https://api.ez-captcha.com/getTaskResult
请求 format:POST
application/json
Request Example
POST https://api.ez-captcha.com/getTaskResult
Content-Type: application/json
{
"clientKey":"YOUR_API_KEY",
"taskId": "TASKID OF CREATETASK" //ID created by createTask method
}
返回参数
参数 | 类型 | 描述 |
---|---|---|
errorId | Integer | 错误提示: 0 - 没有错误,1 - 有错误 |
errorCode | string | 错误代码, 点这里查看全部错误列表 |
errorDescription | string | 错误详细描述 |
status | String | processing - 正在识别中,请3秒后重试 |
solution | Object | 识别结果,不同类型的任务结果会有所区别。 |
返回示例
{
"errorId": 0,
"errorCode": null,
"errorDescription": null,
"solution": {
{"header": {}, "token": "0.alU6fkxnt1TwF7lTlYWWdu0o80HW-4unnp..."}
},
"status": "ready"
}
响应说明
识别成功:当
errorId
等于0
并且status
等于ready
,结果在solution
里面。正在识别中:当
errorId
等于0
并且status
等于processing
,请1-3秒后重试。出错了:当
errorId
大于0
,请根据errorDescription
了解出错误信息 全部错误说明
代码示例
import threading
import time
import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def test():
start_time = time.time()
data = {
"clientKey": "YourClientKey",
"task": {
"type": "CloudFlareTurnstileTask",#
"websiteURL": "https://xxx.com/",
"websiteKey": "websiteKey",
}
}
resp = requests.post("https://api.ez-captcha.com/createTask", json=data,verify=False)
task_id = resp.json()['taskId']
print(f"task_id: {task_id}")
for _ in range(30):
data = {
"clientKey": "YourClientKey",#
"taskId": task_id
}
resp = requests.post("https://api.ez-captcha.com/getTaskResult", json=data,verify=False)
if "token" in resp.text:
resp_json = json.loads(resp.text)
print(f"token: {resp_json.get('solution', {}).get('token', {})}")
end_time = time.time()
print(f"time: {end_time - start_time}")
break;
elif "errorDesc" in resp.text:
print(resp.text)
break;
time.sleep(1)
if __name__ == '__main__':
test()