在企业招聘背景调查、金融信贷风险评估、公务员政审材料审核、高校学籍管理以及在线教育平台实名认证等关键业务场景中,准确验证个人学历真实性已成为防范欺诈、提升决策质量的核心环节。
由天远API推出的“学历信息查询API”(接口标识:IVYZ9A2B),能够基于姓名与身份证号,快速返回用户在高等教育阶段的完整学历履历,包括学历层次、院校类型、学习形式、入学/毕业时间及专业信息,并支持多段学习经历的时间线回溯。
本文专为 Java 开发者打造,将从接口安全机制、请求构造、加解密实现到响应解析进行全流程拆解,帮助您在 Spring Boot、微服务或传统 Java EE 系统中高效集成该能力。
https://apitest.tianyuanapi.com/api/v1/IVYZ9A2B?t=<13位时间戳>Access-Id,请求体中的 data 字段为 AES-128-CBC 加密后的 Base64 字符串⚠️ 注意:以下代码依赖 Bouncy Castle 提供 PKCS7 填充支持。
curl -X POST '<https://apitest.tianyuanapi.com/api/v1/IVYZ9A2B?t=1730505600000>' \\
-H 'Access-Id: YOUR_ACCESS_ID' \\
-H 'Content-Type: application/json' \\
-d '{"data": "UkVQTEFDRV9XSVRIX0VOQ1JZUFRFRF9EQVRB"}'import org.bouncycastle.jce.provider.BouncyCastleProvider;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.Security;
import java.util.Base64;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Map;
import java.util.HashMap;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;
public class TianYuanEducationApi {
static {
Security.addProvider(new BouncyCastleProvider());
}
private static final String ACCESS_ID = "your_access_id";
private static final String ACCESS_KEY_HEX = "a1b2c3d4e5f67890a1b2c3d4e5f67890"; // 32位十六进制
public static byte[] hexToBytes(String hex) {
int len = hex.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
+ Character.digit(hex.charAt(i + 1), 16));
}
return data;
}
public static String encrypt(String plainText, String hexKey) throws Exception {
byte[] key = hexToBytes(hexKey);
byte[] iv = new byte[16];
new java.security.SecureRandom().nextBytes(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv));
byte[] encrypted = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
byte[] combined = new byte[iv.length + encrypted.length];
System.arraycopy(iv, 0, combined, 0, iv.length);
System.arraycopy(encrypted, 0, combined, iv.length, encrypted.length);
return Base64.getEncoder().encodeToString(combined);
}
public static String decrypt(String base64Data, String hexKey) throws Exception {
byte[] combined = Base64.getDecoder().decode(base64Data);
byte[] iv = new byte[16];
byte[] ciphertext = new byte[combined.length - 16];
System.arraycopy(combined, 0, iv, 0, 16);
System.arraycopy(combined, 16, ciphertext, 0, ciphertext.length);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(hexToBytes(hexKey), "AES"), new IvParameterSpec(iv));
byte[] decrypted = cipher.doFinal(ciphertext);
return new String(decrypted, StandardCharsets.UTF_8);
}
public static Map<String, Object> queryEducation(String name, String idCard) {
String url = "<https://apitest.tianyuanapi.com/api/v1/IVYZ9A2B?t=>" + Instant.now().toEpochMilli();
String jsonPayload = String.format("{\\"name\\":\\"%s\\",\\"id_card\\":\\"%s\\"}", name, idCard);
try {
String encryptedData = encrypt(jsonPayload, ACCESS_KEY_HEX);
HttpHeaders headers = new HttpHeaders();
headers.set("Access-Id", ACCESS_ID);
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Map<String, String>> request = new HttpEntity<>(Map.of("data", encryptedData), headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Map> response = restTemplate.postForEntity(url, request, Map.class);
Map<String, Object> resp = response.getBody();
if (!"200".equals(resp.get("err_code"))) {
System.err.println("API业务错误: " + resp.get("err_msg"));
return null;
}
String decrypted = decrypt((String) resp.get("data"), ACCESS_KEY_HEX);
return new ObjectMapper().readValue(decrypted, Map.class);
} catch (Exception e) {
System.err.println("调用失败: " + e.getMessage());
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
Map<String, Object> result = queryEducation("张三", "110101199001011234");
if (result != null) {
System.out.println("学历查询成功: " + result);
}
}
}💡 依赖:implementation 'org.bouncycastle:bcprov-jdk15on:1.70' + Jackson
天远API 的响应体在解密后呈现清晰的嵌套结构。顶层包含全局状态码 err_code 与加密数据 data;解密后的 data 对象内含:
query_id:唯一查询流水号,用于对账与日志追踪;education_background:学历信息主容器,其下包含:code:业务状态码(如 "9100" 表示有结果,"1000" 表示无记录);msg:中文状态描述;data:学历记录数组,可能为空或多条,按毕业时间倒序排列。每条学历记录是一个扁平对象,包含6个关键字段,完整刻画一段高等教育经历。值得注意的是,时间字段(ksrq/jsrq)采用紧凑的 YYMM 格式,需在业务层转换为标准日期以便分析。
字段名 | 含义 | 说明 |
|---|---|---|
| 全局状态码 |
|
| 全局状态描述 | 如“缺少Access-Id”、“IP未授权”等 |
| 加密业务数据 | 需使用 Access Key 解密 |
字段名 | 含义 | 说明 |
|---|---|---|
| 查询流水号 | 唯一标识本次调用,可用于审计 |
| 业务结果码 |
|
| 业务提示信息 | 如“查询成功有结果” |
| 学历记录列表 | 数组类型,可能为空 |
字段名 | 含义 | 说明 |
|---|---|---|
| 学历层次 | 如“大学专科”、“硕士研究生” |
| 院校类型 | 如“普通高校”、“成人高校”,部分返回“其他” |
| 学习形式 | 如“普通全日制”、“非全日制” |
| 入学时间 |
|
| 毕业时间 |
|
| 专业名称 | 如“计算机科学与技术”,部分为“其他” |
1. 业务场景落地
2. 数据深度利用建议
ksrq 与 jsrq 转换为 LocalDate,计算学制时长,识别“2年读完本科”等异常模式。xl 与 xxxs 构建用户教育画像标签,用于人才推荐或精准营销。3. 系统集成最佳实践
query_id 与业务订单关联,便于后续对账与问题排查。通过天远API的标准化接口,企业可将学历验证从“纸质证明+人工核对”升级为“实时自动化”,显著提升效率与准确性。
本文详细介绍了如何在 Java 环境中安全调用学历信息查询API(IVYZ9A2B),涵盖从加密请求构造、HTTPS 调用到响应解密与解析的完整链路。该接口由天远API提供,具备高安全性(AES-128-CBC + HTTPS)、高准确率(对接权威学历数据库)和无频率限制等优势,适用于招聘、金融、政务等多类高价值场景。
对于 Java 开发者,建议封装为独立 Service 组件,并做好异常熔断与日志监控。未来,可进一步结合学位信息、学信网验证码等多维数据,构建更强大的身份核验体系。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。