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 = "https://sx-bkocr.api.bdymkt.com/bankcard/ocr";
ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);
request.setCredentials("您的 access key", "您的 secret key");
request.addHeaderParameter("Content-Type", "application/x-www-form-urlencoded");
request.addQueryParameter("imgUrl", "");
ApiExplorerClient client = new ApiExplorerClient(new AppSigner());
try {
ApiExplorerResponse response = client.sendRequest(request);
// 返回结果格式为Json字符串
System.out.println(response.getResult());
} catch (Exception e) {
e.printStackTrace();
}
}
}
点击复制代码
{
"code": "0",
"msg": "成功",
"isFee": 1,
"seqNo": "14r4nmbcaqpgwptdgpbwpxd5kgt7zucj",
"data": {
"result": 1, //扫描结果
"resultDesc": "识别成功,有数据", //扫描结果描述
"info": {
"bankcard": "6227002510680057642", //银行卡号
"bank": "建设银行" //银行名称
}
}
}
result 识别结果说明
1:识别成功,有数据
2:识别成功,无数据
3:识别失败,无法正确解析、未按要求传入参数、下载图片超时
{
"code": "1",
"msg": "参数错误",
"isFee": 0,
"seqNo": null,
"data": null
}