身份证二要素实名认证

Posted loutai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了身份证二要素实名认证相关的知识,希望对你有一定的参考价值。

适用于金融、保险、在线教育、电商、租赁、物流、旅游等需要实名认证场景。直连自公安部和银联中心接口,实时查询,权威可靠!通过输入姓名和身份证号,即可快速验证姓名与身份证号的真实性和一致性。查看详情

参数名必填描述默认值
Content-Type true   application/json


 

 

 

  • 请求参数(body):
 参数名 类型 是否数组  必填  描述  默认值 
 idName string  否  是  身份证号码   
 userName string  否  是  身份证姓名   

 

 

 

 

 

 

 

  • 返回类型参数:
参数名类型是否数组必填描述
success boolean 请求是否成功
code int 返回码,参照返回码说明
message string 返回信息

 

 

 

 

 

 

  • 返回码(code)说明:
返回码说明错误信息
400423 请求处理时等待超时 UID Request Timeout
400431 身份证信息不匹配 User identity not match
400420 请求参数不合法 Parameter illegal
400422 请求处理时发生异常 UID Request Exception

 

 

 

 

 

 

 

  • Java示例
技术图片
  1 import java.io.BufferedReader;
  2 import java.io.IOException;
  3 import java.io.InputStream;
  4 import java.io.InputStreamReader;
  5 import java.io.OutputStream;
  6 import java.io.UnsupportedEncodingException;
  7 import java.net.HttpURLConnection;
  8 import java.net.URL;
  9 import java.net.URLEncoder;
 10 import java.util.HashMap;
 11 import java.util.Map;
 12  
 13 import javax.net.ssl.HostnameVerifier;
 14 import javax.net.ssl.HttpsURLConnection;
 15 import javax.net.ssl.SSLSession;
 16  
 17 import org.json.JSONObject;//可根据需要导入jar
 18  
 19 public class JavaDemo {
 20     public static final String DEF_CHATSET = "UTF-8";
 21     public static final int DEF_CONN_TIMEOUT = 30000;
 22     public static final int DEF_READ_TIMEOUT = 30000;
 23     public static String userAgent =  "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
 24      
 25     public static final HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
 26         public boolean verify(String hostname, SSLSession session) {
 27             return true;
 28         }
 29     };
 30      
 31     //配置您申请的KEY
 32     public static final String APICODE ="*************************";
 33  
 34     //1.API方法
 35     public static void getRequest(){
 36         String result =null;
 37         String url ="https://api.yonyoucloud.com/apis/dst/matchIdentity/matchIdentity";//请求接口地址
 38         String method = "POST";
 39         String paramFormat = "form";
 40         Map<String, Object> params = new HashMap<String, Object>();//请求参数
 41         params.put("idNumber", "");
 42         params.put("userName", "");
 43  
 44         Map<String, Object> headerParams = new HashMap<String, Object>();//请求头参数
 45         headerParams.put("apicode", APICODE);//APICODE
 46         headerParams.put("Content-Type", "application/json");
 47  
 48         try {
 49             result = net(url, params, headerParams, method, paramFormat);
 50             System.out.println(result);
 51         } catch (Exception e) {
 52             e.printStackTrace();
 53         }
 54     }
 55  
 56     /**
 57      *
 58      * @param strUrl 请求地址
 59      * @param params 请求参数
 60      * @param method 请求方法
 61      * @return  网络请求字符串
 62      * @throws Exception
 63      */
 64     public static String net(String strUrl, Map<String,Object> params, Map<String,Object> headerParams,String method, String paramFormat) throws Exception {
 65         HttpURLConnection conn = null;
 66         BufferedReader reader = null;
 67         String rs = null;
 68         try {
 69             String contentType = null;
 70             if(headerParams.containsKey("Content-Type"))
 71                 contentType = headerParams.get("Content-Type").toString();
 72                  
 73             StringBuffer sb = new StringBuffer();
 74             if(method==null || method.equals("GET")){
 75                 strUrl = strUrl+"?"+urlencode(params);
 76             }
 77              
 78             trustAllHttpsCertificates();
 79             HttpsURLConnection.setDefaultHostnameVerifier(DO_NOT_VERIFY);
 80              
 81             URL url = new URL(strUrl);
 82             conn = (HttpURLConnection) url.openConnection();
 83             if(method==null || method.equals("GET")){
 84                 conn.setRequestMethod("GET");
 85             }else{
 86                 conn.setRequestMethod("POST");
 87                 conn.setDoOutput(true);
 88             }
 89             conn.setRequestProperty("User-agent", userAgent);
 90             for (String i : headerParams.keySet()) {
 91                 conn.setRequestProperty(i, headerParams.get(i).toString());
 92             }
 93             if("form".equals(paramFormat) && !"application/x-www-form-urlencoded".equals(contentType) && !"application/xml".equals(contentType)) {
 94                 conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
 95             }
 96             conn.setUseCaches(false);
 97             conn.setConnectTimeout(DEF_CONN_TIMEOUT);
 98             conn.setReadTimeout(DEF_READ_TIMEOUT);
 99             conn.setInstanceFollowRedirects(false);
100             conn.connect();
101             if (params!= null && method.equals("POST")) {
102                 try {
103                     OutputStream out = conn.getOutputStream();
104                     if("form".equals(paramFormat)) {
105                         if("application/x-www-form-urlencoded".equals(contentType))
106                             out.write(urlencode(params).getBytes("utf-8"));
107                         else if("application/xml".equals(contentType))
108                             out.write(xmlencode(params).getBytes("utf-8"));
109                         else
110                             out.write(jsonencode(params).getBytes("utf-8"));
111                     } else
112                         out.write(params.toString().getBytes("utf-8"));
113                      
114                 } catch (Exception e) {
115                     e.printStackTrace();
116                 }
117             }
118             InputStream is = conn.getInputStream();
119             reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));
120             String strRead = null;
121             while ((strRead = reader.readLine()) != null) {
122                 sb.append(strRead);
123             }
124             rs = sb.toString();
125         } catch (IOException e) {
126             e.printStackTrace();
127         } finally {
128             if (reader != null) {
129                 reader.close();
130             }
131             if (conn != null) {
132                 conn.disconnect();
133             }
134         }
135         return rs;
136     }
137      
138     //将map型转为请求参数型
139     public static String urlencode(Map<String,Object>data) {
140         StringBuilder sb = new StringBuilder();
141         for (Map.Entry i : data.entrySet()) {
142             try {
143                 if(("").equals(i.getKey())) {
144                     sb.append(URLEncoder.encode(i.getValue()+"","UTF-8"));
145                 } else {
146                     sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue()+"","UTF-8")).append("&");
147                 }
148             } catch (UnsupportedEncodingException e) {
149                 e.printStackTrace();
150             }
151         }
152         return sb.toString();
153     }
154      
155     //将map型转为请求参数型
156     public static String jsonencode(Map<String,Object>data) {
157         JSONObject jparam = new JSONObject();
158         for (Map.Entry i : data.entrySet())
159             jparam.put(i.getKey(), i.getValue());
160          
161         return jparam.toString();
162     }
163      
164     //将map型转为请求参数型
165     public static String xmlencode(Map<String,Object>data) {
166         StringBuffer xmlData = new StringBuffer(); 
167         xmlData.append("<?xml version="1.0" encoding="UTF-8"?>");
168         for (Map.Entry i : data.entrySet())
169              xmlData.append("<" + i.getKey() + ">" + i.getValue() + "</" + i.getKey() + ">");
170          
171         return xmlData.toString();
172     }
173      
174         static class miTM implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
175         public java.security.cert.X509Certificate[] getAcceptedIssuers() {
176             return null;
177         }
178  
179         public boolean isServerTrusted(java.security.cert.X509Certificate[] certs) {
180             return true;
181         }
182  
183         public boolean isClientTrusted(java.security.cert.X509Certificate[] certs) {
184             return true;
185         }
186  
187         public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
188                 throws java.security.cert.CertificateException {
189             return;
190         }
191  
192         public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
193                 throws java.security.cert.CertificateException {
194             return;
195         }
196     }
197  
198     private static void trustAllHttpsCertificates() throws Exception {
199         javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
200         javax.net.ssl.TrustManager tm = new miTM();
201         trustAllCerts[0] = tm;
202         javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
203         sc.init(null, trustAllCerts, null);
204         javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
205     }
206      
207     public static void main(String[] args) {
208         getRequest();
209     }
210 }
View Code

 

  • PHP示例
