广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >基于聚合数据的身份证实名认证API接口调用示例-Java版
  • 659
分享到

基于聚合数据的身份证实名认证API接口调用示例-Java版

2024-04-02 19:04:59 659人浏览 独家记忆
摘要

一、申请接口 通过https://www.juhe.cn/docs/api/id/103自助申请开通接口,获取API请求KEY 二、请求参数 名称 是否必填 说明 idcard 是 身份证号码 realname 是 姓名

一、申请接口

通过https://www.juhe.cn/docs/api/id/103自助申请开通接口,获取API请求KEY

二、请求参数

名称 是否必填 说明
idcard 身份证号码
realname 姓名
orderid 传1时返回单号,默认不返回单号(加密版必返回单号)
key 在个人中心->我的数据,接口名称上方查看

三、Java示例代码

package com.jefferson.utils.interfaceDemo.juheDemo;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.Http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;


public class idcard_103 {

    //设置超时时间为5秒
	public static RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build();
	// 配置您申请的KEY,在个人中心->我的数据,接口名称上方查看
	public static final String APPKEY = "";
       //明文查询地址
	public static String query_url = "http://op.juhe.cn/idcard/query?key=" + APPKEY;
       //加密查询地址
	public static String queryEncry_url = "http://op.juhe.cn/idcard/queryEncry?key=" + APPKEY;
   
      //主方法
	public static void main(String[] args) throws Exception {

		// ----------------------身份证实名查询-----------------------------------------------------------------------
		// String realname = "";// 姓名
		// String idcard = "";// 身份证
		// int type = 1;// 普通版,不需要加密
		// Map<String, Object> params = new HashMap<>();
		// params.put("realname", realname);
		// params.put("idcard", idcard);

		// ----------------------身份证实名查询(加密版)-----------------------------------------------------------------------
		String realname = "张三";// 姓名
		String idcard = "32072119970602561X";// 身份证
		String openid = "";// 个人中心查询
		String key = MD5(openid).substring(0, 16);//取前16位作为加密密钥
		int type = 2;// 加密版本
		realname = SecurityAESTool.encrypt(realname, key);//加密姓名
		idcard = SecurityAESTool.encrypt(idcard, key);//加密身份证
		Map<String, Object> params = new HashMap<>();//组合参数
		params.put("realname", realname);
		params.put("idcard", idcard);
                //请求接口
		String result = queryResult(params, type);
                //打印结果
		System.out.println(result);

	}

	

	public static String queryResult(Map<String, Object> params, int type) throws Exception {

		CloseableHttpClient httpClient = HttpClients.createDefault();
		CloseableHttpResponse response = null;
		String result = null;
		String url = query_url;
		switch (type) {
		      case 2:
			url = queryEncry_url;
			break;
		}
		try {
			url = new StringBuffer(url).append("&").append(urlencode(params)).toString();
			HttpGet httpget = new HttpGet(url);
			httpget.setConfig(config);
			response = httpClient.execute(httpget);
			HttpEntity resEntity = response.getEntity();
			if (resEntity != null) {
				result = IOUtils.toString(resEntity.getContent(), "UTF-8");
			}
			EntityUtils.consume(resEntity);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			response.close();
			httpClient.close();
		}
		return result;
	}



	// 将map型转为请求参数型

