身份证实名认证
<h3>接口描述</h3>
<ul>
<li>验证姓名和身份证号是否一致,结果包括:一致、不一致</li>
</ul>
<h3>请求地址</h3>
<p><code>https://api.jumdata.com/idcard/check</code></p>
<h3>请求方式</h3>
<ul>
<li>GET/POST</li>
</ul>
<h3>请求格式</h3>
<ul>
<li>x-www-form-urlencoded</li>
</ul>
<h3>请求参数</h3>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:400px">说明</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>encryption</td>
<td>String</td>
<td>否</td>
<td>参数加密算法,可选值:AES256、AES128、SM4。默认不加密。<br>详见参数加密说明</td>
</tr>
<tr>
<td>name</td>
<td>String</td>
<td>是</td>
<td>姓名</td>
</tr>
<tr>
<td>idcard</td>
<td>String</td>
<td>是</td>
<td>身份证号码</td>
</tr>
</tbody>
</table>
<h3>签名算法</h3>
<pre><code>sign = sha256(appId + appSecret + timestamp)</code></pre>
<p>用服务商分配的 <strong>appId</strong>、服务商分配的 <strong>appSecret</strong>,当前时间戳 <strong>timestamp</strong>,按上述顺序拼接成字符串,再进行 <strong>sha256</strong> 哈希得到。如下:</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>
<p>如果参数需要加密,则通过参数encryption指定加密算法</p>
<ul>
<li>
<p>AES256
加密key为appSecret
[AES256Util.java](<a href="https://file.jumdata.com/support/AES256Util.java">https://file.jumdata.com/support/AES256Util.java</a> "AES256Util.java")</p>
</li>
<li>
<p>AES128
加密key为appSecret,加密算法/分组加密模式/分组填充方式为:AES/ECB/PKCS5Padding</p>
</li>
<li>SM4
加密key请联系服务商分配
[SM4Util.java](<a href="https://file.jumdata.com/support/SM4Util.java">https://file.jumdata.com/support/SM4Util.java</a> "SM4Util.java")</li>
</ul>
<h3>正确返回</h3>
<pre><code>{
&quot;code&quot;: 200,
&quot;message&quot;: &quot;成功&quot;,
&quot;charge&quot;: true,
&quot;taskNo&quot;: &quot;69564903663951243279&quot;,
&quot;data&quot;: {
&quot;result&quot;: 0,
&quot;desc&quot;: &quot;一致&quot;,
&quot;sex&quot;: &quot;男&quot;,
&quot;birthday&quot;: &quot;19940320&quot;,
&quot;address&quot;: &quot;浙江省杭州市西湖区&quot;
}
}</code></pre>
<h3>错误返回</h3>
<pre><code>{
&quot;msg&quot;: &quot;身份证号格式不正确&quot;,
&quot;code&quot;: 400
}</code></pre>
<h3>返回字段说明</h3>
<table>
<thead>
<tr>
<th>字段名</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见返回码说明(非http返回状态码)</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</td>
</tr>
<tr>
<td>charge</td>
<td>计费标志</td>
</tr>
<tr>
<td>taskNo</td>
<td>本次请求号</td>
</tr>
<tr>
<td>data</td>
<td>返回具体结果,object类型,详见data返回字段描述</td>
</tr>
</tbody>
</table>
<h4>data返回字段说明</h4>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:400px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>result</td>
<td>0 一致,1 不一致</td>
</tr>
<tr>
<td>desc</td>
<td>验证结果描述信息</td>
</tr>
<tr>
<td>sex</td>
<td>性别</td>
</tr>
<tr>
<td>birthday</td>
<td>生日</td>
</tr>
<tr>
<td>address</td>
<td>籍贯</td>
</tr>
</tbody>
</table>
<h4>code 返回码说明</h4>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:400px">说明</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>501</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>607</td>
<td>ip不在白名单</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>
<h4>java</h4>
<pre><code class="language-java">import com.anq.core.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class Demo {
String appId = &quot;服务商分配的appId&quot;;
String appSecret = &quot;服务商分配的appSecret&quot;;
String url = &quot;https://api.jumdata.com/idcard/check&quot;;
@Test
public void idcardValidate() {
String timestamp = System.currentTimeMillis() + &quot;&quot;;
String sign = DigestUtils.sha256Hex(appId + appSecret + timestamp); // 生成sign
Map&lt;String, Object&gt; params = new HashMap&lt;String, Object&gt;();
params.put(&quot;appId&quot;, appId); // 服务商分配的appId
params.put(&quot;timestamp&quot;, timestamp);
params.put(&quot;sign&quot;, sign);
params.put(&quot;name&quot;, &quot;&quot;);
params.put(&quot;idcard&quot;, &quot;&quot;);
//HttpUtil可从这里下载 https://file.jumdata.com/support/HttpUtil.java
String result = HttpUtil.post(url, null, params);
log.info(result);
}
}</code></pre>
<h4>php</h4>
<pre><code class="language-php">&lt;?php
$appId = &quot;服务商分配的appId&quot;;
$appSecret= &quot;服务商分配的appSecret&quot;;
$url = &quot;https://api.jumdata.com/idcard/check&quot;;
$method = &quot;POST&quot;;
$headers = array();
//根据API的要求,定义相对应的Content-Type
array_push($headers, &quot;Content-Type&quot; . &quot;:&quot; . &quot;application/x-www-form-urlencoded; charset=UTF-8&quot;);
$timestamp = getUnixTimestamp();
var_dump($timestamp);
$sign = hash('sha256',$appId . $appSecret . $timestamp); // 生成sign
var_dump($sign);
$idcard = &quot;&quot;;
$name = &quot;&quot;;
$bodys = &quot;appId=&quot;. $appId . &quot;&amp;sign=&quot; . $sign . &quot;&amp;amptimestamp=&quot;. $timestamp. &quot;&amp;idcard=&quot; . $idcard . &quot;&amp;name=&quot; . $name;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
var_dump(curl_exec($curl));
function getUnixTimestamp ()
{
list($s1, $s2) = explode(' ', microtime());
return sprintf('%.0f',(floatval($s1) + floatval($s2)) * 1000);
}
</code></pre>
<h4>python</h4>
<pre><code class="language-python">import requests
import time
import hashlib
appId = &quot;服务商分配&quot;
appSecret = &quot;服务商分配&quot;
url = &quot;https://api.jumdata.com/idcard/check&quot;
method = 'POST'
time = time.time()
timestamp = str(round(time * 1000))
print (timestamp)
tmp = appId + appSecret + timestamp
sign = hashlib.sha256(tmp.encode(&quot;utf8&quot;)).hexdigest()
bodys = {}
bodys['appId'] = appId
bodys['timestamp'] = timestamp
bodys['sign'] = sign
bodys['idcard'] = &quot;&quot;
bodys['name'] = &quot;&quot;
headers = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
response = requests.post(url, data = bodys, headers = headers)
print (response.text)
</code></pre>
<h4>C Sharp</h4>
<p>``` c#
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;</p>
<p>public class Demo
{
private const String url = "<a href="https://api.jumdata.com/idcard/check"">https://api.jumdata.com/idcard/check"</a>;;
private const String method = "POST";
private const String appId = "服务商分配";
private const String appSecret = "服务商分配";</p>
<pre><code>public static void Main(string[] args)
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
String timestamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
String sign = SHA256(appId + appSecret + timestamp);
String name = &quot;&quot;;
String idcard = &quot;&quot;;
String bodys = &quot;appId=&quot; + appId + &quot;&amp;sign=&quot; + sign + &quot;&amp;timestamp=&quot; + timestamp + &quot;&amp;idcard=&quot; + idcard +
&quot;&amp;name=&quot; + name;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
httpRequest = (HttpWebRequest) WebRequest.CreateDefault(new Uri(url));
httpRequest.Method = method;
httpRequest.ContentType = &quot;application/x-www-form-urlencoded; charset=UTF-8&quot;;
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
httpResponse = (HttpWebResponse) httpRequest.GetResponse();
Console.WriteLine(httpResponse.StatusCode);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding(&quot;utf-8&quot;));
Console.WriteLine(reader.ReadToEnd());
}
public static string SHA256(string str)
{
byte[] SHA256Data = Encoding.UTF8.GetBytes(str);
SHA256Managed Sha256 = new SHA256Managed();
byte[] by = Sha256.ComputeHash(SHA256Data);
return BitConverter.ToString(by).Replace(&quot;-&quot;, &quot;&quot;).ToLower();
}</code></pre>
<p>}</p>
<pre><code></code></pre>