技术图片
技术图片
 1 <?php
 2 header(‘Content-type:text/html;charset=utf-8‘);
 3 //配置您申请的appkey
 4 $apicode = "*********************";
 5  
 6 $url = "https://api.yonyoucloud.com/apis/dst/matchIdentity/matchIdentity";
 7  
 8 $method = "POST";
 9  
10 $params = array(
11         "idNumber" => "",
12         "userName" => "",
13  
14 );
15  
16 $header = array();
17 $header[] = "apicode:".$apicode;
18 $header[] = "content-type:application/json";
19 $header[] = "Content-Type:application/json";
20  
21  
22 $content = linkcurl($url,$method,$params,$header);
23 $result = json_decode($content,true);
24 if($result){
25     if($result[‘error_code‘]==‘0‘){
26         print_r($result);
27     }else{
28         echo $result[‘error_code‘].":".$result[‘reason‘];
29     }
30 }else{
31     echo "请求失败";
32 }
33  
34 /**
35  * 请求接口返回内容
36  * @param  string $url [请求的URL地址]
37  * @param  string $params [请求的参数]
38  * @param  int $ipost [是否采用POST形式]
39  * @return  string
40  */
41 function linkcurl($url,$method,$params=false,$header=false){
42     $httpInfo = array();
43     $ch = curl_init();
44      
45     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
46     curl_setopt($ch, CURLOPT_URL, $url);
47     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
48     curl_setopt($ch, CURLOPT_FAILONERROR, false);
49     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
50      
51     if (1 == strpos("$".$url, "https://"))
52     {
53         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
54         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
55     }
56     curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
57     curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
58     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
59  
60     if($method == "POST" ){
61         curl_setopt( $ch , CURLOPT_POST , true );
62         curl_setopt( $ch , CURLOPT_POSTFIELDS, json_encode($params) );
63     }else if($params){
64         curl_setopt( $ch , CURLOPT_URL , $url.‘?‘.http_build_query($params) );
65     }
66     $response = curl_exec( $ch );
67     if ($response === FALSE) {
68         //echo "cURL Error: " . curl_error($ch);
69         return false;
70     }
71     $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
72     $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
73     curl_close( $ch );
74     return $response;
75 }
76 ?>
View Code

 

  • C#示例
