虾皮商品实作串接笔记-串接 API 虾皮商品 (1)

前言

目标:串接虾皮商品,目前串接虾皮 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

规格指的是这区块的资料:
http://img2.58codes.com/2024/20136310okPhCVWakb.png

get_item_list 取得商品清单

这个 API 可以取得虾皮的商品 id 跟状态

格式HTTP/JSONURL• 正式区:https://partner.shopeemobile.com/api/v2/product/get_item_list• 测试区:https://partner.test-stable.shopeemobile.com/api/v2/product/get_item_list请求方式GET

公共参数

参数类型说明signstringaccess_token、partner_id、api path、shop_id、timestamp HMAC-SHA256 编码,并用 partner key 当作加密 Key (可参授权商店那一篇)partner_idintCreate App 产生的 partner_id (可参Create App 那一篇)timestampint时间戳,期限 5 minaccess_tokenstring期限 4 小时(可参取得 access token 那一篇)shop_idint商店 ID(可参授权商店那一篇)

业务参数

参数类型说明offsetint预设 0,如果资料有超过 1 页,就填写,就可以取到下页的资料page_sizeint一页的资料数,最大 100update_time_fromtimestamp更新时间item_statusstring[]商品状态 有 NORMAL/BANNED/DELETED/UNLIST

以 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.'&timestamp='.$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


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章