demo使用步骤
1.修改配置文件
2.执行demo类中的main方法
一、配置文件
com.nlp.ctiddemo.config.CtidConfig
```
// 服务器地址
public static String serverUrl = "https://open.digitalcitizen.com.cn:7280/idauth";
// 应用id
public static String appId = "";
// 应用密钥
public static String appSecret = "";
// 应用加密密钥
public static String key = "";
```
二、demo入口
com.nlp.ctiddemo.app.Demo
1.身份证2项信息demo
```
public static void runDemo() {
VerifyService verifyService = new VerifyService();
String authMode = "0x40";
String name = "";
String number = "";
String apply = verifyService.apply(authMode, null);
System.out.println("申请接口返回的数据:" + apply);
CommonResponse applyResponse = JSON.parseObject(apply, CommonResponse.class);
String bizSerialNum = (String) ((Map) applyResponse.getData()).get("bizSerialNum");
String request = verifyService.request(bizSerialNum, authMode, null, name, number);
System.out.println("认证接口返回的数据:" + request);
}
```
2.人脸+身份证2项信息
```
public static void runDemo2() {
VerifyService verifyService = new VerifyService();
String authMode = "0x42";
String name = ";
String number = "";
String photoData = "";
String apply = verifyService.apply(authMode, null);
System.out.println("申请接口返回的数据:" + apply);
CommonResponse applyResponse = JSON.parseObject(apply, CommonResponse.class);
String bizSerialNum = (String) ((Map) applyResponse.getData()).get("bizSerialNum");
String request = verifyService.request(bizSerialNum, authMode, photoData, name, number);
System.out.println("认证接口返回的数据:" + request);
}
```
三、接口调用服务方法
1.获取token方法
com.nlp.ctiddemo.service.TokenService.getAccessToken()
```
public CommonResponse getAccessToken(String appId, String appSecret) {
CommonResponse commonResponse = tokenMap.get(appId + appSecret);
try {
if (commonResponse != null) {
Map<String, Object> data = (Map<String, Object>) commonResponse.getData();
Long expireTime = (Long) data.get("expireTime");
if (expireTime == null || expireTime < System.currentTimeMillis()) {
commonResponse = null;
}
}
} catch (Exception e) {
commonResponse = null;
}
if (commonResponse != null) {
return commonResponse;
}
Map<String, String> data = new HashMap<>();
data.put("appId", appId);
data.put("appSecret", appSecret);
String response = HttpUtil.post(CtidConfig.serverUrl + "/auth/getCode", JSON.toJSONString(data), null);
commonResponse = JSON.parseObject(response, CommonResponse.class);
if ("0".equals(commonResponse.getCode())) {
tokenMap.put(appId + appSecret, commonResponse);
}
return commonResponse;
}
```
2.身份认证申请接口
com.nlp.ctiddemo.service.VerifyService.apply()
```
public String apply(String authMode, String deviceId) {
String accessToken = tokenService.getAccessToken();
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", accessToken);
headers.put("appId", CtidConfig.appId);
Map<String, String> body = new HashMap<>();
if (StringUtils.isNotBlank(deviceId)) {
body.put("deviceId", deviceId);
}
String jsonData = JSON.toJSONString(body);
String encryptString = AESUtil.encryptAES(jsonData, CtidConfig.key);
String post = HttpUtil.post(CtidConfig.serverUrl + "/validateIdentity/apply/" + authMode, encryptString, headers);
return AESUtil.decryptAES(post, CtidConfig.key);
}
```
3.身份认证请求接口
com.nlp.ctiddemo.service.VerifyService.request()
```
public String request(String bizSerialNum, String authMode, String photoData, String name, String number) {
String accessToken = tokenService.getAccessToken();
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", accessToken);
headers.put("appId", CtidConfig.appId);
Map<String, String> body = new HashMap<>();
body.put("bizSerialNum", bizSerialNum);
body.put("authMode", authMode);
body.put("name", name);
body.put("number", number);
if (StringUtils.isNotBlank(photoData)) {
body.put("photoData", photoData);
}
String jsonData = JSON.toJSONString(body);
String encryptString = AESUtil.encryptAES(jsonData, CtidConfig.key);
String post = HttpUtil.post(CtidConfig.serverUrl + "/validateIdentity/request/" + authMode, encryptString, headers);
return AESUtil.decryptAES(post, CtidConfig.key);
}
```
- CTID身份认证服务能力接入文档
- 身份认证服务介绍
- 身份认证能力介绍
- 名词解释
- 产品定价
- 计费说明
- 接入集成介绍
- API接口列表
- 鉴权接口
- 身份认证接口
- 集成示例
- 集成示例总图
- 客户端加密方式接入示例
- 安卓客户端示例
- IOS客户端示例
- Java服务端示例
- PHP服务端示例
- 服务端加密接入方式示例
- Java服务端加密示例
- PHP服务端加密示例
- 管理系统介绍
- 登录
- 机构应用信息
- 身份验证日志
- 常见问题
- 客户端加密接入方式FAQ
- Android端FAQ
- IOS端FAQ
- JAVA服务端FAQ
- PHP服务端FAQ
- 服务端加密接入方式FAQ
- JAVA服务端加密FAQ
- PHP服务端加密FAQ
- 平台FAQ
- 服务端常见异常
- 资料下载
- 客户端加密接入方式DEMO源码
- 服务端加密接入方式DEMO源码