一、什么是商品条码查询接口?
如今,商品条码已成为商品在全球流通中的“唯一身份标识”,是现代供应链体系中不可或缺的基础元素。全球已有超过10亿种商品使用条码技术,每天被扫描次数超过100亿次,其应用覆盖零售、物流、制造、医疗等多个行业。
而商品条码API正是基于这一基础技术,为用户提供快速获取商品信息的能力。用户只需输入13位或14位商品条码,即可获取包括商品名称、品牌、规格、价格、保质期、成分信息等关键数据,广泛服务于消费者、零售商、电商平台、物流企业等多个群体。
二、如何用Java实现商品条码接口调用?
下面我们以阿里云的接口为例,通过Java实现该接口的调用
接口地址:https://market.aliyun.com/apimarket/detail/cmapi00065867
public static void main(String[] args) {
String host = "https://tsbarcode.market.alicloudapi.com";
String path = "/barcode/index";
String method = "GET";
String appcode = "你自己的AppCode";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<String, String>();
querys.put("barcode", "6921830106820");
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
*/
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
System.out.println(response.toString());
//获取response的body
//System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
返回代码示例:
{
"code": 1,
"msg": "操作成功",
"data": {
"barcode": "6921830106820",
"brand": "老厨",
"goods_name": "老厨香辣牛肉干",
"company": "温州老厨食品有限公司",
"keyword": "牛肉干",
"goods_type": "食品、饮料和烟草>>预制食品和罐头>>小吃>>肉干和处理过的肉",
"category_code": "10005767",
"category_name": "预制/加工牛肉",
"image": "http://tanshu-img.oss-cn-hangzhou.aliyuncs.com/barcode/202416/171328157024fb6f.jpg?Expires=1747967789&OSSAccessKeyId=LTAI5tCFqfpS4Mei4vfBxpdn&Signature=nFO3xEFd1LqCkCTnJc%2BZGwFkk1g%3D",
"spec": "52g",
"width": "6.2厘米",
"height": "9.5厘米",
"depth": "2厘米",
"gross_weight": "",
"net_weight": "",
"price": "",
"origin_country": "中国",
"first_ship_date": "",
"packaging_type": "",
"shelf_life": "",
"min_sales_unit": "50(克)",
"certification_standard": "GB 2726",
"certificate_license": "SC11233011000581",
"remark": "checkResult:1;备注:经查,该商品条码已在中国物品编码中心注册;logout_flag:0;login_date:Sep 3 1997 12:00:00:000AM;valid_date:Sep 3 2023 12:00:00:000AM;宽:6.2;单位:CM;高:9.5;深:2;关键字:老厨牌 牛肉干;上市时间:2014-01-01;英文名称:xianglaniurougan;产地:杭州;gpc2020:10005767;"
}
}