import com.baidubce.http.ApiExplorerClient; import com.baidubce.http.AppSigner; import com.baidubce.http.HttpMethodName; import com.baidubce.model.ApiExplorerRequest; import com.baidubce.model.ApiExplorerResponse; // 身份证单双面识别 Java示例代码 public class RequestDemo { public static void main(String[] args) { String path = "http://gwgp-ksbcdfjvde6.n.bdcloudapi.com/idcard/ocr"; ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path); request.setCredentials("您的 access key", "您的 secret key"); request.addHeaderParameter("Content-Type", "application/x-www-form-urlencoded"); ApiExplorerClient client = new ApiExplorerClient(new AppSigner()); try { ApiExplorerResponse response = client.sendRequest(request); // 返回结果格式为Json字符串 System.out.println(response.getResult()); } catch (Exception e) { e.printStackTrace(); } } }
点击复制代码
正面
{
"msg": "",
"success": true,
"code": 200,
"data": {
"order_no": "634416423342575616",
"result": 0,
"side": "front",
"info": {
"number": "320382198912010000",
"address": "江苏省苏州市岔河镇东沙庄村黄庄190号",
"month": "12",
"nation": "汉",
"year": "1989",
"sex": "男",
"name": "赵某宁",
"day": "1"
},
"validity": {
"birthday": true,
"number": true,
"address": true,
"sex": true,
"name": true
},
"image_url": "http://shumai-picture.oss-cn-hangzhou.aliyuncs.com/%E5%95%86%E7%9B%9F/20.png"
}
}
反面
{
"msg": "",
"success": true,
"code": 200,
"data": {
"order_no": "634436714873622528",
"result": 0,
"side": "back",
"info": {
"authority": "杭州市公安局余杭分局",
"timelimit": "20180806-20380806"
},
"validity": {
"authority": true,
"timelimit": true
},
"image_url": null
}
}
{
"msg": "入参错误,
"success": false,
"code": 400,
"data": { }
}
格式为 JPG(JPEG),BMP,PNG,GIF,TIFF(小写也可以),宽和⾼大于 8px,⼩于等于4000px,大小不能超过1MB
字段名 | 说明 |
---|---|
success | 接口请求成功标识,true为成功,false为失败,失败情况下,会有对应描述和状态码 |
code | 成功为200,其它为失败状态码 |
msg | code对应的说明描述 |
data | 验证结果详细信息 |
order_no | 订单号 |
result | 扫描成功 0 ;扫描失败 1 |
side | 身份证方向信息。front 代表身份证正面(人像面), back 代表身份证反面(国徽面) |
info | 身份证信息,分正面和反面,见详情 |
validity | 扫描成功结果,分正面和反面,见详情 |
image_url | 身份证头像照片URL,(预留字段) |
字段名 | 说明 |
---|---|
name | 姓名 |
sex | 性别 |
nation | 民族 |
year | 出生年 |
month | 出生月 |
day | 出生日 |
address | 地址 |
number | 身份证号 |
authority | 签发机关 |
timelimit | 身份证有效期 |
上传身份证正面照片时返回字段 name , sex , nation , year , mouth , day , address ,number ,上传身份证背面照⽚时返回字段 authority 和 timelimit
字段名 | 说明 |
---|---|
birthday | 生日 |
number | 身份证号 |
address | 地址 |
sex | 性别 |
name | 姓名 |
authority | 签发机关 |
timelimit | 身份证有效期 |
上传身份证正面照片时返回字段 name , sex , birthday , address,number , 上传身份证背⾯照片时返回字段 authority 和 timelimit
当上传的图⽚是⾮身份证图⽚片时,系统不会报错,但这种情况下 validity 中 所有字段都会为 false ,请参考 validity 字段进行判断。
购买页面上有基于api接口的请求url,入参字段,响应接口结果,和返回错误码描述,请按照要求对接即可