【实名认证接口】身份证实名认证接口 /姓名和号码二要素一致性查询-【公安授权/实时更新】【最新版】-云市场-阿里云点击上面进入阿里实名认证api

来到这个界面之后,(测试的话直接领取免费的),购买完成会拿到AppKey和AppCode(实名认证这里没有用到AppKey)。

回到上面购买页面,往下拉会看到测试代码

也就是这个代码

package com.sxskz;import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;import java.util.HashMap;
import java.util.Map;@Slf4j
public class Shiming {public static void main(String[] args) {String host = "http://checkone.market.alicloudapi.com";String path = "/chinadatapay/1882";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("idcard", "身份证码");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.getEntity().toString());
//            System.out.println(response.toString());log.info(EntityUtils.toString(response.getEntity())+"333333333333");//获取response的body//System.out.println(EntityUtils.toString(response.getEntity()));} catch (Exception e) {e.printStackTrace();}}
}

这里还缺少一个工具类HttpUtils这里直接给代码

package com.sxskz;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);}}
}

在pom中加入依赖

        <dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency>

新建个类把代码复制下来。然后测试,一般有三种结果

验证成功

验证失败

还有一种是验证异常 ,这里就不演示了。

以上就是阿里实名认证的全过程了。(出错了可以把错误打在评论区)

阿里实名认证Java版(详细教程)相关推荐

  1. mysql安装 linux 5.6,Linux安装MySql5.6版详细教程

    Linux安装MySql5.6版详细教程 Szx • 2019 年 02 月 26 日 首先下载mysql,然后上传到 /usr/local/tmp/下(如果没有这个目录创建一个即可或者存放其他目录) ...

  2. Java log4j详细教程

    Java log4j详细教程 日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供方便的日志记录.在apache网站:jakarta.apache.org/l ...

  3. 阿里云服务器购买详细教程以及建站入门基础教程

    本系列教程汇总: 买了域名一定需要备案吗?什么情况下不需要备案? 如何购买阿里云服务器(图文教程) 如何购买阿里云香港服务器(图文教程) 如何购买阿里云学生服务器(图文教程) 阿里云是国内第一大云服务 ...

  4. 如何购买阿里云服务器?阿里云服务器购买详细教程

    阿里云是国内第一大云服务器厂商,所以往往我会推荐公司客户优先选择阿里云.毕竟稳定,技术可靠和安全是第一优先考虑的因素.现在来详细介绍下阿里云服务器的选购图文操作步骤. 一.选购阿里云的三种方式 根据站 ...

  5. iPad3/iPad2/iPad 5.1.1完美越狱WIN版详细教程

    Absinthe 2.0.4 更新  最新更新:5月30日,iOS 5.1.1完美越狱工具Absinthe 2.0.4再次更新!完美支持iPad2,4 iOS 5.1.1 Absinthe 2.0.4 ...

  6. 内部名称解析设置阿里云私有 DNS 区域,针对于阿里云国际版经验教程

    什么是阿里云 DNS? 阿里云 DNS 是一种安全.快速.可靠的 DNS 服务.阿里云 DNS 可以接收 100% 的 SLA,确保应用程序随时准备好为全球流量提供服务.该服务还利用全球部署的节点来确 ...

  7. java release_使用release自动打包发布正式版详细教程

    release正常打包发布流程按照如下几个阶段: Check that there are no uncommitted changes in the sources Check that there ...

  8. 阿里云国际站版注册教程

    随着阿里云走出中国走向世界,立志要做自己的云计算和要成为世界第4朵云,所以阿里云也相继推出了阿里云之国际站,阿里云国际站宗旨是向世界展示中国企业在云计算.云存储等各方面的伟大成就和傲人的成绩,当然也是 ...

  9. 我的世界java版按键教程视频_我的世界(电脑Java版)execute指令教程

    注:该教程基于Java V1.16.3   通常可以兼容1.13+的版本 1.9-1.12可能会有不兼容,出现问题可以在评论区提问.如果1.12及以下的玩家较多,以后会专门出一个针对1.12及以下的教 ...

最新文章

  1. 装箱与拆箱及其性能损失问题
  2. 【深度学习入门到精通系列】Mean Iou
  3. odps结合mysql统计
  4. 使用Java和JSF构建一个简单的CRUD应用
  5. 一文读懂clickhouse的世界
  6. 正则表达式(思维导图速查版)
  7. selenium 在pycharm中安装selenium
  8. 物理路径,相对路径,绝对路径以及根目录
  9. Vue实战项目开发--首页开发
  10. 基于控制台的老虎机Java Demo
  11. 0068-【数据质控】-Illumina的Barcode的设计用于16S测序
  12. cyberduck 源代码学习记录一,编译源代码 build for window
  13. 全国公众服务电话号码
  14. Android肝帝战纪之Fragmentation的使用(单Activity+多Fragment设计)
  15. zk 系四大 L2 协议大 PK:进度、异同和生态
  16. 技术科普:虚拟现实系统
  17. 医美面膜商城小程序开发,助力企业数字化转型
  18. 删除 Bonjour service服务
  19. MATLAB之拉氏变换
  20. 66句震撼人心的禅语(转)

热门文章

  1. Cent OS 7 的日常操作
  2. Futaba M11BT222A VFD(主控PT6311)STC51单片机驱动程序
  3. poj2391 Ombrophobic Bovines 拆点连边要注意
  4. 年终总结:2021年最有用的数据清洗 Python 库
  5. 线性动态规划-文件排版
  6. Redis学习笔记·
  7. qemu内存模型(2) 实现说明
  8. sap系统中的batch_SAP 批次管理(Batch management)配置介绍
  9. 什么?你居然不会微信分身
  10. Electron:前端人的最佳跨平台解决方案