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; // 护照OCR Java示例代码 public class RequestDemo { public static void main(String[] args) { String path = "http://gwgp-eyjrhqs7ku2.n.bdcloudapi.com/passport_ocr/post"; 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": "694557636569468928",
"result": {
"log_id": 235509498581932799,
"words_result": {
"姓名": {
"words": "张三三",
"location": {
"top": 53,
"left": 124,
"width": 36,
"height": 11
}
},
"护照签发地点": {
"words": "青Q/INGHAI",
"location": {
"top": 126,
"left": 225,
"width": 78,
"height": 11
}
},
"签发机关": {
"words": "山东SHANDONG",
"location": {
"top": 173,
"left": 126,
"width": 83,
"height": 11
}
},
"护照号码": {
"words": "G06091123",
"location": {
"top": 20,
"left": 266,
"width": 75,
"height": 12
}
},
"签发日期": {
"words": "2002**30",
"location": {
"top": 148,
"left": 125,
"width": 75,
"height": 11
}
},
"出生地点": {
"words": "/",
"location": {
"top": 101,
"left": 226,
"width": 124,
"height": 12
}
},
"生日": {
"words": "19751124",
"location": {
"top": 126,
"left": 125,
"width": 75,
"height": 12
}
},
"国家码": {
"words": "CHN",
"location": {
"top": 19,
"left": 169,
"width": 21,
"height": 8
}
},
"有效期至": {
"words": "20071229",
"location": {
"top": 148,
"left": 225,
"width": 77,
"height": 11
}
},
"姓名拼音": {
"words": "ZHANG,SANSAN",
"location": {
"top": 77,
"left": 125,
"width": 76,
"height": 12
}
},
"性别": {
"words": "男/M",
"location": {
"top": 102,
"left": 125,
"width": 26,
"height": 11
}
}
},
"words_result_num": 11
}
}
}
{
"msg": "入参错误,
"success": false,
"code": 400,
"data": { }
}
购买页面上有基于api接口的请求url,入参字段,响应接口结果,和返回错误码描述,请按照要求对接即可