如何对用户的绑定的身份证真实性进行实名认证(java)

java

现在随着对用户实名制的要求,因此用户提交的身份证信息经查需要检查是否为真实信息,我们需要对用户提交的身份证信息进行核验,具体操作步骤如下:

第一步

到认证平台注册账号:云亿互通--实名认证服务 (yunyidata.com),然后即可获取秘钥。

第二步

调试程序,下面依据java为例:

import net.sf.json.JSONObject;

import org.apache.http.HttpEntity;

import org.apache.http.NameValuePair;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.util.EntityUtils;

import com.netgate.util.MD5;

// 公民身份证实名认证实例代码

public class IDTest {

public static void main(String[] args) {

// 创建默认的httpClient实例

CloseableHttpClient httpclient = HttpClients.createDefault();

HttpPost httppost = new HttpPost("https://service.yunyidata.com/idAuthentic");

// 创建参数队列

String merNo = "26001";

String name = "张三";

String idNo = "350783199806195231";

String md5Key = "12345678"; // 在【管理后台-->安全管理-->秘钥信息】里面获取

String MD5Info = "";

MD5 md5 = new MD5();

String signStr = "merNo=" + merNo + "&name=" + name + "&idNo=" + idNo + "&" + md5Key;

MD5Info = md5.getMD5Info(signStr);

List<NameValuePair> formparams = new ArrayList<NameValuePair>();

formparams.add(new BasicNameValuePair("merNo", merNo));

formparams.add(new BasicNameValuePair("name", name));

formparams.add(new BasicNameValuePair("idNo", idNo));

formparams.add(new BasicNameValuePair("MD5Info", MD5Info));

UrlEncodedFormEntity uefEntity;

try {

uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");

httppost.setEntity(uefEntity);

System.out.println("executing request " + httppost.getURI());

CloseableHttpResponse response = httpclient.execute(httppost);

try {

HttpEntity entity = response.getEntity();

if (entity != null) {

String entitys = EntityUtils.toString(entity, "UTF-8");

System.out.println("--------------------------------------");

System.out.println("Response content: " + entitys);

System.out.println("--------------------------------------");

Map<String, String> data = new LinkedHashMap<String, String>();

JSONObject json = JSONObject.fromObject(entitys);

Iterator<?> it = json.keys();

// 遍历jsonObject数据,添加到Map对象

while(it.hasNext()){

String key = String.valueOf(it.next());

String values = String.valueOf(json.get(key));

if(key.equals("respMessage") || "MD5Info".equals(key)){

continue;

}

data.put(key, values);

}

String respMessage = (String) json.get("respMessage");

String matchMessage = (String) json.get("matchMessage");

System.out.println("respMessage: " + respMessage);

System.out.println("matchMessage: " + matchMessage);

}

} finally {

response.close();

}

} catch (ClientProtocolException e) {

e.printStackTrace();

} catch (UnsupportedEncodingException e1) {

e1.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

// 关闭连接,释放资源

try {

httpclient.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

上线前建议与客服沟通下,确认无误即可上线啦!

以上是 如何对用户的绑定的身份证真实性进行实名认证(java) 的全部内容, 来源链接: utcz.com/z/395105.html

回到顶部