# fastOcr — AI 验证码识别技能

## 概述

通过 HTTP API 识别验证码图片，支持算术题、汉字单字、滑块缺口、文字点选四种类型。按成功计费，失败不计费。

## API 端点

```
POST https://fastocr.kuaimeo.com/api/v1/captcha/recognize
```

## 认证

```
Authorization: Bearer focr_your_api_key
```

## 请求

```json
Content-Type: application/json

{
  "type": "answer",
  "image": "<base64编码的图片>"
}
```

### type 参数

| type | 说明 | 额外参数 |
|------|------|---------|
| answer | 算术题（如 3+5=?），返回数值答案 | 无 |
| hanzi | 汉字单字，返回汉字 | 无 |
| slider | 滑块缺口定位，返回 x 坐标 | 需额外传 piece（拼图块 base64） |
| clickword | 文字点选，返回候选字及坐标 | 无 |

## 响应

```json
{
  "code": 0,
  "request_id": "a1b2c3d4",
  "type": "answer",
  "result": { "answer": 14, "confidence": 0.999 },
  "cost": 15,
  "latency_ms": 120,
  "balance": 1985
}
```

### result 字段按 type 不同

- answer: `{"answer": 14, "confidence": 0.999}`
- hanzi: `{"char": "龙"}`
- slider: `{"x": 236}`
- clickword: `{"peaks": [[x,y],...], "candidates": [{"box":[x1,y1,x2,y2], "char":"龙", "conf":0.9}]}`

## 错误码

| code | 含义 |
|------|------|
| 0 | 成功 |
| 400 | 参数错误 |
| 401 | 认证失败（Key 无效） |
| 402 | 余额不足 |
| 500 | 服务异常（不计费） |

## curl 示例

```bash
# 识别算术题
curl -X POST https://fastocr.kuaimeo.com/api/v1/captcha/recognize \
  -H "Authorization: Bearer focr_your_key" \
  -H "Content-Type: application/json" \
  -d "{\"type\":\"answer\",\"image\":\"$(base64 -w0 captcha.png)\"}"

# 识别滑块
curl -X POST https://fastocr.kuaimeo.com/api/v1/captcha/recognize \
  -H "Authorization: Bearer focr_your_key" \
  -H "Content-Type: application/json" \
  -d "{\"type\":\"slider\",\"image\":\"$(base64 -w0 bg.png)\",\"piece\":\"$(base64 -w0 piece.png)\"}"
```

## Python（requests，无需 SDK）

```python
import requests, base64

API = "https://fastocr.kuaimeo.com/api/v1/captcha/recognize"
KEY = "focr_your_key"

img_b64 = base64.b64encode(open("captcha.png", "rb").read()).decode()
resp = requests.post(API, json={"type": "answer", "image": img_b64},
                     headers={"Authorization": f"Bearer {KEY}"})
data = resp.json()
print(data["result"])  # {"answer": 14, "confidence": 0.999}
```

## 获取 API Key

访问 https://fastocr.kuaimeo.com/register 注册（送 2000 积分），在控制台生成 Key。
