📡 百川条码查询 API 使用说明
接口概述
本API提供商品条码查询功能,支持EAN-13和EAN-8格式的条码查询。通过API接口,您可以快速查询商品信息,并按套餐内查询量扣减使用次数。
💡 使用前提:您需要先在用户中心购买API套餐,获取API Key和Secret Key后方可使用本接口。
请求地址
https://tiaoma.cnaidc.com/api/api_query.php
请求方式
支持 GET 和 POST 两种请求方式
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
api_key |
string | 是 | 您的API Key,从用户中心API服务页面获取 |
secret_key |
string | 是 | 您的Secret Key,从用户中心API服务页面获取 |
code_sn |
string | 是 | 要查询的条形码号码,支持EAN-13(13位)和EAN-8(8位) |
响应参数
| 参数名 | 说明 |
|---|---|
code |
状态码,1 表示成功,0 表示失败 |
msg |
返回信息,描述请求结果 |
data |
查询到的产品信息对象(查询成功时返回),包含:code_sn、code_name、code_type、code_company、code_price、code_spec、code_unit、code_pinpai、code_img、code_country |
响应示例
查询成功
{
"code": 1,
"msg": "查询成功",
"data": {
"code_sn": "6901234567890",
"code_name": "产品名称",
"code_type": "EAN-13",
"code_company": "xxx公司",
"code_price": "29.90",
"code_spec": "500g",
"code_unit": "克",
"code_pinpai": "品牌名称",
"code_country": "中国"
"code_img": "https://example.com/img.jpg"
}
}
条码不存在(返回国家信息)
{
"code": 0,
"msg": "未找到该条形码对应的产品信息",
"data": {
"country": "中国"
}
}
余额不足
{
"code": 0,
"msg": "套餐查询次数已用完"
}
API Key错误
{
"code": 0,
"msg": "API Key或Secret Key错误"
}
代码示例
PHP 示例
$url = 'https://tiaoma.cnaidc.com/api/api_query.php';
$data = [
'api_key' => '您的API Key',
'secret_key' => '您的Secret Key',
'code_sn' => '6901234567890'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['code'] == 1) {
echo "产品名称:" . $result['data']['code_name'];
echo "品牌:" . $result['data']['code_pinpai'];
echo "价格:" . $result['data']['code_price'];
} else {
echo "查询失败:" . $result['msg'];
}
Python 示例
import requests
url = 'https://tiaoma.cnaidc.com/api/api_query.php'
data = {
'api_key': '您的API Key',
'secret_key': '您的Secret Key',
'code_sn': '6901234567890'
}
response = requests.post(url, data=data)
result = response.json()
if result['code'] == 1:
print(f"产品名称:{result['data']['code_name']}")
print(f"品牌:{result['data']['code_pinpai']}")
print(f"价格:{result['data']['code_price']}")
else:
print(f"查询失败:{result['msg']}")
JavaScript (jQuery) 示例
$.ajax({
url: 'https://tiaoma.cnaidc.com/api/api_query.php',
type: 'POST',
data: {
api_key: '您的API Key',
secret_key: '您的Secret Key',
code_sn: '6901234567890'
},
success: function(result) {
if (result.code == 1) {
console.log('产品名称:' + result.data.code_name);
console.log('品牌:' + result.data.code_pinpai);
console.log('价格:' + result.data.code_price);
} else {
console.log('查询失败:' + result.msg);
}
}
});
JavaScript (Fetch) 示例
const response = await fetch('https://tiaoma.cnaidc.com/api/api_query.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
api_key: '您的API Key',
secret_key: '您的Secret Key',
code_sn: '6901234567890'
})
});
const result = await response.json();
if (result.code == 1) {
console.log('产品名称:' + result.data.code_name);
} else {
console.log('查询失败:' + result.msg);
}
错误码说明
| 错误信息 | 说明 |
|---|---|
参数不完整 |
缺少必填参数 api_key、secret_key 或 code_sn |
API Key或Secret Key错误 |
密钥验证失败,请检查Key是否正确 |
API Key已被禁用 |
您的API Key已被管理员禁用 |
无可用的套餐 |
您还没有购买套餐或套餐已过期 |
套餐查询次数已用完 |
当前套餐的总查询次数已用完,请购买新套餐 |
今日查询次数已用完 |
今日查询次数已达上限,请明天再试 |
注意事项
- 请妥善保管您的
api_key和secret_key,不要泄露给他人 - API采用按套餐扣量模式,查询成功才会扣减次数
- 支持 EAN-13(13位)和 EAN-8(8位)格式的条码
- 部分条码可能不存在于数据库中,返回时会附带条码前缀对应的国家信息
- 查询频率建议控制在合理范围内,避免触发风控
⚠️ 免责声明:本API仅提供已有的商品条码信息查询服务,不对查询结果的准确性做任何承诺。如有疑问,请联系管理员。
获取API Key
如果您还没有API Key,请按以下步骤操作:
- 注册并登录商品条码查询系统
- 进入 用户中心 → API服务
- 创建API Key并购买相应的查询套餐
- 购买后联系管理员启用套餐