前言
目标:串接虾皮商品,目前串接虾皮 OpenAPI 2.0 版本,串接手册
这次要串接商品资料会用到的有
get_item_list 取得商品清单get_item_base_info 取得商品基本资料get_model_list 取得规格资料说明一下串接商品的流程
get_item_list ,可以用来取得虾皮的商品 id,然后再用商品 id 去串接 get_item_base_info,就会得到商品的详细资料,如果商品有其他规格的话就要用商品 id 去串接 get_model_list
规格指的是这区块的资料:
get_item_list 取得商品清单
这个 API 可以取得虾皮的商品 id 跟状态
公共参数
业务参数
以 PHP 为例
// 取得商品清单function getItemLit($host,$partnerId,$partnerKey,$timestamp,$access_token,$shop_id, $parameter){$path='/api/v2/product/get_item_list'; $base_string=strval($partnerId.$path.$timestamp.$access_token.$shop_id);$sign=hash_hmac('sha256',$base_string,$partnerKey,false);$url=$host.$path.'?partner_id='.$partnerId.'×tamp='.$timestamp.'&sign='.$sign.'&access_token='.$access_token.'&shop_id='.$shop_id.$paremeter;$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);$res = curl_exec($ch);return $res;}//取得上架跟下架的商品$parameter='&offset=0&page_size=100&item_status=NORMAL&item_status=UNLIST';getItemLit($host,$partnerId,$partnerKey,$timestamp,$access_token,$shop_id,$parameter);
可以依据状态取得想要的商品 item_id
取得商品的 item_id 后就可以用 item_id 去串接 get_item_base_info、get_model_list 来取得其他商品资讯
小小心得:
我觉得很有趣的是串这个 get_item_list 只会给你 item id 的清单,并不会有所有商品的详细资料,或许是为了让你先筛选想要的商品 id 再去根据需求取得其他资料,可以更弹性也不用一次回传过于庞大的资料。
参考资料:
v2.product.get_item_list