如何對用戶的綁定的身份證真實性進行實名認證(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("//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(); } } } }
上線前建議與客服溝通下,確認無誤即可上線啦!