京东商品推送
<p>[TOC]</p>
<h3>接入说明</h3>
<p>接入商先调用商品请求接口
商品生成之后,聚美智数通过接入商提供的接收接口,将商品信息推送给接入商</p>
<h3>请求说明</h3>
<h4>请求地址</h4>
<p><code>https://api.jumdata.com/jd/goods/request</code></p>
<h4>请求方式</h4>
<ul>
<li>POST</li>
</ul>
<h4>请求格式</h4>
<ul>
<li>x-www-form-urlencoded</li>
</ul>
<h4>请求参数</h4>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>appId</td>
<td>String</td>
<td>是</td>
<td>服务商分配的唯一标识</td>
</tr>
<tr>
<td>timestamp</td>
<td>Long</td>
<td>是</td>
<td>当前时间的毫秒数</td>
</tr>
<tr>
<td>sign</td>
<td>String</td>
<td>是</td>
<td>签名,详见:签名算法说明</td>
</tr>
<tr>
<td>goodsId</td>
<td>String</td>
<td>是</td>
<td>商品ID</td>
</tr>
<tr>
<td>notifyUrl</td>
<td>String</td>
<td>是</td>
<td>接入商接收商品信息接口的地址,商品生成之后,聚美智数通过该地址,将商品信息推送给接入商,详见:推送说明</td>
</tr>
</tbody>
</table>
<h4>签名算法说明</h4>
<pre><code>sign = sha256( appId + appSecret + timestamp)</code></pre>
<p>用服务商分配的 appId、服务商分配的 appSecret,当前时间毫秒数 timestamp,按上述顺序拼接成字符串,再进行 sha256 哈希得到。如下:</p>
<pre><code class="language-java">String appId = &quot;xyzxy2121zxyz&quot;;
String timestamp = &quot;1555378976238&quot;;
String appSecret = &quot;efcefcef1121cefcefc1212121&quot;;
String str = appId + appSecret + timestamp;
String sign = sha256(str);</code></pre>
<h3>返回说明</h3>
<h4>正确返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200,
&quot;msg&quot;: &quot;成功&quot;,
&quot;taskNo&quot;: &quot;43910772161680797793&quot;,
&quot;charge&quot;: true
}
</code></pre>
<h4>错误返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 400,
&quot;msg&quot;: &quot;商品id不能为空&quot;,
&quot;charge&quot;: false
}</code></pre>
<h4>返回字段说明</h4>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见:code返回码说明</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</td>
</tr>
<tr>
<td>charge</td>
<td>计费标志</td>
</tr>
<tr>
<td>taskNo</td>
<td>请求号,推送的时候与商品信息一并推送,详见:推送说明</td>
</tr>
</tbody>
</table>
<h4>code返回码说明</h4>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>成功(计费)</td>
</tr>
<tr>
<td>400</td>
<td>参数错误</td>
</tr>
<tr>
<td>404</td>
<td>接口地址不正确</td>
</tr>
<tr>
<td>500</td>
<td>系统维护,请稍候再试</td>
</tr>
<tr>
<td>601</td>
<td>接口未开通</td>
</tr>
<tr>
<td>602</td>
<td>账号停用</td>
</tr>
<tr>
<td>603</td>
<td>余额不足请充值</td>
</tr>
<tr>
<td>604</td>
<td>接口停用</td>
</tr>
<tr>
<td>606</td>
<td>调用超限,请稍候再试</td>
</tr>
<tr>
<td>609</td>
<td>请求过于频繁,请稍候再试</td>
</tr>
<tr>
<td>610</td>
<td>请求超时</td>
</tr>
<tr>
<td>999</td>
<td>其他,以实际返回为准</td>
</tr>
</tbody>
</table>
<h3>推送说明</h3>
<p>商品信息生成之后,聚美智数将商品信息推送至接入商提供地址为notifyUrl的接口</p>
<h4>数据格式</h4>
<p>成功查询到商品信息,推送格式如下:</p>
<pre><code class="language-json">{
&quot;taskNo&quot;: &quot;21009868671598003433&quot;, // 请求号,和调用请求接口时返回的taskNo一致
&quot;goodsId&quot;: &quot;11931112321&quot;, //商品id
&quot;data&quot;: { // 详见商品详细信息
...
}
}</code></pre>
<p><a href="https://file.jumdata.com/support/jd/jd-goods.json">商品详细信息</a></p>
<p>如果从请求时间开始,超过<strong>10小时</strong>未推送,则认为推送失败,聚美智数将停止推送商品信息,只推送停止标识,格式如下:</p>
<pre><code class="language-json">{
&quot;taskNo&quot;: &quot;1009868671598003433&quot;,
&quot;goodsId&quot;: &quot;11931112321&quot;,
&quot;status&quot;: &quot;stop&quot;
}
</code></pre>
<p>> 停止推送的同时,会退回本次请求的扣费</p>
<h4>请求格式</h4>
<ul>
<li>application/json</li>
</ul>
<h4>签名验证</h4>
<p>为了防止推动过程中数据被篡改,聚美智数将推送数据进行签名,将签名和数据一并推送,具体步骤如下:</p>
<p>1、在推送数据前拼接appSecret,对拼接后的数据做SHA256哈希,得到sign</p>
<pre><code class="language-java">sign = sha256(appSecret + 推送数据)</code></pre>
<p>例如:
appSecret:312aadadas3123ddadas
推送数据: {"goodsId":"111111","taskNo":"21009868671598003433","data":{}}
则拼接后数据为:312aadadas3123ddadas {"goodsId":"111111","taskNo":"21009868671598003433","data":{}}
再将拼接后的数据进行SHA256哈希,得到sign:trtret31212aa2312312dadas3123ddadas</p>
<p>2、sign放置在请求header中推送至接入商,header name=sign
3、接入商接收到推送数据后,根据步骤1生成sign,与header中的sign进行比较是否一致,一致说明数据没有被篡改</p>
<h4>返回接收结果</h4>
<ul>
<li>接入商需要返回接收处理结果返回给聚美智数</li>
<li>如果是接收失败,聚美智能会再次推送,最多推送20次。推送失败20次,推送自动关闭,不在推送。</li>
</ul>
<pre><code class="language-json">//接收成功
{
&quot;success&quot;:true
}
// 接收失败
{
&quot;success&quot;:false,
&quot;msg&quot;: &quot;接收失败&quot;
} </code></pre>
<h4>接收示例(java)</h4>
<pre><code class="language-java">@PostMapping(&quot;callbackUrl&quot;)
public Map&lt;String,Object&gt; receive(@RequestBody String data, HttpServletRequest request) {
log.info(&quot;接收到商品推送数据: {}&quot;, data);
String signInHeader = request.getHeader(&quot;sign&quot;);
String signText = appSecret + data;
String sign = DigestUtils.sha256Hex(signText);
log.info(&quot;sign: {}&quot;, sign);
log.info(&quot;signInHeader: {}&quot;, signInHeader);
Map&lt;String,Object&gt; map = new HashMap&lt;&gt;();
if (StringUtils.equals(sign, signInHeader)) {
... // 处理自己的业务逻辑
if (处理成功) {
map.put(&quot;success&quot;,true);
} else {
map.put(&quot;success&quot;,false);
map.put(&quot;msg&quot;,&quot;接收失败, xxx&quot;);
}
} else {
map.put(&quot;success&quot;,false);
map.put(&quot;msg&quot;,&quot;接收失败,签名不正确&quot;);
}
return map;
}</code></pre>