兑换系统开放接口


接口规则介绍

<p>[TOC]</p> <h2>基本规则</h2> <ul> <li> <p>采用HTTP/HTTPS传输协议,仅允许POST方式进行API请求,并采用RESTFUL风格的服务访问方式</p> </li> <li>使用 <strong>JSON</strong> 作为消息体的数据交换格式。请求须设置HTTP头部:</li> </ul> <pre><code>Content-Type: application/json; charset=utf-8 Accept: application/json</code></pre> <ul> <li>请求参数、鉴权请求头及响应参数的属性名都对大小写敏感</li> </ul> <h2>接口校验</h2> <ul> <li>所有请求需携带鉴权用的HTTP头部信息,包括:</li> </ul> <table> <thead> <tr> <th>Header</th> <th>Type</th> <th>Description</th> <th>Required</th> </tr> </thead> <tbody> <tr> <td>businessId</td> <td>string</td> <td>业务ID,由平台提供</td> <td>true</td> </tr> <tr> <td>nonce</td> <td>string</td> <td>随机字符串,需保证每次请求不同</td> <td>true</td> </tr> <tr> <td>timestamp</td> <td>string</td> <td>时间戳,毫秒值</td> <td>true</td> </tr> <tr> <td>sign</td> <td>string</td> <td>签名值</td> <td>true</td> </tr> <tr> <td>signType</td> <td>string</td> <td>签名方式:SHA256-RSA、MD5。默认:SHA256-RSA</td> <td>false</td> </tr> </tbody> </table> <h2>错误码和错误提示</h2> <p>当请求处理失败时,API将在消息体返回错误相应说明具体的错误原因。</p> <ul> <li><code>status</code>:状态码,参考<em>接口响应状态</em></li> <li><code>message</code>:错误描述,使用易理解的文字表示错误的原因。</li> <li><code>data</code>:数据对象</li> </ul> <pre><code>{ "status": 2, "message": "验签失败", "data": { "merchantId": "19", "businessId": "19", "creditLine": 381, "amount": 164 } }</code></pre> <h2>时间参数及返参</h2> <p>平台开放接口中的日期类字段,都是以时间戳形式接收或返回的</p> <h2>签名</h2> <blockquote> <p>API通过验证签名来保证请求的真实性和数据的完整性。</p> </blockquote> <h3>请求签名</h3> <p>商户需要使用自身的私钥对(<code>SHA-256 with RSA方式</code>)或者密钥(<code>MD5方式</code>)鉴权头部信息、消息体等关键数据的组合进行签名。请求的签名信息通过HTTP头<code>sign</code> 传递,具体说明请见 签名生成指南。没有携带签名或者签名验证不通过的请求,都不会被执行。</p> <h3>回调通知签名</h3> <p>当调用商户的接口时,平台会对回调请求进行签名。签名的方法同请求签名的方式一致,商户<code>必须</code>验证回调的签名.</p> <blockquote> <p><code>SHA-256 with RSA方式</code> 使用平台公钥进行验签,由本平台方提供。</p> <p><code>MD5方式</code> 使用密钥进行验签,由本平台方提供。</p> </blockquote> <h2>密钥</h2> <blockquote> <p><code>SHA-256 with RSA方式</code> 采用RSA非对称加密算法,生成密钥位数:2048位</p> <p><code>MD5方式</code> 由本平台方提供。</p> </blockquote> <h3>商家密钥</h3> <h4>SHA-256 with RSA方式</h4> <ul> <li>商家开户时需要生成秘钥对,私钥商家妥善保存,公钥告知平台方。商家调用平台接口时需使用商家私钥签名,平台会用商家公钥进行验签。</li> </ul> <p>密钥生成方式:</p> <pre><code class="language-java"> /** * 随机生成密钥对 并打印 */ @Test public void genRsaKey() { try { // 获取指定算法的密钥对生成器 KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); // 初始化密钥对生成器(指定密钥长度, 使用默认的安全随机数源) gen.initialize(2048); // 随机生成一对密钥(包含公钥和私钥) KeyPair keyPair = gen.generateKeyPair(); log.info("公钥:{}", getKeString(keyPair.getPublic())); log.info("私钥:{}", getKeString(keyPair.getPrivate())); } catch (Exception e) { e.printStackTrace(); } } /** * 将公/私钥转为字符串方便保存 * @param key * @return */ public static String getKeString(Key key) { byte[] encoded = key.getEncoded(); return Base64.getEncoder().encodeToString(encoded); }</code></pre> <blockquote> <p>平台秘钥</p> </blockquote> <p>商家开户后,平台会提供平台公钥;</p> <h4>MD5方式</h4> <p>商家调用平台接口时需使用<code>MD5密钥</code>进行签名,平台会用<code>MD5密钥</code>进行验签。密钥由本平台提供。</p>

页面列表

ITEM_HTML