最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java使用阿里云接口進(jìn)行身份證實(shí)名認(rèn)證的示例實(shí)現(xiàn)

 更新時間:2020年07月13日 15:04:14   作者:ruidongjun007  
這篇文章主要介紹了使用阿里云接口進(jìn)行身份證實(shí)名認(rèn)證的示例實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

如今隨著互聯(lián)網(wǎng)產(chǎn)業(yè)的多元化發(fā)展,尤其是互聯(lián)網(wǎng)金融,O2O,共享經(jīng)濟(jì)等新興商業(yè)形式的興起,企業(yè)對實(shí)名認(rèn)證業(yè)務(wù)的數(shù)據(jù)形式和數(shù)據(jù)質(zhì)量有了更高的需求。如今也衍生出身份證實(shí)名認(rèn)證業(yè)務(wù),通過接口將身份證號碼、姓名上傳至阿里云,再與全國公民身份信息系統(tǒng)進(jìn)行匹配,判斷信息的一致性。

在使用接口服務(wù)的方面我推薦使用技術(shù)實(shí)力強(qiáng)大的阿里云;

附上:阿里云最高¥2000云產(chǎn)品通用代金券

首先點(diǎn)擊:【阿里云API接口】獲取相應(yīng)的訂單后在控制臺中可以得到您的appcode;

發(fā)送數(shù)據(jù):

bodys.put("idNo", "340421190210182345");
bodys.put("name", "張三");

返回?cái)?shù)據(jù):

{
 "name": "張三",
 "idNo": "340421190710145412",
 "respMessage": "身份證信息匹配",
 "respCode": "0000",
 "province": "安徽省",
 "city": "淮南市",
 "county": "鳳臺縣",
 "birthday": "19071014",
 "sex": "M",
 "age": "111"
}

具體實(shí)現(xiàn)類:

