京东商品详情 API 完整调用实例

发布时间:2026/7/2 5:58:47
京东商品详情 API 完整调用实例 Java 完整调用示例HttpClient依赖 Mavenxml!-- httpclient -- dependency groupIdorg.apache.httpcomponents/groupId artifactIdhttpclient/artifactId version4.5.14/version /dependency !-- commons-codec MD5 -- dependency groupIdcommons-codec/groupId artifactIdcommons-codec/artifactId version1.15/version /dependency核心代码java运行import org.apache.commons.codec.digest.DigestUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.util.*; public class JdGoodsDetailApi { // 替换为自己的密钥 private static final String APP_KEY 你的appKey; private static final String APP_SECRET 你的appSecret; private static final String API_URL https://api.jd.com/routerjson; // 商品详情接口方法 private static final String METHOD jd.union.open.goods.jingfen.query; public static void main(String[] args) throws Exception { // 1.业务入参skuId为京东商品SKU编号 MapString, Object bizParam new HashMap(); bizParam.put(skuId, 100012345678); // 目标商品SKU bizParam.put(goodsType, 0); // 2.组装全部参数 MapString, String allParams new TreeMap(); allParams.put(app_key, APP_KEY); allParams.put(timestamp, new Date().toLocaleString()); allParams.put(v, 1.0); allParams.put(method, METHOD); allParams.put(format, json); // 业务参数转JSON字符串 allParams.put(param_json, new com.alibaba.fastjson.JSONObject(bizParam).toString()); // 3.生成MD5签名 String sign getSign(allParams); allParams.put(sign, sign); // 4.POST请求 String result doPost(allParams); System.out.println(接口返回结果 result); } // 生成签名 private static String getSign(MapString, String params) { StringBuilder sb new StringBuilder(APP_SECRET); for (Map.EntryString, String entry : params.entrySet()) { sb.append(entry.getKey()).append(entry.getValue()); } sb.append(APP_SECRET); return DigestUtils.md5Hex(sb.toString()).toUpperCase(); } // 发送Post请求 private static String doPost(MapString, String params) throws Exception { CloseableHttpClient httpClient HttpClients.createDefault(); HttpPost httpPost new HttpPost(API_URL); httpPost.setEntity(new StringEntity(new com.alibaba.fastjson.JSONObject(params).toString(), ContentType.APPLICATION_JSON)); CloseableHttpResponse response httpClient.execute(httpPost); String resp EntityUtils.toString(response.getEntity(), UTF-8); response.close(); httpClient.close(); return resp; } }三、PHP 调用实例php运行?php $appKey 你的appKey; $appSecret 你的appSecret; $method jd.union.open.goods.jingfen.query; $url https://api.jd.com/routerjson; // 业务参数 $bizData [ skuId 100012345678, goodsType 0 ]; $paramJson json_encode($bizData); // 公共参数 $params [ app_key $appKey, timestamp date(Y-m-d H:i:s), v 1.0, method $method, format json, param_json $paramJson ]; // 字典排序 ksort($params); $str $appSecret; foreach ($params as $k $v) { $str . $k . $v; } $str . $appSecret; $sign strtoupper(md5($str)); $params[sign] $sign; // curl请求 $ch curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); curl_setopt($ch, CURLOPT_HTTPHEADER, [Content-Type: application/json]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $res curl_exec($ch); curl_close($ch); echo $res; ?四、返回核心字段说明联盟详情接口成功返回 JSON 核心节点jingfenGoodsInfo商品主体信息skuId商品 IDskuName商品标题price售价、originPrice原价mainImage主图地址galleryImages图集brandName品牌category类目couponInfo优惠券信息面额、门槛、链接commissionInfo佣金比例联盟推广佣金