一、京东优惠券信息API接口参数说明: 1.通过京东商品ID获取京东优惠券信息接口,获取数据包括:PID信息,优惠券信息,优惠券有效期,店铺昵称,店铺名字等页面上面有的数据均可以拿到. 点击获取测试key和secret 2.请求参数: 请求参数:q=&num_iid=10335871600 参数说明:q: num_iid:商品ID 3.响应参数: 名称 类型 示例值 描述 item item[] 优惠券查询 num_iid Bigint 634250549720 宝贝ID detail_url String https://item.jd.com/10335871600.html#crumb-wrap 宝贝url data_from String app item item[] 优惠券详情数据 title String 每200减15 优惠条件 pic_url String https://gw.alicdn.com/tfs/TB19Nsthbr1gK0jSZR0XXbP8XXa-498-90.png 图片url price Float 15 优惠额度 price_currency String ¥ 优惠币种 user_time String 距到期仅剩2天 优惠时间 二、请求示例:(CURL、PHP 、PHPsdk 、Java 、C# 、Python)
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 {
String url = "https://注册账号获取/jd/item_search_coupon/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&q=&num_iid=10335871600=";
JSONObject json = getRequestFromUrl(url);
System.out.println(json.toString());
}
}
响应参数:
{
"num_iid": "10335871600",
"detail_url": "https://item.jd.com/10335871600.html#crumb-wrap",
"data_from": "app",
"item": [
{
"title": "每200减15",
"pic_url": "https://gw.alicdn.com/tfs/TB19Nsthbr1gK0jSZR0XXbP8XXa-498-90.png",
"price": "15",
"price_currency": "¥",
"user_time": "距到期仅剩2天"
},
{
"title": "满40使用",
"pic_url": "https://gw.alicdn.com/tfs/TB19Nsthbr1gK0jSZR0XXbP8XXa-498-90.png",
"price": "3",
"price_currency": "¥",
"user_time": "有效期至2021.06.30 23:59"
}
],
"error": "",
"reason": "",
"error_code": "0000",
"cache": 0,
"api_info": "today:124 max:10000",
"execution_time": 0.745,
"server_time": "Beijing/2021-05-12 16:43:15",
"client_ip": "106.60.38.2133",
"call_args": [],
"api_type": "taobao",
"translate_language": "zh-CN",
"translate_engine": "google_cn",
"server_memory": "7.38MB",
"request_id": "2.609b9522d7041"
}
API 工具 API SDK调用示例 APISDK下载 API测试工具
如何开通API测试,点击立即开通
|