public static void main(String[] args) {
    String host = "https://idenauthen.market.alicloudapi.com";
    String path = "/idenAuthentication";
    String method = "POST";
    String appcode = "你自己的AppCode";
    Map<String, String> headers = new HashMap<String, String>();
    //最后在header中的格式(中間是英文空格)為Authorization:APPCODE 83359fd73fe94948385f570e3c139105
    headers.put("Authorization", "APPCODE " + appcode);
    //根據(jù)API的要求,定義相對應(yīng)的Content-Type
    headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    Map<String, String> querys = new HashMap<String, String>();
    Map<String, String> bodys = new HashMap<String, String>();
    bodys.put("idNo", "340421190210182345");
    bodys.put("name", "張三");
 
 
    try {
      /**
      * 重要提示如下:
      * HttpUtils請從
      * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
      * 下載
      *
      * 相應(yīng)的依賴請參照
      * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
      */
      HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
      System.out.println(response.toString());
      //獲取response的body
      //System.out.println(EntityUtils.toString(response.getEntity()));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

工具類HttpUtils:

package com.netgate.util.send;
 
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
 
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
 
public class HttpUtils {
  
  /**
   * get
   * 
   * @param host
   * @param path
   * @param method
   * @param headers
   * @param querys
   * @return
   * @throws Exception
   */
  public static HttpResponse doGet(String host, String path, String method, 
      Map<String, String> headers, 
      Map<String, String> querys)
      throws Exception {    
    HttpClient httpClient = wrapClient(host);
 
    HttpGet request = new HttpGet(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
      request.addHeader(e.getKey(), e.getValue());
    }
    
    return httpClient.execute(request);
  }
  
  /**
   * post form
   * 
   * @param host
   * @param path
   * @param method
   * @param headers
   * @param querys
   * @param bodys
   * @return
   * @throws Exception
   */
  public static HttpResponse doPost(String host, String path, String method, 
      Map<String, String> headers, 
      Map<String, String> querys, 
      Map<String, String> bodys)
      throws Exception {    
    HttpClient httpClient = wrapClient(host);
 
    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
      request.addHeader(e.getKey(), e.getValue());
    }
 
    if (bodys != null) {
      List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
 
      for (String key : bodys.keySet()) {
        nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
      }
      UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
      formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
      request.setEntity(formEntity);
    }
 
    return httpClient.execute(request);
  }  
  
  /**
   * Post String
   * 
   * @param host
   * @param path
   * @param method
   * @param headers
   * @param querys
   * @param body
   * @return
   * @throws Exception
   */
  public static HttpResponse doPost(String host, String path, String method, 
      Map<String, String> headers, 
      Map<String, String> querys, 
      String body)
      throws Exception {    
    HttpClient httpClient = wrapClient(host);
 
    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
      request.addHeader(e.getKey(), e.getValue());
    }
 
    if (StringUtils.isNotBlank(body)) {
      request.setEntity(new StringEntity(body, "utf-8"));
    }
 
    return httpClient.execute(request);
  }
  
  /**
   * Post stream
   * 
   * @param host
   * @param path
   * @param method
   * @param headers
   * @param querys
   * @param body
   * @return
   * @throws Exception
   */
  public static HttpResponse doPost(String host, String path, String method, 
      Map<String, String> headers, 
      Map<String, String> querys, 
      byte[] body)
      throws Exception {    
    HttpClient httpClient = wrapClient(host);
 
    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
      request.addHeader(e.getKey(), e.getValue());
    }
 
    if (body != null) {
      request.setEntity(new ByteArrayEntity(body));
    }
 
    return httpClient.execute(request);
  }
  
  /**
   * Put String
   * @param host
   * @param path
   * @param method
   * @param headers
   * @param querys
   * @param body
   * @return
   * @throws Exception
   */
  public static HttpResponse doPut(String host, String path, String method, 
      Map<String, String> headers, 
      Map<String, String> querys, 
      String body)
      throws Exception {    
    HttpClient httpClient = wrapClient(host);
 
    HttpPut request = new HttpPut(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
      request.addHeader(e.getKey(), e.getValue());
    }
 
    if (StringUtils.isNotBlank(body)) {
      request.setEntity(new StringEntity(body, "utf-8"));
    }
 
    return httpClient.execute(request);
  }
  
  /**
   * Put stream
   * @param host
   * @param path
   * @param method
   * @param headers
   * @param querys
   * @param body
   * @return
   * @throws Exception
   */
  public static HttpResponse doPut(String host, String path, String method, 
      Map<String, String> headers, 
      Map<String, String> querys, 
      byte[] body)
      throws Exception {    
    HttpClient httpClient = wrapClient(host);
 
    HttpPut request = new HttpPut(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
      request.addHeader(e.getKey(), e.getValue());
    }
 
    if (body != null) {
      request.setEntity(new ByteArrayEntity(body));
    }
 
    return httpClient.execute(request);
  }
  
  /**
   * Delete
   * 
   * @param host
   * @param path
   * @param method
   * @param headers
   * @param querys
   * @return
   * @throws Exception
   */
  public static HttpResponse doDelete(String host, String path, String method, 
      Map<String, String> headers, 
      Map<String, String> querys)
      throws Exception {    
    HttpClient httpClient = wrapClient(host);
 
    HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
      request.addHeader(e.getKey(), e.getValue());
    }
    
    return httpClient.execute(request);
  }
  
  private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
    StringBuilder sbUrl = new StringBuilder();
    sbUrl.append(host);
    if (!StringUtils.isBlank(path)) {
      sbUrl.append(path);
    }
    if (null != querys) {
      StringBuilder sbQuery = new StringBuilder();
      for (Map.Entry<String, String> query : querys.entrySet()) {
        if (0 < sbQuery.length()) {
          sbQuery.append("&");
        }
        if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
          sbQuery.append(query.getValue());
        }
        if (!StringUtils.isBlank(query.getKey())) {
          sbQuery.append(query.getKey());
          if (!StringUtils.isBlank(query.getValue())) {
            sbQuery.append("=");
            sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
          }          
        }
      }
      if (0 < sbQuery.length()) {
        sbUrl.append("?").append(sbQuery);
      }
    }
    
    return sbUrl.toString();
  }
  
  private static HttpClient wrapClient(String host) {
    HttpClient httpClient = new DefaultHttpClient();
    if (host.startsWith("https://")) {
      sslClient(httpClient);
    }
    
    return httpClient;
  }
  
  private static void sslClient(HttpClient httpClient) {
    try {
      SSLContext ctx = SSLContext.getInstance("TLS");
      X509TrustManager tm = new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() {
          return null;
        }
        public void checkClientTrusted(X509Certificate[] xcs, String str) {
          
        }
        public void checkServerTrusted(X509Certificate[] xcs, String str) {
          
        }
      };
      ctx.init(null, new TrustManager[] { tm }, null);
      SSLSocketFactory ssf = new SSLSocketFactory(ctx);
      ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      ClientConnectionManager ccm = httpClient.getConnectionManager();
      SchemeRegistry registry = ccm.getSchemeRegistry();
      registry.register(new Scheme("https", 443, ssf));
    } catch (KeyManagementException ex) {
      throw new RuntimeException(ex);
    } catch (NoSuchAlgorithmException ex) {
      throw new RuntimeException(ex);
    }
  }
}

