API v1 · Reference
接口参考
查看各接口的请求方式、参数、响应字段和调用示例。
统一约定
接口地址为 https://gezhao.cn/api/open/gezhao,统一使用 Authorization: Bearer API Key 认证。JSON 响应都会包含链路标识 request_id,错误结构见错误码。
流程对应关系
直接成品:create(mode=final) → result → 下载。预览确认:create(mode=preview) → result → finalize → 下载。status 查询队列进度,files 查询文件列表。查看流程说明
GET
获取规格列表
https://gezhao.cn/api/open/gezhao/idphoto/specs获取全部可用的证件照规格。返回的 code 用于创建证件照。
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
items | Specification[] | 规格列表 |
items[].code | string | 用于创建证件照的规格代码 |
items[].width_px / height_px | integer | 成品宽高,单位为像素 |
items[].width_mm / height_mm | number | 成品宽高,单位为毫米 |
items[].backgrounds | string[] | 可选的背景色 |
请求示例
1curl --silent --show-error \
2 -H "Authorization: Bearer $API_KEY" \
3 "https://gezhao.cn/api/open/gezhao/idphoto/specs"响应示例
{
"request_id": "req_example_001",
"items": [{
"code": "one-inch",
"name": "一寸",
"width_mm": 25,
"height_mm": 35,
"width_px": 295,
"height_px": 413,
"dpi": 300,
"use": "常用证件照",
"backgrounds": ["#FFFFFF", "#438EDB", "#D73232"]
}]
}GET
获取规格详情
https://gezhao.cn/api/open/gezhao/idphoto/specs/detail根据规格代码获取尺寸、分辨率和可选背景色。
请求参数
| 名称 | 是否必填 | 类型 | 说明 |
|---|---|---|---|
code | 是 | string | 查询参数,填写规格代码,例如 one-inch |
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
code | string | 规格代码 |
name | string | 规格名称 |
width_px / height_px | integer | 成品宽高,单位为像素 |
width_mm / height_mm | number | 成品宽高,单位为毫米 |
dpi | integer | 输出分辨率 |
backgrounds | string[] | 可选的背景色 |
请求示例
1curl --silent --show-error --get \
2 -H "Authorization: Bearer $API_KEY" \
3 --data-urlencode "code=$SPECIFICATION_CODE" \
4 "https://gezhao.cn/api/open/gezhao/idphoto/specs/detail"响应示例
{
"request_id": "req_example_002",
"code": "one-inch",
"name": "一寸",
"width_mm": 25,
"height_mm": 35,
"width_px": 295,
"height_px": 413,
"dpi": 300,
"use": "常用证件照",
"backgrounds": ["#FFFFFF", "#438EDB", "#D73232"]
}POST
创建证件照
https://gezhao.cn/api/open/gezhao/idphoto/create上传人像照片并创建处理任务。mode=final 直接生成成品;mode=preview 先生成免费水印预览。
请求参数
| 名称 | 是否必填 | 类型 | 说明 |
|---|---|---|---|
Idempotency-Key | 是 | string | 请求头,填写 8~128 位字符;重试同一请求时请保持不变 |
image | 是 | binary | 待处理的人像图片 |
specification_code | 是 | string | 预设规格代码 |
mode | 否 | preview | final | 生成模式,默认 preview;直接生成成品时传 final |
backgrounds | 否 | APIBackground[] | 背景设置,使用 JSON 字符串;最多填写一个 |
output | 否 | APIOutput | 输出设置,使用 JSON 字符串 |
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
photo_id | string | 证件照资源标识 |
job_id | string | 异步任务标识,仅在使用任务进度接口时需要 |
status | string | 处理状态:queued、processing、preview_ready、finalizing、completed 或 failed |
mode | string | 生成模式:preview 或 final |
specification | Specification | 本次任务采用的规格 |
quality | object | 质量检测结果 |
files | APIFile[] | 已生成的文件 |
billing | APIBilling | 计费状态及金额 |
expires_at | date-time | 资源失效时间 |
请求示例
1curl --silent --show-error \
2 -H "Authorization: Bearer $API_KEY" \
3 -H "Idempotency-Key: create-photo-0001" \
4 -F "image=@portrait.jpg" \
5 -F "mode=final" \
6 -F "specification_code=one-inch" \
7 -F 'backgrounds=[{"type":"preset","value":"white"}]' \
8 -F 'output={"format":"jpeg","dpi":300,"include_layout":true,"layout_size":"6-inch"}' \
9 "https://gezhao.cn/api/open/gezhao/idphoto/create"响应示例
{
"request_id": "req_example_001",
"photo_id": "photo_0123456789abcdef0123456789abcdef",
"job_id": "job_0123456789abcdef0123456789abcdef",
"status": "queued",
"mode": "final",
"specification": {
"code": "one-inch",
"name": "一寸",
"width_px": 295,
"height_px": 413,
"width_mm": 25,
"height_mm": 35,
"dpi": 300,
"use": "常用证件照",
"backgrounds": ["#FFFFFF", "#438EDB", "#D73232"]
},
"quality": {},
"files": [],
"billing": {
"pricing_rule_id": "price_api_default",
"version": 1,
"points": 5,
"amount_cents": 50,
"currency": "CNY",
"status": "frozen",
"charged": false
},
"created_at": "2026-07-15T08:00:00Z",
"expires_at": "2026-07-16T08:00:00Z"
}异步响应 · 202 Accepted
业务侧保存 photo_id 并用它查询结果;job_id 只在需要任务诊断时使用。请求超时后,使用相同内容和幂等键重试。
GET
查询证件照结果
https://gezhao.cn/api/open/gezhao/idphoto/result使用 photo_id 查询业务状态、质量检测、计费信息和可下载文件。
请求参数
| 名称 | 是否必填 | 类型 | 说明 |
|---|---|---|---|
photo_id | 是 | string | 查询参数,填写创建接口返回的 photo_id |
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
photo_id | string | 证件照资源标识 |
job_id | string | 异步任务标识,仅在使用任务进度接口时需要 |
status | string | 处理状态:queued、processing、preview_ready、finalizing、completed 或 failed |
mode | string | 生成模式:preview 或 final |
specification | Specification | 本次任务采用的规格 |
quality | object | 质量检测结果 |
files | APIFile[] | 已生成的文件 |
billing | APIBilling | 计费状态及金额 |
expires_at | date-time | 资源失效时间 |
请求示例
1curl --silent --show-error --get \
2 -H "Authorization: Bearer $API_KEY" \
3 --data-urlencode "photo_id=$PHOTO_ID" \
4 "https://gezhao.cn/api/open/gezhao/idphoto/result"响应示例
{
"request_id": "req_example_001",
"photo_id": "photo_0123456789abcdef0123456789abcdef",
"job_id": "job_0123456789abcdef0123456789abcdef",
"status": "completed",
"mode": "final",
"specification": {
"code": "one-inch",
"name": "一寸",
"width_px": 295,
"height_px": 413,
"width_mm": 25,
"height_mm": 35,
"dpi": 300,
"use": "常用证件照",
"backgrounds": ["#FFFFFF", "#438EDB", "#D73232"]
},
"quality": {},
"files": [
{
"file_id": "file_11111111111111111111111111111111",
"kind": "photo",
"format": "jpeg",
"width_px": 295,
"height_px": 413,
"size_bytes": 48216,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_11111111111111111111111111111111",
"expires_at": "2026-07-16T08:00:00Z"
},
{
"file_id": "file_22222222222222222222222222222222",
"kind": "transparent",
"format": "png",
"width_px": 295,
"height_px": 413,
"size_bytes": 93640,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_22222222222222222222222222222222",
"expires_at": "2026-07-16T08:00:00Z"
},
{
"file_id": "file_33333333333333333333333333333333",
"kind": "layout",
"format": "jpeg",
"size_bytes": 186420,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_33333333333333333333333333333333",
"expires_at": "2026-07-16T08:00:00Z"
}
],
"billing": {
"pricing_rule_id": "price_api_default",
"version": 1,
"points": 5,
"amount_cents": 50,
"currency": "CNY",
"status": "confirmed",
"charged": true
},
"created_at": "2026-07-15T08:00:00Z",
"expires_at": "2026-07-16T08:00:00Z"
}根据 status 决定下一步
queued / processing / finalizing 继续查询;preview_ready 展示预览并等待确认;completed 直接下载;failed 停止查询。
POST
确认预览并生成成品
https://gezhao.cn/api/open/gezhao/idphoto/finalize仅用于 mode=preview 的流程。用户确认水印预览后调用;接口扣费并开放无水印成品,无需重新上传照片。
请求参数
| 名称 | 是否必填 | 类型 | 说明 |
|---|---|---|---|
Idempotency-Key | 是 | string | 请求头,填写 8~128 位字符;重试同一请求时请保持不变 |
photo_id | 是 | string | 处于 preview_ready 状态的证件照标识 |
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
photo_id | string | 证件照资源标识 |
job_id | string | 异步任务标识,仅在使用任务进度接口时需要 |
status | string | 处理状态:queued、processing、preview_ready、finalizing、completed 或 failed |
mode | string | 生成模式:preview 或 final |
specification | Specification | 本次任务采用的规格 |
quality | object | 质量检测结果 |
files | APIFile[] | 已生成的文件 |
billing | APIBilling | 计费状态及金额 |
expires_at | date-time | 资源失效时间 |
请求示例
1curl --request POST \
2 -H "Authorization: Bearer $API_KEY" \
3 -H "Idempotency-Key: finalize-photo-0001" \
4 --url-query "photo_id=$PHOTO_ID" \
5 "https://gezhao.cn/api/open/gezhao/idphoto/finalize"响应示例
{
"request_id": "req_example_001",
"photo_id": "photo_0123456789abcdef0123456789abcdef",
"job_id": "job_0123456789abcdef0123456789abcdef",
"status": "completed",
"mode": "final",
"specification": {
"code": "one-inch",
"name": "一寸",
"width_px": 295,
"height_px": 413,
"width_mm": 25,
"height_mm": 35,
"dpi": 300,
"use": "常用证件照",
"backgrounds": ["#FFFFFF", "#438EDB", "#D73232"]
},
"quality": {},
"files": [
{
"file_id": "file_11111111111111111111111111111111",
"kind": "photo",
"format": "jpeg",
"width_px": 295,
"height_px": 413,
"size_bytes": 48216,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_11111111111111111111111111111111",
"expires_at": "2026-07-16T08:00:00Z"
},
{
"file_id": "file_22222222222222222222222222222222",
"kind": "transparent",
"format": "png",
"width_px": 295,
"height_px": 413,
"size_bytes": 93640,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_22222222222222222222222222222222",
"expires_at": "2026-07-16T08:00:00Z"
},
{
"file_id": "file_33333333333333333333333333333333",
"kind": "layout",
"format": "jpeg",
"size_bytes": 186420,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_33333333333333333333333333333333",
"expires_at": "2026-07-16T08:00:00Z"
}
],
"billing": {
"pricing_rule_id": "price_api_default",
"version": 1,
"points": 5,
"amount_cents": 50,
"currency": "CNY",
"status": "confirmed",
"charged": true
},
"created_at": "2026-07-15T08:00:00Z",
"expires_at": "2026-07-16T08:00:00Z"
}适用条件
此接口处理 mode=preview 且状态为 preview_ready 的证件照。mode=final 的任务由创建流程直接结算。
GET
查询处理进度
https://gezhao.cn/api/open/gezhao/idphoto/status使用 job_id 查询队列状态和重试次数。
请求参数
| 名称 | 是否必填 | 类型 | 说明 |
|---|---|---|---|
job_id | 是 | string | 创建接口返回的异步任务标识 |
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
job_id | string | 任务标识 |
photo_id | string | 关联的证件照标识 |
status | string | 证件照业务状态 |
queue_status | string | 队列状态:queued、processing、succeeded 或 failed |
attempt_count | integer | 已执行次数 |
quality | object | 质量检测结果 |
expires_at | date-time | 任务失效时间 |
请求示例
1curl --silent --show-error --get \
2 -H "Authorization: Bearer $API_KEY" \
3 --data-urlencode "job_id=$JOB_ID" \
4 "https://gezhao.cn/api/open/gezhao/idphoto/status"响应示例
{
"request_id": "req_example_006",
"job_id": "job_0123456789abcdef0123456789abcdef",
"photo_id": "photo_0123456789abcdef0123456789abcdef",
"status": "completed",
"queue_status": "succeeded",
"attempt_count": 1,
"quality": {"passed": true, "issues": []},
"expires_at": "2026-07-16T08:00:00Z"
}GET
查询生成文件
https://gezhao.cn/api/open/gezhao/idphoto/files使用 photo_id 获取当前可访问的预览和成品文件列表。
请求参数
| 名称 | 是否必填 | 类型 | 说明 |
|---|---|---|---|
photo_id | 是 | string | 证件照资源标识 |
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
photo_id | string | 证件照资源标识 |
items | APIFile[] | 当前可访问文件,最多 4 个 |
items[].kind | string | preview、photo、transparent 或 layout |
items[].download_url | string | 带认证的文件下载地址,响应 302 跳转到 5 分钟有效的签名地址,客户端需跟随跳转(如 curl -L) |
expires_at | date-time | 文件失效时间 |
请求示例
1curl --silent --show-error --get \
2 -H "Authorization: Bearer $API_KEY" \
3 --data-urlencode "photo_id=$PHOTO_ID" \
4 "https://gezhao.cn/api/open/gezhao/idphoto/files"响应示例
{
"request_id": "req_example_007",
"photo_id": "photo_0123456789abcdef0123456789abcdef",
"items": [
{
"file_id": "file_11111111111111111111111111111111",
"kind": "photo",
"format": "jpeg",
"width_px": 295,
"height_px": 413,
"size_bytes": 48216,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_11111111111111111111111111111111",
"expires_at": "2026-07-16T08:00:00Z"
},
{
"file_id": "file_22222222222222222222222222222222",
"kind": "transparent",
"format": "png",
"width_px": 295,
"height_px": 413,
"size_bytes": 93640,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_22222222222222222222222222222222",
"expires_at": "2026-07-16T08:00:00Z"
},
{
"file_id": "file_33333333333333333333333333333333",
"kind": "layout",
"format": "jpeg",
"size_bytes": 186420,
"download_url": "https://gezhao.cn/api/open/gezhao/idphoto/download?file_id=file_33333333333333333333333333333333",
"expires_at": "2026-07-16T08:00:00Z"
}
],
"expires_at": "2026-07-16T08:00:00Z"
}