如今随着互联网产业的多元化发展,尤其是互联网金融,O2O,共享经济等新兴商业形式的兴起,企业对实名认证业务的数据形式和数据质量有了更高的需求。如今也衍生出身份证实名认证业务,通过接口将身份证号码、姓名上传至阿里云,再与全国公民身份信息系统进行匹配,判断信息的一致性。

在使用接口服务的方面我推荐使用技术实力强大的阿里云;

首先点击:(阿里云API接口)获取相应的订单后在控制台中可以得到您的appcode;

发送数据:

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

返回数据:

{"name": "张三","idNo": "340421190710145412","respMessage": "身份证信息匹配","respCode": "0000","province": "安徽省","city": "淮南市","county": "凤台县","birthday": "19071014","sex": "M","age": "111"
}

具体实现类:

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 83359fd73fe94948385f570e3c139105headers.put("Authorization", "APPCODE " + appcode);//根据API的要求,定义相对应的Content-Typeheaders.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* 下载** 相应的依赖请参照* 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);}}
}

如何使用阿里云接口对系统用户【身份证】实名认证相关推荐

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

    如今随着互联网产业的多元化发展,尤其是互联网金融,O2O,共享经济等新兴商业形式的兴起,企业对实名认证业务的数据形式和数据质量有了更高的需求.如今也衍生出银行卡实名认证业务,通过接口将[银行卡号.身份 ...

  2. 阿里云虚拟主机 mysql_阿里云虚拟主机数据库用户操作是怎样的

    阿里云虚拟主机数据库用户操作是怎样的,阿里云开启数据库. 对于大多数小型或初期项目来说,我们可能常用的做法是先将web.数据库全部安装在一起,后期根据需要来看是否将数据库单独迁移分离.传统物理服务器可 ...

  3. 阿里云接口实现发送短信验证码

    java 阿里云接口实现发送短信验证码 1. 阿里云后台配置短信相关 1.1 开通短信服务 1.2 添加模板签名 1.3 创建秘钥 1.4 短信需要后台授权--注意点 2 java--简单实现短信验证 ...

  4. 阿里云服务器镜像系统怎么选择?超详细教程

    阿里云服务器镜像怎么选择?云服务器操作系统镜像分为Linux和Windows两大类,Linux可以选择Alibaba Cloud Linux,Windows可以选择Windows Server 202 ...

  5. 阿里云接口实现短信发送java版

    阿里云接口实现短信发送java版 1. 前期准备 1.1.开通阿里云短信服务 1.2.申请签名管理和模板管理 1.3.获取Access_key和Access_secret 2.代码部分 2.1.在po ...

  6. 调用阿里云接口实现短信消息的发送源码——CSDN博客

    在调用阿里云接口之前首先需要购买接口,获得accessKeySecret,然后使用下列代码就可以直接调用了!! /** * @Title: TestPhoneVerification.java * @ ...

  7. 8月17日云栖精选夜读:用户体验再掀高潮_阿里云域名领跑用户体验

    原文地址 8月16日阿里云"贡献者荣誉榜单第四期"正式对外发布. 热点热议 用户体验再掀高潮,阿里云域名领跑用户体验 作者:仙游 云原生:云计算时代命题之终极解决方案 作者:博文视 ...

  8. 在阿里云搭建CENTOS7系统以及图形界面

    1. 搭建CentOS7操作系统服务器 首先要购买服务器,推荐学生认证可以获得好几个月的免费服务器.略去具体的过程. 阿里云默认的系统不是CentOS7,所以需要先将操作系统改成CentOS7. 在实 ...

  9. .Net 调用阿里云接口-识别车牌

    参考文档:生成URL - 阿里云视觉智能开放平台 - 阿里云 参考文档:https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeLicenseP ...

最新文章

  1. js设置div透明度
  2. java代码_阿里资深工程师教你如何优化 Java 代码!
  3. JS判断浏览器类型的方法【转】
  4. R语言应用实战系列(四)-Apriori算法的相关内容(附案例源代码)
  5. oracle底层执行顺序,select语句结构与执行顺序-Oracle
  6. Makefile(1):基本使用
  7. Linux二进制程序安装使用
  8. jquery ajax get 数组参数
  9. mysql5.7.28升级到5.7.29_MySQL升级5.7.29
  10. python识别cad图纸_手把手教你广联达软件如何识别天正CAD图纸
  11. git commit --amend 的使用记录
  12. python聊天机器人_用 Python 实现聊天机器人
  13. MYSQL修改编码为utf8无效往表中插入汉字还是失败的解决方法
  14. 用C语言写羊了个羊(一)
  15. DNS中的A记录和CNAME记录的区别
  16. 通过labview vision视觉模块写的带学习功能的OCR字符识别程序
  17. 数据分析--数据分析是什么?
  18. RTFM — man
  19. tif文件在html打开,电脑里tif文件怎么打开?你学会了吗
  20. 图的概念与主要类型、图模型的应用场景

热门文章

  1. Power Query 系列 (01) - Power Query 介绍
  2. 拼多多运营该怎么做你知道吗?
  3. php 点赞 代码,WordPress模板如何使用纯代码实现点赞功能?
  4. 基于51单片机的汽车倒车防撞报警系统
  5. 阿里云学生成长计划资格考试分享
  6. 2023进销存软件排行榜
  7. lombok小辣椒的使用
  8. wps linux 无法输入中文,WPS for linux 中不能切换到中文输入法
  9. warmup lr+CosineAnnealingLR策略
  10. 为了实现自动控制处理,需要计算机具有的基础条件是( ),计算机应用基础考试试卷(电大本科)...