到此這篇關(guān)于Java使用阿里云接口進(jìn)行身份證實(shí)名認(rèn)證的示例實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)阿里云身份證實(shí)名認(rèn)證內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Springboot使用Redis中ZSetOperations實(shí)現(xiàn)博客訪問量

    Springboot使用Redis中ZSetOperations實(shí)現(xiàn)博客訪問量

    在日常的網(wǎng)站使用中,經(jīng)常會碰到頁面的訪問量,本文主要介紹了Springboot使用Redis中ZSetOperations實(shí)現(xiàn)博客訪問量,具有一定的參考價值,感興趣的可以了解一下
    2024-01-01
  • Java中的List集合初始化及常見方法解析

    Java中的List集合初始化及常見方法解析

    這篇文章主要介紹了Java中的List集合初始化及常見方法解析,List集合的特點(diǎn)是元素有序可重復(fù),只要是帶集合、數(shù)組的都叫有序,因若無序就不會存在有下標(biāo),本文來講一下List集合初始化及常見方法,需要的朋友可以參考下
    2023-10-10
  • Java DOM4J方式生成XML的方法

    Java DOM4J方式生成XML的方法

    今天小編就為大家分享一篇Java DOM4J方式生成XML的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • 深入淺析drools中Fact的equality?modes

    深入淺析drools中Fact的equality?modes

    這篇文章主要介紹了drools中Fact的equality?modes的相關(guān)知識,本文通過圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • Springboot過濾器禁止ip頻繁訪問功能實(shí)現(xiàn)

    Springboot過濾器禁止ip頻繁訪問功能實(shí)現(xiàn)

    這篇文章主要介紹了Springboot過濾器禁止ip頻繁訪問功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-04-04
  • 了解spring中的CloudNetflix Hystrix彈性客戶端

    了解spring中的CloudNetflix Hystrix彈性客戶端

    這篇文章主要介紹了了解spring中的CloudNetflix Hystrix彈性客戶端,客戶端彈性模式是在遠(yuǎn)程服務(wù)發(fā)生錯誤或表現(xiàn)不佳時保護(hù)遠(yuǎn)程資源(另一個微服務(wù)調(diào)用或者數(shù)據(jù)庫查詢)免于崩潰。,需要的朋友可以參考下
    2019-06-06
  • Java滾動數(shù)組計(jì)算編輯距離操作示例

    Java滾動數(shù)組計(jì)算編輯距離操作示例

    這篇文章主要介紹了Java滾動數(shù)組計(jì)算編輯距離操作,涉及java字符串與數(shù)組的遍歷、計(jì)算、轉(zhuǎn)換等相關(guān)操作技巧,需要的朋友可以參考下
    2019-12-12
  • 避免Java中的內(nèi)存泄漏的三種方法

    避免Java中的內(nèi)存泄漏的三種方法

    在Java開發(fā)中,內(nèi)存泄漏(Memory Leak)是一個常見但令人頭疼的問題,本文將深入探討什么是內(nèi)存泄漏、常見的泄漏原因、如何識別和避免內(nèi)存泄漏,以及通過代碼示例展示如何優(yōu)化Java程序以減少內(nèi)存泄漏的發(fā)生,需要的朋友可以參考下
    2024-07-07
  • java抓包后對pcap文件解析示例

    java抓包后對pcap文件解析示例

    這篇文章主要介紹了java抓包后對pcap文件解析示例,需要的朋友可以參考下
    2014-03-03
  • SpringMVC之返回JSON的三種方式

    SpringMVC之返回JSON的三種方式

    現(xiàn)在都是前后端分離了,后端只需要跟前端提供restful接口,所有接口都返回json格式數(shù)據(jù)即可,SpringMVC通常有3種方式向前端輸出json格式數(shù)據(jù),下面我們就來了解一下
    2023-06-06

最新評論

青岛市| 疏附县| 黄平县| 思南县| 北票市| 孟州市| 商洛市| 尉氏县| 富平县| 葵青区| 滁州市| 玉林市| 香港 | 海门市| 汨罗市| 清涧县| 洱源县| 镇坪县| 青川县| 抚远县| 富民县| 昌邑市| 鸡东县| 科技| 务川| 巴南区| 阿鲁科尔沁旗| 东安县| 苏尼特左旗| 泰顺县| 改则县| 秭归县| 阿拉善盟| 呼伦贝尔市| 萨迦县| 锦州市| 常德市| 阜康市| 行唐县| 西和县| 郁南县|