MoonRecharge-说明
<p>一.请求方式</p>
<p>所有的接口统一使用post方式</p>
<p>二.报文格式</p>
<p>所有的接口请求与返回均为application/json</p>
<p>三.DES加密参数
(1)所有加密都需要privateKey(代理商私钥),如果没有,请联系平台工作人员进行配置。</p>
<p>(2)平台对ip进行白名单限定,下游需要提供相应ip给平台工作人员进行授权,否则将无法调用平台API</p>
<p>(3)平台加密方式为DES加密:
偏移变量,固定占8位字节:12345678
密钥算法:DES
加密-工作模式-填充模式:DES/CBC/PKCS5Padding
默认编码:utf-8
使用privateKey(代理商私钥)作为加密密码,,把参数转换为json作为加密字符串
参考链接:<code>https://blog.csdn.net/Luck_ZZ/article/details/104805562</code></p>
<p>拼接规则见每个api的参数描述</p>
<p>java例子:</p>
<pre><code class="language-java">public static void main(String[] args) {
for (int i = 0; i &lt; 1; i++){
Gson gson = new Gson();
String json = &quot;{\n&quot; +
&quot; \&quot;serialNumber\&quot;:&quot;+System.currentTimeMillis()+&quot;,\n&quot; +
&quot; \&quot;timestamp\&quot;:&quot;+ System.currentTimeMillis() + &quot;,\n&quot; +
&quot; \&quot;version\&quot;:\&quot;1\&quot;\n&quot; +
&quot;}&quot;;
EncryptionRechargeDO encryptionRechargeDO = new EncryptionRechargeDO();
encryptionRechargeDO.setPrivateKey(&quot;TM34ZrPp8DLn+shdXH7mBxFURhYha2eo&quot;);
encryptionRechargeDO.setEncryptionData(DESUtil.encrypt(&quot;TM34ZrPp8DLn+shdXH7mBxFURhYha2eo&quot;, json));
String responseData = null;
try {
responseData = HttpUtil.post(&quot;http://moon.cqxinhuayun.com/recharge/api/recharge.html&quot;, gson.toJson(encryptionRechargeDO), conn -&gt; {
conn.setRequestProperty(&quot;Content-Type&quot;, &quot;application/json;charset=utf-8&quot;);
conn.setRequestProperty(&quot;accept&quot;, &quot;application/json;charset=utf-8&quot;);
}
);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(&quot;回调下游接口返回结果为:&quot; + responseData);
System.out.println(gson.toJson(encryptionRechargeDO));
}</code></pre>
<p>java加密:</p>
<pre><code class="language-java"> public static String encrypt(String password, String data) {
if (password== null || password.length() &lt; 8) {
throw new RuntimeException(&quot;加密失败,key不能小于8位&quot;);
}
if (data == null)
return null;
try {
DESKeySpec dks = new DESKeySpec(password.getBytes(&quot;utf-8&quot;));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(&quot;DES&quot;);
SecretKey secretKey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(&quot;DES/CBC/PKCS5Padding&quot;);
IvParameterSpec iv = new IvParameterSpec(&quot;12345678&quot;.getBytes(&quot;utf-8&quot;));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
byte[] bytes = cipher.doFinal(data.getBytes(&quot;utf-8&quot;));
//JDK1.8及以上可直接使用Base64,JDK1.7及以下可以使用BASE64Encoder
//Android平台可以使用android.util.Base64
return new String(Base64.getEncoder().encode(bytes));
} catch (Exception e) {
e.printStackTrace();
return data;
}
}</code></pre>
<p>4.接口返回规范</p>
<h5>返回参数说明</h5>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>status</td>
<td>int</td>
<td>响应状态码</td>
</tr>
<tr>
<td>msg</td>
<td>string</td>
<td>响应信息</td>
</tr>
<tr>
<td>version</td>
<td>int</td>
<td>响应状态码</td>
</tr>
<tr>
<td>data</td>
<td>object</td>
<td>响应数据</td>
</tr>
</tbody>
</table>
<p>详情见每个具体的接口</p>
<h5>返回示例</h5>
<pre><code>
{&quot;status&quot;:200,&quot;msg&quot;:&quot;操作成功&quot;,&quot;version&quot;:1,&quot;data&quot;:null}
</code></pre>