如何对用户绑定的身份证真实性进行实名认证API接口(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();
            }
        }
    }

}

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值