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

前言

目标:串接虾皮商品,目前串接虾皮 OpenAPI 2.0 版本,串接手册
这次要串接商品资料会用到的有

get_item_list 取得商品清单get_item_base_info 取得商品基本资料get_model_list 取得规格资料
上一篇 已经用 get_item_list 取得商品的 item_id,这一篇要来串接 get_item_base_info & get_model_list

get_item_base_info

这个 API 可以取得虾皮的商品的基本资讯

格式HTTP/JSONURL• 正式区:https://partner.shopeemobile.com/api/v2/product/get_item_base_info• 测试区:https://partner.test-stable.shopeemobile.com/api/v2/product/get_item_base_info请求方式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(可参授权商店那一篇)

业务参数

参数类型说明item_id_listint[]item_id,可以带入多组,多组的话[1234567,1234568] 这样带入need_tax_infoboolean预设 false,true 的话会回应 tax_info 的资料need_complaint_policyboolean预设 false,true 的话会回应 need_complaint_policy 的资料

以 PHP 为例

// 取得商品清单function getItemBaseInfo($host,$partnerId,$partnerKey,$timestamp,$access_token,$shop_id,  $parameter){$path='/api/v2/product/get_item_base_info'; $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='&item_id_list=[1234567,1234568]';getItemBaseInfo($host,$partnerId,$partnerKey,$timestamp,$access_token,$shop_id,$parameter);

你会取得所有商品清单的资讯,但最多好像只能 50 笔
有一个状况很特别,如果这个商品有设定其他规格(尺寸、大小),那么 price_info、stock_info 就不会有资料,而是要再去串接 get_model_list 才可以取的每个规格对应的 price_info、stock_info


get_model_list

这个 API 可以取得虾皮商品的规格资料

格式HTTP/JSONURL• 正式区:https://partner.shopeemobile.com/api/v2/product/get_model_list• 测试区:https://partner.test-stable.shopeemobile.com/api/v2/product/get_model_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(可参授权商店那一篇)

业务参数

参数类型说明item_idint一次带入一组 item_id

以 PHP 为例

// 取得商品清单function getModelList($host,$partnerId,$partnerKey,$timestamp,$access_token,$shop_id,  $parameter){$path='/api/v2/product/get_model_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='&item_id=1234567';getItemBaseInfo($host,$partnerId,$partnerKey,$timestamp,$access_token,$shop_id,$parameter);

在 get_item_base_info 没有取得 price_info、stock_info 的话就可以从这边取得
有一点很特别,option_list 是规格清单,model 的 tier_index 是 option 对应的 index,要用这个 index 才可以取得对应的规格名称

小小心得

一开始串接订单的时候一直不明白为甚么有 model 这个栏位,后来才发现是跟商品有关
然后规格如果被删掉了,不会有跟 item_status 一样有 DELETE 的状态,删掉就只是 option_list 少掉这个规格而已


关于作者: 网站小编

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

热门文章