一、什么是商品條碼查詢接口?
1974年6月26日,美國俄亥俄州的一家超市首次使用商品條碼完成結算,標志著商品條碼正式進入商業應用領域。這項技術通過自動識別和數據采集,極大提升了零售行業的作業效率,減少了人工錄入錯誤,提高了庫存管理水平。
如今,商品條碼已成為商品在全球流通中的“唯一身份標識”,而商品條碼查詢接口正是基于這一基礎技術,為用戶提供快速獲取商品信息的能力。用戶只需輸入13位或14位商品條碼,即可獲取包括商品名稱、品牌、規格、價格、保質期、成分信息等關鍵數據,廣泛服務于消費者、零售商、電商平臺、物流企業等多個群體。
二、商品條形碼查詢接口如何用C#進行調用?
下面我們以阿里云的接口為例,具體代碼示例如下:
接口地址:https://market.aliyun.com/apimarket/detail/cmapi00065867
//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;private const String host = "https://tsbarcode.market.alicloudapi.com";private const String path = "/barcode/index";private const String method = "GET";private const String appcode = "你自己的AppCode";static void Main(string[] args){String querys = "barcode=6921830106820";String bodys = "";String url = host + path;HttpWebRequest httpRequest = null;HttpWebResponse httpResponse = null;if (0 < querys.Length){url = url + "?" + querys;}if (host.Contains("https://")){ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));}else{httpRequest = (HttpWebRequest)WebRequest.Create(url);}httpRequest.Method = method;httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);if (0 < bodys.Length){byte[] data = Encoding.UTF8.GetBytes(bodys);using (Stream stream = httpRequest.GetRequestStream()){stream.Write(data, 0, data.Length);}}try{httpResponse = (HttpWebResponse)httpRequest.GetResponse();}catch (WebException ex){httpResponse = (HttpWebResponse)ex.Response;}Console.WriteLine(httpResponse.StatusCode);Console.WriteLine(httpResponse.Method);Console.WriteLine(httpResponse.Headers);Stream st = httpResponse.GetResponseStream();StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));Console.WriteLine(reader.ReadToEnd());Console.WriteLine("\n");}public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors){return true;}
返回代碼如下:
{"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=1748410862&OSSAccessKeyId=LTAI5tCFqfpS4Mei4vfBxpdn&Signature=Yn70h%2FoTA9gpUu%2F1rEJ0xt4SRXU%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;"}
}