	public static String urlencode(Map<String, ?> data) {
		StringBuilder sb = new StringBuilder();
		for (Map.Entry<String, ?> i : data.entrySet()) {
			try {
				sb.append(i.geTKEy()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		String result = sb.toString();
		result = result.substring(0, result.lastIndexOf("&"));
		return result;
	}



	
	public static String MD5(String data) {
		StringBuffer md5str = new StringBuffer();
		byte[] input = data.getBytes();
		try {
			// 创建一个提供信息摘要算法的对象,初始化为md5算法对象
			MessageDigest md = MessageDigest.getInstance("MD5");
			// 计算后获得字节数组
			byte[] buff = md.digest(input);
			// 把数组每一字节换成16进制连成md5字符串
			int digital;
			for (int i = 0; i < buff.length; i++) {
				digital = buff[i];
				if (digital < 0) {
					digital += 256;
				}
				if (digital < 16) {
					md5str.append("0");
				}
				md5str.append(Integer.toHexString(digital));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return md5str.toString();
	}
}

AES工具类,加密解密

package com.jefferson.utils.interfaceDemo.juheDemo;

import org.apache.commons.codec.binary.Base64;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class SecurityAESTool {

	
	public static String encrypt(String str, String key) {
		byte[] crypted = null;
		try {
			SecretKeySpec skey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
			Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
			cipher.init(Cipher.ENCRYPT_MODE, skey);
			String enStr = str;
			crypted = cipher.doFinal(enStr.getBytes("UTF-8"));
		} catch (Exception e) {
			System.out.println(e.toString());
		}
		String body = new String(Base64.encodeBase64(crypted));
		return body;
	}

	
	public static String decrypt(String input, String key) {
		byte[] output = null;
		String body = null;
		if (input == null || key == null) {
			return null;
		}
		try {
			SecretKeySpec skey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
			Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
			cipher.init(Cipher.DECRYPT_MODE, skey);
			byte[] b = Base64.decodeBase64(input);
			// 解密
			output = cipher.doFinal(b);
			body = new String(output, "UTF-8");
		} catch (Exception e) {
			System.out.println(e.toString());
		}
		return body;
	}

	public static void main(String[] args) throws UnsupportedEncodingException {
		String key = "1111111111111111";// 密钥
		String data = "123456"; // 明文

		String enStr = SecurityAESTool.encrypt(data, key);
		System.out.println(enStr);
		System.out.println(URLEncoder.encode(enStr, "UTF-8"));
	}
}

四、返回参数说明

名称 类型 说明
error_code int 返回码
reason string 返回说明
result JSONobject 返回结果集
res int 属result,匹配详情,1匹配,2不匹配
orderid string 属result,单号

返回示例:

{
    "reason": "成功",
    "result": {
        "realname": "***",
        "idcard": "******************",
        "orderid":"J103201911121607589548",[/color]
        "res": 1 
    },
    "error_code": 0
}

--结束END--

本文标题: 基于聚合数据的身份证实名认证API接口调用示例-Java版

本文链接: https://www.lsjlt.com/news/99288.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 基于聚合数据的身份证实名认证API接口调用示例-Java版
    一、申请接口 通过https://www.juhe.cn/docs/api/id/103自助申请开通接口,获取API请求KEY 二、请求参数 名称 是否必填 说明 idcard 是 身份证号码 realname 是 姓名 ...
    99+
    2022-10-22
  • 基于聚合数据的身份证实名认证API接口调用示例-PHP版
    一、申请接口 通过https://www.juhe.cn/docs/api/id/103自助申请开通接口,获取API请求KEY。 二、用示例代码PHP //如需请求加密接口,加密方式请参考https://www.sdk.cn/detail...
    99+
    2022-10-22
  • 基于聚合数据的验证码短信API接口调用示例-PHP版
    前期准备 根据运营商的要求,目前此接口只对实名认证的企业用户开放使用,所以在使用之前请确保您是实名认证的企业用户 申请接口,你可以在个人中心 ➡️ 数据中心 ➡️ 我的API 模块看到此接口的调用凭证请求key 购买数据的请求次...
    99+
    2022-10-22
  • 基于聚合数据的短信验证码(486)接口调用示例-JAVA版
    前言 接口地址:https://www.juhe.cn/docs/api/id/486 依赖 <dependency> <groupId>net.sf.json-lib<...
    99+
    2022-10-22
  • 基于聚合数据的短信API接口(54)调用示例-Java版
    前期准备 根据运营商的要求,目前此接口只对实名认证的企业用户开放使用,所以在使用之前请确保您是实名认证的企业用户 申请接口,你可以在个人中心 ➡️ 数据中心 ➡️ 我的API 模块看到此接口的调用凭证请求key 购买数据的请求次...
    99+
    2022-10-22
  • 基于聚合数据的短信API接口调用示例-Python版
    一、申请接口 通过https://www.juhe.cn/docs/api/id/54自助申请开通短信API,获得接口请求Key。(目前接口暂只支持企业类用户使用) 申请后,在个人中心提交短信模板,聚合官方已经提供了多个常用模板,可以快捷申...
    99+
    2022-10-22
  • 基于聚合数据的短信API接口(54)调用示例-PHP版
    前期准备 根据运营商的要求,目前此接口只对实名认证的企业用户开放使用,所以在使用之前请确保您是实名认证的企业用户 申请接口,你可以在个人中心 ➡️ 数据中心 ➡️ 我的API 模块看到此接口的调用凭证请求key 购买数据的请求次...
    99+
    2022-10-22
  • 基于聚合数据的老黄历接口调用示例-JAVA版
    本文介绍聚合数据的老黄历接口的使用 依赖 <dependency> <groupId>net.sf.json-lib</groupId> ...
    99+
    2022-10-22
  • 基于聚合数据的笑话大全接口调用示例-JAVA版
    接口地址 接口地址 前言 本文主要介绍笑话大全接口的调用示例 依赖 <dependency> <groupId>net.sf.json-lib</groupId> ...
    99+
    2022-10-22
  • 基于node.js的聚合数据的短信API接口调用示例
    前期准备 根据运营商的要求,目前此接口只对实名认证的企业用户开放使用,所以在使用之前请确保您是实名认证的企业用户 申请接口,你可以在个人中心 ➡️ 数据中心 ➡️ 我的API 模块看到此接口的调用凭证请求key 接口申请开通入口...
    99+
    2022-10-22
  • 基于聚合数据的老黄历接口调用示例-PHP版
    前期准备 接口申请,申请地址—“聚合数据”官网:https://www.juhe.cn/docs/api/id/65 你可以在个人中心 ➡️ 数据中心 ➡️ 我的API 模块看到此接口的调用凭证请求key 接口说明 免费使用,根据会员...
    99+
    2022-10-22
  • 基于聚合数据的老黄历接口调用示例-Python版
    前期准备 接口申请,申请地址—“聚合数据”官网:https://www.juhe.cn/docs/api/id/65 你可以在个人中心 ➡️ 数据中心 ➡️ 我的API 模块看到此接口的调用凭证请求key 接口说明 免费使用,根据会员...
    99+
    2022-10-22
  • 基于聚合数据的笑话大全接口调用示例-PHP版
    前期准备 申请接口,你可以在个人中心 ➡️ 数据中心 ➡️ 我的API 模块看到此接口的调用凭证请求key 请仔细阅读官网的接口文档,这是聚合数据与开发者的约定,它将有助于您对接口业务的理解,从而顺利地开展开发工作 1.随机获取笑话接口...
    99+
    2022-10-22
  • 基于聚合数据的银行卡四元素校验API接口调用示例-PHP版
    一、申请接口 通过https://www.juhe.cn/docs/api/id/213自助申请开通短信API,获得接口请求Key。(目前接口暂只支持企业类用户使用) 二、PHP请求代码示例 // 请求的接口URL $apiUrl = ...
    99+
    2022-10-22
  • 基于聚合数据的全国车辆违章的接口示例-Java版
    开发环境 Jdk 1.8 Maven 3.6.1 IDE IntelliJ IDEA 前期准备 申请接口全国车辆违章 购买次数(免费和有赠送次数的可以先行测试) 阅读接口文档 maven依赖 <depen...
    99+
    2022-10-22
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作