接口简介
VVIC图片搜索接口提供基于商品图片的智能检索能力,开发者可通过上传图片或图片URL,获取平台内相似商品的结果列表。本接口支持HTTP RESTful调用,返回JSON格式数据。
快速接入指南
准备工作
前往VVIC开放平台注册开发者账号
创建应用并获取API Key和Secret
开通「图片搜索」接口权限
接口参数说明
请求示例
python
Copy Code
import requests
url = "api.vvic.com/search/imag…"
headers = { "Authorization": "Bearer your_api_key", "Content-Type": "application/json" }
payload = { "image_url": "example.com/sample.jpg", # 图片网络地址 "max_results": 10, # 最大返回结果数 "threshold": 0.7, # 相似度阈值 "sort_by": "price_asc" # 排序方式 }
response = requests.post(url, headers=headers, json=payload)
请求参数 参数名 类型 必填 说明 image_url string 是 需要搜索的图片网络地址 image_file file 否 图片二进制文件(二选一) max_results int 否 返回结果数量(默认5) threshold float 否 相似度过滤阈值(0-1) 响应示例 成功响应 json Copy Code { "code": 200, "data": { "results": [ { "product_id": "123456", "title": "2023新款女士手提包", "price": 299.00, "similarity": 0.92, "image_url": "img.vvic.com/item/123456…", "detail_url": "www.vvic.com/item/123456" }, // ...更多结果 ] } }
错误代码 python Copy Code if response.status_code == 200: data = response.json() if data['code'] == 200: print("搜索成功!") for item in data['data']['results']: print(f"商品ID:{item['product_id']}") print(f"标题:{item['title']}") print(f"价格:{item['price']}") else: print(f"接口错误:{data['msg']}") else: print(f"请求失败,状态码:{response.status_code}")
本地图片上传示例 python Copy Code import requests from requests_toolbelt.multipart.encoder import MultipartEncoder
api_key = "your_api_key_here" file_path = "/path/to/your/image.jpg"
with open(file_path, 'rb') as f: m = MultipartEncoder( fields={ 'image_file': ('search_image.jpg', f, 'image/jpeg'), 'max_results': '5' } )
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': m.content_type
}
response = requests.post(
"https://api.vvic.com/search/image",
headers=headers,
data=m
)
注意事项 图片格式支持:JPG/PNG/WebP 单文件大小限制:≤5MB 免费版QPS限制:5次/秒 推荐图片尺寸:800x800像素以上 异步处理需添加callback_url参数
建议先通过VVIC官方提供的API调试工具进行接口测试,确保参数配置正确后再接入生产环境。