运营商三要素验证
<h3>接口描述</h3>
<ul>
<li>验证姓名、身份证号、手机号是否一致,返回验证结果</li>
</ul>
<h3>请求地址</h3>
<p><code>https://api.jumdata.com/mobile-three/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: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>name</td>
<td>String</td>
<td>是</td>
<td>姓名</td>
</tr>
<tr>
<td>idcard</td>
<td>String</td>
<td>是</td>
<td>身份证号</td>
</tr>
<tr>
<td>mobile</td>
<td>String</td>
<td>是</td>
<td>手机号</td>
</tr>
<tr>
<td>isp</td>
<td>String</td>
<td>否</td>
<td>运营商: cmcc-移动,cucc-联通,ctcc-电信,cncc-广电<br/>为空则自动识别运营商,支持携号转网<br/>传入表示指定运营商,如果传入的isp和实际运营商不符,则返回无记录,支持携号转入</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>
<pre><code>{
&quot;code&quot;: 200,
&quot;msg&quot;: &quot;成功&quot;,
&quot;taskNo&quot;: &quot;69564903663951243279&quot;,
&quot;charge&quot;: true,
&quot;data&quot;: {
&quot;result&quot;: &quot;0&quot;,
&quot;desc&quot;: &quot;一致&quot;,
&quot;isp&quot;: &quot;cmcc&quot;,
&quot;sex&quot;: &quot;男&quot;,
&quot;birthday&quot;: &quot;19850106&quot;,
&quot;address&quot;: &quot;浙江省杭州市&quot;
}
}</code></pre>
<h3>错误返回</h3>
<pre><code>{
&quot;code&quot;: 400,
&quot;msg&quot;: &quot;手机号格式不正确&quot;,
&quot;charge&quot;: false,
}</code></pre>
<h3>返回字段说明</h3>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见返回码说明</td>
</tr>
<tr>
<td>charge</td>
<td>计费标志</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</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:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>result</td>
<td>验证结果 <br/>0:一致(计费)<br/>1:不一致(计费)<br/>2: 无记录(不计费)</td>
</tr>
<tr>
<td>desc</td>
<td>结果描述</td>
</tr>
<tr>
<td>isp</td>
<td>运营商 <br/> cmcc:移动<br/>cucc:联通<br/>ctcc:电信<br/>cncc:广电</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:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>成功</td>
</tr>
<tr>
<td>400</td>
<td>参数错误</td>
</tr>
<tr>
<td>401</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 IdcardValidateDemo {
String appId = &quot;服务商分配的appId&quot;;
String appSecret = &quot;服务商分配的appSecret&quot;;
String url = &quot;https://api.jumdata.com/mobile_three/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;mobile&quot;, &quot;&quot;);
params.put(&quot;idcard&quot;, &quot;&quot;);
//HttpUtil可从这里下载 https://file.jumdata.com/support/HttpUtil.java
String result = HttpUtil.get(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/mobile_three/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(&#039;sha256&#039;,$appId . $appSecret . $timestamp); // 生成sign
var_dump($sign);
$idcard = &quot;&quot;;
$name = &quot;&quot;;
$mobile = &quot;&quot;;
$bodys = &quot;appId=&quot;. $appId . &quot;&amp;sign=&quot; . $sign . &quot;&amp;timestamp=&quot;. $timestamp. &quot;&amp;mobile=&quot; . mobile . &quot;&amp;name=&quot; . $name . &quot;&amp;idcard=&quot; . $idcard;
$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(&#039; &#039;, microtime());
return sprintf(&#039;%.0f&#039;,(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/mobile_three/check&quot;
method = &#039;POST&#039;
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[&#039;appId&#039;] = appId
bodys[&#039;timestamp&#039;] = timestamp
bodys[&#039;sign&#039;] = sign
bodys[&#039;mobile&#039;] = &quot;&quot;
bodys[&#039;name&#039;] = &quot;&quot;
bodys[&#039;idcard&#039;] = &quot;&quot;
headers = {
&#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded; charset=UTF-8&#039;
}
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 IdcardValidate
{
private const String url = "<a href="https://api.jumdata.com/mobile_three/check">https://api.jumdata.com/mobile_three/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;mobile=&quot; + mobile +
&quot;&amp;name=&quot; + name + &quot;&amp;idcard=&quot; + idcard;
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>