技术图片
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Net;
  6 using System.IO;
  7 using System.Diagnostics;
  8 using System.Web;
  9  
 10   
 11 namespace ConsoleAPI
 12 {
 13     class Program
 14     {
 15         static void Main(string[] args)
 16         {
 17             string url ="https://api.yonyoucloud.com/apis/dst/matchIdentity/matchIdentity";//请求接口地址
 18             string method = "POST";
 19             string apicode = "*******************"; //配置您申请的appkey
 20   
 21             var bodyParams = new Dictionary<string, string>();
 22             bodyParams.Add("idNumber", "");
 23             bodyParams.Add("userName", "");
 24  
 25             var headerParams = new Dictionary<string, string>();
 26             headerParams.Add("apicode", apicode);
 27             headerParams.Add("Content-Type", "application/json");
 28              
 29             string result1 = sendPost(url, bodyParams, headerParams, method);
 30   
 31             JsonObject newObj1 = new JsonObject(result1);
 32             String errorCode1 = newObj1["error_code"].Value;
 33   
 34             if (errorCode1 == "0")
 35             {
 36                 Debug.WriteLine("成功");
 37                 Debug.WriteLine(newObj1);
 38             }
 39             else
 40             {
 41                 //Debug.WriteLine("失败");
 42                 Debug.WriteLine(newObj1["error_code"].Value+":"+newObj1["reason"].Value);
 43             }
 44   
 45   
 46         }
 47   
 48         /// <summary>
 49         /// Http (GET/POST)
 50         /// </summary>
 51         /// <param name="url">请求URL</param>
 52         /// <param name="bodyParams">请求体参数</param>
 53         /// <param name="headerParams">请求头参数</param>
 54         /// <param name="method">请求方法</param>
 55         /// <returns>响应内容</returns>
 56         static string sendPost(string url, IDictionary<string, string> bodyParams, IDictionary<string, string> headerParams, string method)
 57         {
 58             if (method.ToLower() == "post")
 59             {
 60                 HttpWebRequest req = null;
 61                 HttpWebResponse rsp = null;
 62                 System.IO.Stream reqStream = null;
 63                 try
 64                 {
 65                     req = (HttpWebRequest)WebRequest.Create(url);
 66                     req.Method = method;
 67                     req.KeepAlive = false;
 68                     req.ProtocolVersion = HttpVersion.Version10;
 69                     req.Timeout = 5000;
 70                     req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
 71                     BuildHeader(headerParams, req);
 72                     byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(bodyParams, "utf8"));
 73                     reqStream = req.GetRequestStream();
 74                     reqStream.Write(postData, 0, postData.Length);
 75                     rsp = (HttpWebResponse)req.GetResponse();
 76                     Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
 77                     return GetResponseAsString(rsp, encoding);
 78                 }
 79                 catch (Exception ex)
 80                 {
 81                     return ex.Message;
 82                 }
 83                 finally
 84                 {
 85                     if (reqStream != null) reqStream.Close();
 86                     if (rsp != null) rsp.Close();
 87                 }
 88             }
 89             else
 90             {
 91                 //创建请求
 92                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "?" + BuildQuery(bodyParams, "utf8"));
 93   
 94                 //GET请求
 95                 request.Method = "GET";
 96                 request.ReadWriteTimeout = 5000;
 97                 request.ContentType = "text/html;charset=UTF-8";
 98                 BuildHeader(headerParams, req);
 99                 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
100                 Stream myResponseStream = response.GetResponseStream();
101                 StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
102   
103                 //返回内容
104                 string retString = myStreamReader.ReadToEnd();
105                 return retString;
106             }
107         }
108   
109         /// <summary>
110         /// 组装普通文本请求参数。
111         /// </summary>
112         /// <param name="parameters">Key-Value形式请求参数字典</param>
113         /// <returns>URL编码后的请求数据</returns>
114         static string BuildQuery(IDictionary<string, string> parameters, string encode)
115         {
116             StringBuilder postData = new StringBuilder();
117             bool hasParam = false;
118             IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator();
119             while (dem.MoveNext())
120             {
121                 string name = dem.Current.Key;
122                 string value = dem.Current.Value;
123                 // 忽略参数名或参数值为空的参数
124                 if (!string.IsNullOrEmpty(name))//&& !string.IsNullOrEmpty(value)
125                 {
126                     if (hasParam)
127                     {
128                         postData.Append("&");
129                     }
130                     postData.Append(name);
131                     postData.Append("=");
132                     if (encode == "gb2312")
133                     {
134                         postData.Append(HttpUtility.UrlEncode(value, Encoding.GetEncoding("gb2312")));
135                     }
136                     else if (encode == "utf8")
137                     {
138                         postData.Append(HttpUtility.UrlEncode(value, Encoding.UTF8));
139                     }
140                     else
141                     {
142                         postData.Append(value);
143                     }
144                     hasParam = true;
145                 }
146             }
147             return postData.ToString();
148         }
149          
150         /// <summary>
151         /// 组装请求头参数。
152         /// </summary>
153         /// <param name="headerParams">Key-Value形式请求参数字典</param>
154         /// <param name="req">web请求</param>
155         static void BuildHeader(IDictionary<string, string> headerParams, HttpWebRequest req)
156         {
157             IEnumerator<KeyValuePair<string, string>> dem = headerParams.GetEnumerator();
158             while (dem.MoveNext())
159             {
160                 req.Headers.Add(dem.Current.Key, dem.Current.value);
161             }
162         }
163   
164         /// <summary>
165         /// 把响应流转换为文本。
166         /// </summary>
167         /// <param name="rsp">响应流对象</param>
168         /// <param name="encoding">编码方式</param>
169         /// <returns>响应文本</returns>
170         static string GetResponseAsString(HttpWebResponse rsp, Encoding encoding)
171         {
172             System.IO.Stream stream = null;
173             StreamReader reader = null;
174             try
175             {
176                 // 以字符流的方式读取HTTP响应
177                 stream = rsp.GetResponseStream();
178                 reader = new StreamReader(stream, encoding);
179                 return reader.ReadToEnd();
180             }
181             finally
182             {
183                 // 释放资源
184                 if (reader != null) reader.Close();
185                 if (stream != null) stream.Close();
186                 if (rsp != null) rsp.Close();
187             }
188         }
189     }
190 }
View Code

 

  • 请求参数示例:
{ "userName":"小明","idNumber":"120902199912135678"}
技术图片
  • JSON正确返回示例
{
    "success": true,
    "code": 400100,
    "message": "成功"
}
技术图片
  • 错误码说明

