首页 开发文档 植物识别

植物识别

识别花卉绿植:名称、学名、科属、特征与养护建议,园艺与生活场景。上游处理较慢时,同步请求超过等待秒数会自动转为异步返回 task_id,可凭 task_id 调用任务查询接口获取最终结果,失败自动退款。

请求信息
请求地址 https://www.cx4.cn/openApi/ai/plant_recognize 复制
请求方式 GET / POST
接口标识 plant_recognize
鉴权方式 必须
四种方式任选其一:Header「X-Api-Key」/ Header「Authorization: Bearer 你的key」/ URL 参数「?key=你的key」/ POST 参数「key」
请求参数
参数名 类型 必填 说明 示例
image string 是 植物图片,公网 URL 或 base64 https://example.com/plant.jpg
async int 否 是否异步:0 同步直接返回(默认);1 异步提交返回 task_id,结果走回调或任务查询 0
callback_url string 否 异步回调地址(仅 async=1 生效),公网 http(s);有结果时 POST,HMAC-SHA256 签名 https://example.com/cb
返回参数

下表字段位于返回结构的 data 内;外层 code / message 为全平台统一格式,不在此重复列出。

参数名 类型 说明 示例
name string 植物名称 绿萝
latin_name string 学名(拉丁文) Epipremnum aureum
family string 科属 天南星科
description string 特征描述 叶片心形,翠绿有光泽…
care_tips string 养护建议 喜散射光,土干再浇,忌暴晒
confidence float 识别置信度 0-1 0.92
task_id string 同步请求超过系统配置的等待秒数仍未完成时自动转为异步,返回任务 ID;凭此调用「任务查询」接口获取结果 20261120a1b2c3d4e5
status string 仅转为异步时返回,任务状态 pending(同步完成时本字段不出现,直接返回业务结果) pending
返回示例

成功

{
    "code": 200,
    "message": "操作成功",
    "data": {
        "name": "绿萝",
        "latin_name": "Epipremnum aureum",
        "family": "天南星科",
        "description": "叶片心形",
        "care_tips": "喜散射光",
        "confidence": 0.92
    }
}

失败

{
    "code": 500,
    "message": "智能识别失败",
    "data": null
}
平台通用状态码
状态码 说明
200调用成功
400缺少必填参数或参数格式有误
401密钥缺失或无效
402余额不足,请充值后重试
403未开通该接口,请在本页开通后调用
404接口不存在或已下架
429触发限流,请稍后重试
500接口调用失败(已扣款的会自动退款)
调用示例

cURL 复制

curl -X POST "https://www.cx4.cn/openApi/ai/plant_recognize" -H "X-Api-Key: 你的SecretKey" -d "image=https://example.com/plant.jpg&async=0&callback_url=https://example.com/cb"

JavaScript 复制

fetch('https://www.cx4.cn/openApi/ai/plant_recognize', {
  method: 'POST',
  headers: {
    'X-Api-Key': '你的SecretKey',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: 'image=https://example.com/plant.jpg&async=0&callback_url=https://example.com/cb'
})
.then(res => res.json())
.then(data => console.log(data));

PHP 复制

<?php
require 'vendor/autoload.php';

$client = new \GuzzleHttp\Client();
$response = $client->post('https://www.cx4.cn/openApi/ai/plant_recognize', [
    'headers' => ['X-Api-Key' => '你的SecretKey'],
    'form_params' => ['image' => 'https://example.com/plant.jpg', 'async' => '0', 'callback_url' => 'https://example.com/cb'],
]);
echo $response->getBody();

Java 复制

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://www.cx4.cn/openApi/ai/plant_recognize"))
    .header("X-Api-Key", "你的SecretKey")
    .header("Content-Type", "application/x-www-form-urlencoded")
    .POST(HttpRequest.BodyPublishers.ofString("image=https://example.com/plant.jpg&async=0&callback_url=https://example.com/cb"))
    .build();
HttpResponse<String> response = client.send(
        request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Python 复制

import requests

res = requests.post('https://www.cx4.cn/openApi/ai/plant_recognize',
    headers={'X-Api-Key': '你的SecretKey'},
    data={'image': 'https://example.com/plant.jpg', 'async': '0', 'callback_url': 'https://example.com/cb'})
print(res.json())
在线测试 (使用你的密钥真实调用,计费与正常调用一致)

登录后可在线测试: 立即登录

计费说明

¥0.0500

每次调用


每日免费额度:无

累计调用:1 次


快速上手

1. 注册并完成邮箱验证:立即注册

2. 登录后复制 Secret Key:去登录

3. 点击右侧「开通接口」按钮

4. 用下方「在线测试」一键体验,或复制下方示例代码直接调用