中国工控网(国内领先的工业自动化 B2B 平台)的 item_get 接口,是精准获取工控类商品全维度详情的核心入口,专注服务 PLC、传感器、变频器、伺服系统、工控机等自动化设备采购场景。该接口支持通过商品 ID 或详情页 URL,提取工业级核心数据(如技术参数、兼容性、认证资质、售后保障、供应商实力),广泛应用于自动化项目选型、设备替换采购、供应商评估、备件库存管理等核心业务,是工控场景下对接平台数据的必备工具。
一、接口核心认知:先明确 “能做什么”“适配什么场景”
1. 接口定位与核心价值
2. 核心参数与返回字段(工控场景适配版)
(1)请求参数(必填 + 可选,按优先级排序)
(2)返回核心字段(按业务场景分类,工控重点标注)
3. 接口限制与注意事项
二、对接前准备:3 步搞定前置条件
1. 注册与获取密钥(核心步骤)
2. 技术环境准备
(1)支持语言与协议
(2)必备工具与依赖
3. 业务需求梳理
三、实操步骤:从调试到落地(Python 示例)
步骤 1:理解请求流程
步骤 2:签名生成规则(关键!避免调用失败)
签名示例(参数排序与拼接)
步骤 3:完整代码实现(Python)
(1)依赖安装
(2)完整代码(含签名生成、接口调用、工控数据标准化)
import requests
import hashlib
import time
import json
from urllib.parse import urlencode
from typing import Dict, Optional, List
# 接口核心配置(替换为自己的密钥和接口地址)
APP_KEY = "你的appkey"
SECRET = "你的secret"
API_URL = "https://api.gongkong.com/item_get" # 正式接口地址
TEST_ITEM_ID = "工控_1008611" # 测试用商品ID(可从平台详情页提取)
def generate_sign(params: Dict) -> str:
"""生成接口签名(严格按平台规则实现,核心函数)"""
# 1. 按参数名ASCII升序排序(排除sign字段)
sorted_params = sorted(params.items(), key=lambda x: x[0])
# 2. 拼接参数字符串(urlencode自动处理中文、空格等特殊字符)
param_str = urlencode(sorted_params, encoding="utf-8") + f"&secret={SECRET}"
# 3. MD5加密(32位大写)
md5 = hashlib.md5()
md5.update(param_str.encode("utf-8"))
return md5.hexdigest().upper()
def parse_industrial_params(tech_params: List[Dict]) -> Dict:
"""解析工控商品技术参数(标准化字段命名,适配工控场景)"""
# 工控核心参数映射表(可根据业务扩展,覆盖PLC、传感器、变频器等品类)
standard_params = {
"model_full": "", # 型号全称
"brand": "", # 品牌
"rated_voltage": "", # 额定电压
"rated_current": "", # 额定电流
"power": "", # 功率
"communication_protocol": "", # 通信协议
"io_points": "", # I/O点数
"response_time": "", # 响应时间
"detection_range": "", # 检测范围
"protection_level": "", # 防护等级
"operating_temperature": "", # 工作温度
"accuracy_class": "", # 精度等级
"installation_method": "", # 安装方式
"execution_standard": "", # 执行标准
"emc_level": "" # EMC抗干扰等级
}
for param in tech_params:
key = param.get("key", "").lower() # 参数名转小写,统一匹配
value = param.get("value", "").strip()
# 按关键词匹配,标准化字段(覆盖不同品牌/供应商的参数命名差异)
if any(k in key for k in ["型号全称", "完整型号"]):
standard_params["model_full"] = value
elif any(k in key for k in ["品牌", "brand"]):
standard_params["brand"] = value
elif any(k in key for k in ["额定电压", "voltage", "u额定"]):
standard_params["rated_voltage"] = value
elif any(k in key for k in ["额定电流", "current", "i额定"]):
standard_params["rated_current"] = value
elif any(k in key for k in ["功率", "power", "p"]):
standard_params["power"] = value
elif any(k in key for k in ["通信协议", "通讯协议", "protocol"]):
standard_params["communication_protocol"] += value + "|" if value else ""
elif any(k in key for k in ["i/o", "输入输出", "点数"]):
standard_params["io_points"] = value
elif any(k in key for k in ["响应时间", "response"]):
standard_params["response_time"] = value
elif any(k in key for k in ["检测范围", "探测距离"]):
standard_params["detection_range"] = value
elif any(k in key for k in ["防护等级", "ip"]):
standard_params["protection_level"] = value
elif any(k in key for k in ["工作温度", "temperature"]):
standard_params["operating_temperature"] = value
elif any(k in key for k in ["精度等级", "accuracy", "精度"]):
standard_params["accuracy_class"] = value
elif any(k in key for k in ["安装方式", "安装"]):
standard_params["installation_method"] = value
elif any(k in key for k in ["执行标准", "标准", "iec", "gb"]):
standard_params["execution_standard"] = value
elif any(k in key for k in ["emc", "抗干扰", "电磁兼容"]):
standard_params["emc_level"] = value
# 清理多余分隔符
standard_params["communication_protocol"] = standard_params["communication_protocol"].rstrip("|")
return standard_params
def get_item_detail(
item_id: Optional[str] = None,
item_url: Optional[str] = None,
is_authorized: int = 0,
need_compatibility: int = 1,
refresh: int = 0
) -> Dict:
"""
调用item_get接口获取工控商品详情(核心接口调用函数)
:param item_id: 商品ID(优先级高于URL)
:param item_url: 商品详情页URL
:param is_authorized: 是否筛选授权供应商(1=是,0=否)
:param need_compatibility: 是否返回兼容性信息(1=是,0=否)
:param refresh: 是否强制刷新缓存(1=是,0=否,企业版可用)
:return: 标准化后的商品详情字典(含成功状态标识)
"""
# 1. 校验必填参数
if not (item_id or item_url):
return {"success": False, "error_msg": "必须传入item_id或item_url", "error_code": -1}
# 2. 构建基础参数(必填项)
params = {
"appkey": APP_KEY,
"timestamp": int(time.time() * 1000), # 毫秒级时间戳
"is_authorized": is_authorized,
"need_compatibility": need_compatibility,
"refresh": refresh,
# 按需筛选字段,减少数据传输量(工控场景核心字段)
"fields": "base_info,tech_params,compatibility,price,stock,seller,certification,after_sales,technical_doc"
}
# 3. 添加查询标识(二选一)
if item_id:
params["item_id"] = item_id
else:
params["item_url"] = item_url
# 4. 生成签名(必须在所有参数拼接完成后)
params["sign"] = generate_sign(params)
try:
# 5. 发送POST请求(HTTPS协议,设置JSON请求头,超时10秒)
response = requests.post(
url=API_URL,
data=json.dumps(params),
headers={"Content-Type": "application/json"},
timeout=10,
verify=True # 生产环境开启SSL验证,防止数据泄露
)
# 6. 解析响应(JSON格式)
result = response.json()
# 7. 处理响应状态
if result.get("code") == 200:
raw_data = result.get("data", {})
# 标准化返回数据结构(统一字段命名,便于后续处理)
standard_data = {
"success": True,
"item_id": raw_data.get("base_info", {}).get("item_id", item_id),
"base_info": {
"name": raw_data.get("base_info", {}).get("name", ""),
"subtitle": raw_data.get("base_info", {}).get("subtitle", ""),
"main_image": raw_data.get("base_info", {}).get("main_image", ""),
"category": raw_data.get("base_info", {}).get("category", ""),
"tags": raw_data.get("base_info", {}).get("tags", []), # 原厂授权/现货/技术支持
"url": raw_data.get("base_info", {}).get("url", item_url)
},
"tech_params": parse_industrial_params(raw_data.get("tech_params", [])), # 标准化技术参数
"compatibility": {
"compatible_brands": raw_data.get("compatibility", {}).get("brands", []), # 兼容品牌
"compatible_models": raw_data.get("compatibility", {}).get("models", []), # 兼容型号
"adapt_modules": raw_data.get("compatibility", {}).get("modules", []), # 适配模块
"replacement_model": raw_data.get("compatibility", {}).get("replacement", "") # 替换型号
},
"price_info": {
"base_price": raw_data.get("price", {}).get("base_price", 0.0),
"tax_inclusive": raw_data.get("price", {}).get("tax_inclusive", True), # 是否含税
"ladder_prices": raw_data.get("price", {}).get("ladder_prices", []), # 批量阶梯价
"currency": raw_data.get("price", {}).get("currency", "CNY")
},
"stock_info": {
"stock_quantity": raw_data.get("stock", {}).get("quantity", 0),
"stock_status": raw_data.get("stock", {}).get("status", "现货"),
"min_order": raw_data.get("stock", {}).get("min_order", 1), # 最小起订量
"max_supply": raw_data.get("stock", {}).get("max_supply", 999),
"lead_time": raw_data.get("stock", {}).get("lead_time", "") # 备货周期
},
"seller_info": {
"seller_id": raw_data.get("seller", {}).get("seller_id", ""),
"company_name": raw_data.get("seller", {}).get("company_name", ""),
"qualification": raw_data.get("seller", {}).get("qualification", []), # 原厂授权/ISO9001
"is_authorized": raw_data.get("seller", {}).get("is_authorized", False), # 是否授权供应商
"location": raw_data.get("seller", {}).get("location", ""),
"contact_phone": raw_data.get("seller", {}).get("contact_phone", ""),
"tech_support": raw_data.get("seller", {}).get("tech_support", "") # 技术支持方式
},
"certification": {
"ce": raw_data.get("certification", {}).get("ce", ""), # CE认证编号
"ul": raw_data.get("certification", {}).get("ul", ""), # UL认证编号
"ccc": raw_data.get("certification", {}).get("ccc", ""), # CCC认证编号
"rohs": raw_data.get("certification", {}).get("rohs", ""), # ROHS认证
"detection_report": raw_data.get("certification", {}).get("detection_report", "") # 检测报告
},
"after_sales": {
"warranty_period": raw_data.get("after_sales", {}).get("warranty_period", ""), # 质保期
"repair_response": raw_data.get("after_sales", {}).get("repair_response", ""), # 维修响应时间
"spare_part_cycle": raw_data.get("after_sales", {}).get("spare_part_cycle", ""), # 备件周期
"support_method": raw_data.get("after_sales", {}).get("support_method", []) # 支持方式
},
"technical_doc": {
"product_manual": raw_data.get("technical_doc", {}).get("product_manual", ""), # 产品手册
"installation_guide": raw_data.get("technical_doc", {}).get("installation_guide", ""), # 安装指南
"programming_manual": raw_data.get("technical_doc", {}).get("programming_manual", "") # 编程手册
},
"update_time": time.strftime("%Y-%m-%d %H:%M:%S") # 数据更新时间
}
return standard_data
else:
# 接口返回错误(如签名错误、权限不足)
return {
"success": False,
"error_code": result.get("code"),
"error_msg": result.get("msg", "接口调用失败")
}
except requests.exceptions.RequestException as e:
# 网络异常(超时、连接失败、SSL错误等)
return {
"success": False,
"error_code": -2,
"error_msg": f"网络异常:{str(e)}"
}
except Exception as e:
# 其他异常(JSON解析失败、参数处理异常等)
return {
"success": False,
"error_code": -3,
"error_msg": f"处理异常:{str(e)}"
}
# 调用示例(工控商品详情查询,适配项目选型场景)
if __name__ == "__main__":
# 按商品ID查询(推荐,精准高效)
item_detail = get_item_detail(
item_id=TEST_ITEM_ID,
is_authorized=1, # 仅查询授权供应商商品
need_compatibility=1, # 返回兼容性信息
refresh=0 # 非实时需求无需强制刷新
)
# 打印结果(实际场景可存储到数据库/Excel,或对接前端选型系统)
if item_detail["success"]:
print("=" * 80)
print(f"【商品基础信息】")
print(f"商品名称:{item_detail['base_info']['name']}")
print(f"商品标签:{','.join(item_detail['base_info']['tags'])}")
print(f"所属类目:{item_detail['base_info']['category']}")
print(f"详情页URL:{item_detail['base_info']['url']}")
print("-" * 80)
print(f"【核心技术参数】")
for key, value in item_detail["tech_params"].items():
if value:
print(f" {key}:{value}")
print("-" * 80)
print(f"【兼容性信息】")
print(f"兼容品牌:{','.join(item_detail['compatibility']['compatible_brands'])}")
print(f"兼容型号:{','.join(item_detail['compatibility']['compatible_models'])}")
print(f"适配模块:{','.join(item_detail['compatibility']['adapt_modules'])}")
if item_detail['compatibility']['replacement_model']:
print(f"替换型号:{item_detail['compatibility']['replacement_model']}")
print("-" * 80)
print(f"【价格与库存】")
print(f"基础单价:¥{item_detail['price_info']['base_price']}({'含税' if item_detail['price_info']['tax_inclusive'] else '不含税'})")
print(f"批量阶梯价:")
for ladder in item_detail["price_info"]["ladder_prices"]:
print(f" {ladder['min_qty']}-{ladder['max_qty']}台:¥{ladder['price']}/台")
print(f"库存状态:{item_detail['stock_info']['stock_status']} | 库存数量:{item_detail['stock_info']['stock_quantity']}台")
print(f"最小起订量:{item_detail['stock_info']['min_order']}台 | 备货周期:{item_detail['stock_info']['lead_time']}")
print("-" * 80)
print(f"【供应商与认证】")
print(f"企业名称:{item_detail['seller_info']['company_name']}")
print(f"是否授权:{'是' if item_detail['seller_info']['is_authorized'] else '否'}")
print(f"资质认证:{','.join(item_detail['seller_info']['qualification'])}")
print(f"所在地:{item_detail['seller_info']['location']} | 技术支持:{item_detail['seller_info']['tech_support']}")
print(f"联系电话:{item_detail['seller_info']['contact_phone']}")
print(f"认证信息:CE={item_detail['certification']['ce']} | CCC={item_detail['certification']['ccc']} | ROHS={item_detail['certification']['rohs']}")
print("-" * 80)
print(f"【售后与技术文档】")
print(f"质保期:{item_detail['after_sales']['warranty_period']} | 维修响应:{item_detail['after_sales']['repair_response']}")
print(f"支持方式:{','.join(item_detail['after_sales']['support_method'])}")
if item_detail["technical_doc"]["product_manual"]:
print(f"产品手册:{item_detail['technical_doc']['product_manual']}")
if item_detail["technical_doc"]["programming_manual"]:
print(f"编程手册:{item_detail['technical_doc']['programming_manual']}")
print("=" * 80)
else:
print(f"查询失败:{item_detail['error_msg']}(错误码:{item_detail['error_code']})")