调用方错误:

错误码说明错误信息
300001 请求header中没有设置apikey Missing apikey
300002 api不存在或url无法解析 URL cannot be resolved
300003 apikey不存在,请输入正确的apikey apicode does not exist
300004 服务剩余次数不足,请再次购买 Service overdue, please pay in time
300005 未设置ip白名单 not int white ip list
300006 IP白名单中不包含您的IP IP white list does not contain your IP
300007 系统繁忙稍候再试 Sorry,The system is busy. Please try again late
300008 访问次数超载 Request was denied due to api flow control
300009 未找到节流信息 not int apiservice paramer
300010 header参数中缺少需签名的参数值 request header do not contain param:
300011 缺少需验证的参数列表 no sign headers found!
300012 签名信息不匹配 Signature information mismatch
300013 header中缺少参数appkey appkey does not exist in the request header
300014 header中缺少参数appsecret appsecret does not exist
300015 api已过期,请另行购买 Your API has been expired!
300017 要求必填参数为不能为空 Requied parameter can not be null!
300018 api没有授权 The app key do not has the authorization of this api

 

 

 

 

 

 

 

 

 

 

 

 

 



 

 

 

 

 

 

 

 

 

  • 服务地址:身份证二要素实名认证
  • 数据来源:用友旗下中关村银行和第三方支付公司畅捷支付直连银联,通过银联接口实时核验,非缓存数据

 

特别提醒:选择实名认证接口时一定要仔细甄别,由于身份证实名制服务提供时间已久,很多数据提供商(实则是二

道贩子)利用缓存数据对外提供服务(这些历史缓存数据的源头有可能是NCIIC,这也是他们敢宣称“直连公安部接口”的

原因)。目前国内预计有8亿元的缓存量市场,由于缓存的数据并没有什么成本,所以这些鱼龙混杂的公司,在市面上

提供的接口调用价格甚至低至0.1元/次。实际上不仅其数据更新的及时性远远无法达到NCIIC的标准,而且留存用户信

息的行为本身就是违法的,更不要说用于商业目的。这些服务商随时都面临着被查封的风险,一旦接入这种服务,如

果服务商挂了,给使用接口的单位带来的损失或将是无法估量的。。。

以上是关于身份证二要素实名认证的主要内容,如果未能解决你的问题,请参考以下文章

使用阿里云接口进行银行卡四要素实名认证

手机号二要素实名认证

PHP如何进行身份证实名认证?

hbuilderx+实名认证+安全吗

身份证实名认证

身份证实名认证