接口规范
<p>[TOC]</p>
<p><code>注:如果您已经自定义域名,请将接口地址中的域名www.wjx.cn换成自定义域名</code></p>
<p>1、接口仅支持<code>post</code>请求,<code>json</code>的数据格式,需要在<code>http header</code>中设置 <code>Content-Type:application/json</code>。
2、接口使用<code>Utf-8</code>编号;
3、以键值对的方式传递参数;
4、可在接口地址后统一加上<code>?traceid=xxx&amp;action=xxx</code>来方便跟踪定位;
5、QPS(每秒最大请求数)限制,参见[3.1 数据接口列表](<a href="https://www.showdoc.com.cn/wjxopenapi/7565183782246685">https://www.showdoc.com.cn/wjxopenapi/7565183782246685</a> "3.1 数据接口列表")中对各接口的限制;
6、公共参数说明如下:</p>
<h4>GET请求参数列表:</h4>
<table>
<thead>
<tr>
<th style="text-align: left;">字段</th>
<th style="text-align: left;">类型</th>
<th>是否必须</th>
<th>默认</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">traceid</td>
<td style="text-align: left;">varchar</td>
<td>否</td>
<td></td>
<td>1:为方便跟踪请求定位问题,建议添加<br> 2:值为全局唯一标识符(GUID,Globally Unique Identifier) <br> 3:GUID值采用32位全小写格式,不含“-” <br> 4:参与签名<br> 5:traceid参数不要放在POST参数中</td>
</tr>
</tbody>
</table>
<h4>POST请求参数列表:</h4>
<table>
<thead>
<tr>
<th style="text-align: left;">字段</th>
<th style="text-align: left;">类型</th>
<th>是否必须</th>
<th>默认</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">appid</td>
<td style="text-align: left;">varchar</td>
<td>是</td>
<td></td>
<td>开发ID,开发密钥appkey请联系客户顾问获取</td>
</tr>
<tr>
<td style="text-align: left;">ts</td>
<td style="text-align: left;">varchar</td>
<td>是</td>
<td></td>
<td>Unix时间戳(格林威治时间1970年01月01日00时00分00秒起至现在的总秒数)主要用于请求有效期检查的,过期时间为30秒</td>
</tr>
<tr>
<td style="text-align: left;">encode</td>
<td style="text-align: left;">varchar</td>
<td>否</td>
<td></td>
<td>签名验证方式,支持SHA1、SHA256、SHA384、SHA512、SM3,不填默认为SHA1</td>
</tr>
<tr>
<td style="text-align: left;">nocache</td>
<td style="text-align: left;">varchar</td>
<td>否</td>
<td></td>
<td>可选参数,指定查询类接口是否使用缓存,默认值为0;使用缓存,1:不使用缓存</td>
</tr>
<tr>
<td style="text-align: left;">action</td>
<td style="text-align: left;">varchar</td>
<td>是</td>
<td></td>
<td>请求的接口编号,参见3.1 数据接口列表</td>
</tr>
<tr>
<td style="text-align: left;">sign</td>
<td style="text-align: left;">varchar</td>
<td>是</td>
<td></td>
<td>sign计算方法:<br>1、对消息体所有参数的参数名按ASCII码字母顺序进行排序;<br>2、根据排序参数名拼接对应的参数值;<br>3、将appkey加上所得的拼接字符串最后,得到加密原串;<br>4、对加密原串进行SHA1(默认)加密得到sign值;<br>5、 appid,appkey请联系客户顾问获取;</td>
</tr>
</tbody>
</table>
<h4>响应参数列表:</h4>
<table>
<thead>
<tr>
<th style="text-align: left;">字段</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">result</td>
<td style="text-align: left;">boolean</td>
<td>true/false</td>
</tr>
<tr>
<td style="text-align: left;">data</td>
<td style="text-align: left;">object</td>
<td>值为true时,data为返回的接口数据</td>
</tr>
<tr>
<td style="text-align: left;">errormsg</td>
<td style="text-align: left;">varchar</td>
<td>值为false时,errormsg为返回的错误描述</td>
</tr>
</tbody>
</table>
<h4>sign计算示例代码如下</h4>
<p>C#代码:</p>
<pre><code class="language-csharp">string url = &quot;https://&quot; + host + &quot;/openapi/default.aspx&quot;;
//时间截,用于判断请求的过期时间
string ts = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds).ToString();
//使用排序字典来构造参数
SortedDictionary&lt;string, string&gt; dic = new SortedDictionary&lt;string, string&gt;();
dic.Add(&quot;appid&quot;, appid);
dic.Add(&quot;ts&quot;, ts);
dic.Add(&quot;action&quot;, &quot;1000001&quot;);
dic.Add(&quot;vid&quot;, vid);
dic.Add(&quot;get_questions&quot;, &quot;0&quot;);
dic.Add(&quot;get_items&quot;, &quot;0&quot;);
StringBuilder toSign = new StringBuilder();
foreach (var kv in dic)
{
if (!string.IsNullOrEmpty(kv.Value))
{
toSign.Append(kv.Value);
}
}
//在拼接好的toSign基础上再加上appkey,组成最终的签名原串
toSign.Append(appkey);
//计算SHA1签名值,并将签名值转化为小写格式
string wjxSign = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(toSign.ToString(), &quot;SHA1&quot;).ToLower();
//将签名sign添加到参数中
dic.Add(&quot;sign&quot;, wjxSign);
string content = JsonConvert.SerializeObject(dic);
string data = HttpRequestUtility.SendPostHttpRequest(url, &quot;application/json&quot;, content);</code></pre>
<p>Java代码:</p>
<pre><code class="language-java">import java.net.URL;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.SortedMap;
import java.util.TreeMap;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
String host = &quot;your_host&quot;;
String appid = &quot;your_appid&quot;;
String vid = &quot;your_vid&quot;;
String appkey = &quot;your_appkey&quot;;
String url = &quot;https://&quot; + host + &quot;/openapi/default.aspx&quot;;
// 时间截,用于判断请求的过期时间
long ts = (new Date().getTime() / 1000) - (new Date(0).getTime() / 1000);
// 使用排序字典来构造参数
SortedMap&lt;String, String&gt; dic = new TreeMap&lt;&gt;();
dic.put(&quot;appid&quot;, appid);
dic.put(&quot;ts&quot;, String.valueOf(ts));
dic.put(&quot;action&quot;, &quot;1000001&quot;);
dic.put(&quot;vid&quot;, vid);
dic.put(&quot;get_questions&quot;, &quot;0&quot;);
dic.put(&quot;get_items&quot;, &quot;0&quot;);
StringBuilder toSign = new StringBuilder();
for (Map.Entry&lt;String, String&gt; kv : dic.entrySet()) {
if (kv.getValue() != null &amp;&amp; !kv.getValue().isEmpty()) {
toSign.append(kv.getValue());
}
}
// 在拼接好的toSign基础上再加上appkey,组成最终的签名原串
toSign.append(appkey);
// 计算SHA1签名值,并将签名值转化为小写格式
String wjxSign = getSHA1(toSign.toString()).toLowerCase();
// 将签名sign添加到参数中
dic.put(&quot;sign&quot;, wjxSign);
String content = new ObjectMapper().writeValueAsString(dic);
String data = sendPostHttpRequest(url, content);
System.out.println(data);
}
private static String getSHA1(String str) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance(&quot;SHA-1&quot;);
messageDigest.update(str.getBytes());
byte[] sha1Hash = messageDigest.digest();
StringBuilder hexString = new StringBuilder();
for (byte b : sha1Hash) {
String hex = Integer.toHexString(0xff &amp; b);
if (hex.length() == 1) hexString.append(&#039;0&#039;);
hexString.append(hex);
}
return hexString.toString();
}
private static String sendPostHttpRequest(String urlString, String json) throws Exception {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod(&quot;POST&quot;);
conn.setRequestProperty(&quot;Content-Type&quot;, &quot;application/json&quot;);
try (OutputStream os = conn.getOutputStream()) {
byte[] input = json.getBytes(&quot;utf-8&quot;);
os.write(input, 0, input.length);
}
try (BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), &quot;utf-8&quot;))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
return response.toString();
}
}
}</code></pre>