开发分享:JD平台满足多语言开发+高并发的API接口接入实例

-
参数说明
- 通用参数说明
- url说明 https://api-gw.onebound.cn/平台/API类型/ 平台:淘宝,京东等, API类型:[item_search,item_get,item_search_shop等]
- version:API版本
- key:调用key,测试key:test_api_key
- secret:调用secret,测试secret:(不用填写)
- cache:[yes,no]默认yes,将调用缓存的数据,速度比较快
- result_type:[json,xml,serialize,var_export]返回数据格式,默认为json
- lang:[cn,en,ru] 翻译语言,默认cn简体中文
- secret:密钥
-
API:item_search 参数说明:
- q:搜索关键字
- cat:分类ID
- start_price:开始价格
- end_price:结束价格
- sort:排序[bid,bid,bid2,_bid2,_sale,_credit]
(bid:总价,bid2:商品价格,sale:销量,credit信用,加前缀为从大到小排序) - page:页数
- page_size:每页宝贝数量,默认40
- seller_info:是否获取商家信息[yes,no],默认yes
-
API:item_get 参数说明: num_iid:宝贝ID
- 通用参数说明
-
此API目前支持以下基本接口:
- item_get 获得JD商品详情
- item_search 按关键字搜索商品
- item_search_img 按图搜索京东商品(拍立淘)
- item_search_shop 获得店铺的所有商品
- item_history_price 获取商品历史价格信息
- item_recommend 获取推荐商品列表
- buyer_order_list 获取购买到的商品订单列表
- buyer_order_datail 获取购买到的商品订单详情
- upload_img 上传图片到JD
- item_review 获得JD商品评论
- cat_get 获得jd商品分类
接口KEY及详细说明请参考测试界面参数
请求参数:num_iid=10335871600
参数说明:num_iid:JD商品ID
响应参数
| 名称 | 类型 | 是否隐私 | 示例值 | 描述 |
|---|---|---|---|---|
| items | items[] | 获得JD商品详情 | ||
| num_iid | Bigint | 29186819959 | 商品ID | |
| title | String | MOCO2018夏季新品时尚V领条纹连衣裙 摩安珂 蓝白条色 S | 商品标题 | |
| desc_short | String | 商品简介 | ||
| price | Float | 719.0 | 价格 | |
| total_price | Float | 0 | ||
| suggestive_price | Float | 0 | ||
| orginal_price | Float | 1199.00 | 原价 | |
| nick | String | MO&Co.官方旗舰店 | 掌柜昵称 | |
| num | Int | 999 | ||
| min_num | Int | 0 | ||
| detail_url | String | http://item.jd.com/29186819959.html | 商品链接 | |
| pic_url | String | //img14.360buyimg.com/n0/jfs/t22033/147/1051007175/85125/c44dd0df/5b1f2855Ncbe35858.jpg | 商品图片 | |
| brand | String | 品牌名称 | ||
| brandId | Int | 品牌ID | ||
| rootCatId | Int | 1343 | 顶级分类ID | |
| cid | Int | 9719 | ||
| crumbs | Mix | [] | ||
| created_time | String | |||
| modified_time | String | |||
| delist_time | String | |||
| desc | String | |||
| desc_img | Mix | [] | ||
| item_imgs | Mix | [{ "url": "//img14.360buyimg.com/n0/jfs/t22033/147/1051007175/85125/c44dd0df/5b1f2855Ncbe35858.jpg"}] | 商品图片 | |
| item_weight | String | |||
| item_size | String | |||
| location | String | 发货地 | ||
| post_fee | Float | 6.00 | 物流费用 | |
| express_fee | Float | 6.00 | 快递费用 | |
| ems_fee | Float | 6.00 | EMS费用 | |
| shipping_to | String | 发货至 | ||
| has_discount | Boolean | false | ||
| video | Mix | [] | 商品视频 | |
| is_virtual | String | |||
| sample_id | String | 商品风格标识ID | ||
| is_promotion | Boolean | |||
| props_name | String | 0:0:尺码:S;0:1:尺码:XS;0:2:尺码:M;0:3:尺码:L;0:4:尺码:XL | 商品属性名 | |
| prop_imgs | Mix | {"prop_img": []} | 商品属性图片列表 | |
| property_alias | String | 0:0:S;0:1:XS;0:2:M;0:3:L;0:4:XL | 商品属性别名 | |
| props | Mix | [{ "name": "尺码","value": "S XS M L XL" }] | 商品详情 | |
| total_sold | Int | |||
| skus | Mix | {"sku": [{"price": "719.00", "orginal_price": "1199.00", "properties": "0:0", "properties_name": "0:0:尺码:S", "quantity": 99, "sku_id": 29186819959, "sku_url": "http://item.jd.com/29186819959.html"}] | 商品规格信息 | |
| seller_id | Int | 卖家ID | ||
| sales | Int | 销量 | ||
| shop_id | Int | 店铺ID | ||
| props_list | Mix | {"0:0": "尺码:S"} | 商品属性 | |
| seller_info | Mix | {"level": null, "shop_type": null, "user_num_id": 57467, "cid": null, "delivery_score": null, "item_score": null, "score_p": null, "zhuy": "//moco.jd.com", "search_id": "", "nick": "MO&Co.官方旗舰店", "shop_name": "MO&Co.官方旗舰店", "title": "MO&Co.官方旗舰店" } | 卖家信息 | |
| tmall | Boolean | false | 是否天猫 | |
| error | String | 错误信息 | ||
| warning | String | 警告信息 | ||
| url_log | Mix | [] | ||
| props_img | Mix | [] | 属性图片 | |
| shop_item | Mix | [] | ||
| relate_items | Mix | [] |
-- 请求示例 url 默认请求参数已经URL编码处理 curl -i "https://api-gw.onebound.cn/jd/item_get/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=10335871600"
<?php// 请求示例 url 默认请求参数已经URL编码处理
// 本示例代码未加密secret参数明文传输,若要加密请参考:https://api.onebound.cn/taobao/demo/sdk2020/demo-sign.php
$method = "GET";
$url = "https://api-gw.onebound.cn/jd/item_get/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=10335871600";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
var_dump(curl_exec($curl));
?>
<?php
//定义缓存目录和引入文件
define("DIR_RUNTIME","runtime/");
define("DIR_ERROR","runtime/");
define("SECACHE_SIZE","0");
//SDK下载地址 http://api-gw.onebound.cn/taobao/demo/sdk2020/onebound-api-sdk.zip
include ("ObApiClient.php");$obapi = new otao\\ObApiClient();
$obapi->api_url = "http://api-gw.onebound.cn/";
$obapi->api_urls = array("http://api-gw.onebound.cn/","http://api-1.onebound.cn/");//备用API服务器
$obapi->api_urls_on = true;//当网络错误时,是否启用备用API服务器
$obapi->api_key = "<您自己的apiKey>";
$obapi->api_secret = "<您自己的apiSecret>";
$obapi->api_version ="";
$obapi->secache_path ="runtime/";
$obapi->secache_time ="86400";
$obapi->cache = true;$api_data = $obapi->exec(array("api_type" =>"jd","api_name" =>"item_get","api_params"=>array ('num_iid' => '10335871600',
)));var_dump($api_data);
?>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.PrintWriter;
import java.net.URLConnection;public class Example {private static String readAll(Reader rd) throws IOException {StringBuilder sb = new StringBuilder();int cp;while ((cp = rd.read()) != -1) {sb.append((char) cp);}return sb.toString();}public static JSONObject postRequestFromUrl(String url, String body) throws IOException, JSONException {URL realUrl = new URL(url);URLConnection conn = realUrl.openConnection();conn.setDoOutput(true);conn.setDoInput(true);PrintWriter out = new PrintWriter(conn.getOutputStream());out.print(body);out.flush();InputStream instream = conn.getInputStream();try {BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));String jsonText = readAll(rd);JSONObject json = new JSONObject(jsonText);return json;} finally {instream.close();}}public static JSONObject getRequestFromUrl(String url) throws IOException, JSONException {URL realUrl = new URL(url);URLConnection conn = realUrl.openConnection();InputStream instream = conn.getInputStream();try {BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));String jsonText = readAll(rd);JSONObject json = new JSONObject(jsonText);return json;} finally {instream.close();}}public static void main(String[] args) throws IOException, JSONException {// 请求示例 url 默认请求参数已经URL编码处理String url = "https://api-gw.onebound.cn/jd/item_get/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=10335871600";JSONObject json = getRequestFromUrl(url);System.out.println(json.toString());}}


