/ocr/parse_bankcard_ocr_result

1.接口描述

对APP端银行卡的OCR扫描结果进行解析,并返回解析结果,本接口需要配合APP端SDK使用。

请求方式

POST

请求 URL

https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result

2.请求参数

字段 类型 必需 描述
api_id string API 账户
api_secret string API 密钥
file file APP端银行卡或身份证OCR识别结果文件
return_image string 默认为false, 不返回原图

3.返回参数

字段 类型 说明
status string 返回状态,正常为 OK,其他值表示失败,详见错误码
valid boolean 识别结果是否全部有效 ,是为1, 否为0
layout string 银行卡方向,未知方向为0,水平方向为1,垂直方向为2
num_item string 银行卡号,详情见num_item 数组中字段的结构
bankname string 银行名称
bankid string 银行编号
cardname string 卡片名称
cardtype string 卡片类型
holder string 持卡人(暂时无效)
date string 有效日期(暂时无效)
corners string 检测到银行卡的四个角点:左上、右上、左下、右下
image_crop string 裁剪后只包含银行卡的图像
code string 公有云返回码
version string 版本
request_id string 请求id

num_item 数组中字段的结构为:

字段 类型 说明
valid boolean 识别结果是否有效 ,是为1, 否为0
digit_count string 银行卡号的号码数
digit_content string 银行卡号的号码
digit_pos string 银行卡号每个数字的位置(相对矫正后的图像)
rect string 银行卡号的位置(相对矫正后的图像)

返回结果示例:

{
  "status": "OK",
  "valid": 1,
  "layout": 1,
  "num_item": {
    "valid": 1,
    "digit_count": 19,
    "digit_content": "622848001xxxx102419",
    "digit_pos": [
      {
        "left": 61,
        "top": 288,
        "right": 84,
        "bottom": 335
      } //此处为19个元素的数组
    ],
    "rect": {
      "left": 75,
      "top": 288,
      "right": 681,
      "bottom": 335
    }
  },
  "bankname": "中国农业银行",
  "bankid": "1030000",
  "cardname": "金穗通宝卡(银联卡)",
  "cardtype": "借记卡",
  "holder": "",
  "date": "",
  "corners": [
    {
      "x": 135.72572326660156,
      "y": 262.80316162109375
    },
    {
      "x": 851.33642578125,
      "y": 196.20187377929688
    },
    {
      "x": 163.607666015625,
      "y": 724
    },
    {
      "x": 901.0619506835938,
      "y": 676.1900634765625
    }
  ],
  "image_crop": "......", //如果return_image设置为true,此处会返回图片的base64编码值
  "code": 1000,
  "version": "0.1.0",
  "request_id": "68b07ae90ac44d21a1dc2acd288a69b1"
}

4.错误码

状态码 status 字段 说明
400 ENCODING_ERROR 参数非UTF-8编码
400 INVALID_ARGUMENT 请求参数错误,具体原因见 reason 字段内容
400 PARSE_BANKCARD_ERROR 上传的加密文件有误
400 SAVE_BANKCARD_IMG_ERROR 存储图片错误
401 UNAUTHORIZED 账号或密钥错误
401 KEY_EXPIRED 账号过期,具体情况见 reason 字段内容
403 RATE_LIMIT_EXCEEDED 调用频率超出限额
403 NO_PERMISSION 无调用权限
403 OUT_OF_QUOTA 调用次数超出限额
404 NOT_FOUND 请求路径错误
500 INTERNAL_ERROR 服务器内部错误

5.输入示例

  • cURL 样例
curl -X POST "https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result?api_id=ID&api_secret=SECRET" \
  -F file=@/PATH/TO/OCR_FILE
  • HTTPie 样例
http -f POST "https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result?api_id=ID&api_secret=SECRET" \
  file=@/PATH/TO/OCR_FILE
  • C++ 样例
#include <iostream>
#include <cstring>
#include <exception>
#include <curl/curl.h>
#include <json/json.h>

using namespace std;
size_t callback(char *ptr, size_t size, size_t nmemb, string &stream){

  size_t sizes = size*nmemb;
  string temp(ptr,sizes);
  stream += temp;
  return sizes;
}
int main( int argv, char * argc[] ){

  CURL *curl;
  CURLM *multi_handle;
  CURLcode res;
  long code;
  string stream;
  struct curl_httppost *formpost = NULL;
  struct curl_httppost *lastptr = NULL;
  struct curl_slist *headerlist = NULL;

  try{

    curl_global_init(CURL_GLOBAL_DEFAULT);
    curl = curl_easy_init();

    if( curl ){

      curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"api_id",
                  CURLFORM_COPYCONTENTS, "ID",CURLFORM_END);
      curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"api_secret",
                  CURLFORM_COPYCONTENTS, "SECRET",CURLFORM_END);
      curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"file",
                  CURLFORM_FILE, argc[1], CURLFORM_END);

      curl_easy_setopt(curl, CURLOPT_URL, "https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result");
      curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);

      #ifdef SKIP_PEER_VERIFICATION
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
      #endif
      #ifdef SKIP_HOSTNAME_VERIFICATION
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
      #endif

      res = curl_easy_perform(curl);

      if( res != CURLE_OK ){
        cout<<"curl_easy_perform() failed:"<<curl_easy_strerror(res)<<endl;
        return -1;
      }
      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
      Json::Value res_data;
      Json::Reader *reader = new Json::Reader(Json::Features::strictMode());
      if(!reader->parse(stream, res_data)){
        cout<<"parse error";
        return -1;
      }
      cout<<"HTTP Status Code:"<<code<<endl;
      cout<<res_data<<endl;
      curl_easy_cleanup(curl);
  }
    curl_global_cleanup();

  }catch(exception &ex){
    cout<<"curl exception:"<<ex.what()<<endl;
  }
}
  • Java 样例
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class httpClientPost {

    public static final String api_id = "ID"; 
    public static final String api_secret = "SECRET"; 
      public static final String type = "BANKCARD"; 
    public static final String filepath = "C:/Users/bankcard.proto";//OCR文件路径
    public static final String POST_URL = "https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result";

    public static void HttpClientPost() throws ClientProtocolException, IOException {
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost post = new HttpPost(POST_URL);
      FileBody fileBody = new FileBody(new File(filepath));
      StringBody id = new StringBody(api_id);
      StringBody secret = new StringBody(api_secret);
      MultipartEntity entity = new MultipartEntity();
      entity.addPart("file", fileBody);
      entity.addPart("api_id", id);
      entity.addPart("api_secret", secret);
      post.setEntity(entity);

      HttpResponse response = httpclient.execute(post);
      if (response.getStatusLine().getStatusCode() == 200) {
          HttpEntity entitys = response.getEntity();
          BufferedReader reader = new BufferedReader(
          new InputStreamReader(entitys.getContent()));
        String line = reader.readLine();
        System.out.println(line);
      }else{
        HttpEntity r_entity = response.getEntity();
        String responseString = EntityUtils.toString(r_entity);
        System.out.println("错误码是:"+response.getStatusLine().getStatusCode()+"  "+response.getStatusLine().getReasonPhrase());
        System.out.println("出错原因是:"+responseString);
        //你需要根据出错的原因判断错误信息,并修改
      }

      httpclient.getConnectionManager().shutdown();
    }


  public static void main(String[] args) throws ClientProtocolException, IOException {
    HttpClientPost();
  }
}
  • Ruby 样例
require 'net/http/post/multipart'
require 'json'

begin
  uri = URI.parse('https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result')
  File.open("bankcard.proto") do |proto|
    req = Net::HTTP::Post::Multipart.new uri.path,
          "file" => UploadIO.new(proto, "application/octet-stream", "bankcard.proto"),
          "api_id" => "ID",
          "api_secret" => "SECRET"
    res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
      http.request(req)
    end
    result = JSON.parse(res.body)
    puts result
  end
rescue Exception => e
  puts e.message
end
  • Python 样例

我们提供的样例支持 Python 2.7 & 3.4–3.7 和 PyPy,其他版本暂不提供,需要您查阅相关资料。

import requests

try:
    host = 'https://cloudapi.linkface.cn'
    url = host + '/ocr/parse_bankcard_ocr_result'
    files = {'file': open('/image/file/path', 'rb')}
    data = {'api_id': 'ID','api_secret': 'SECRET'}

    response = requests.post(url, files = files, data = data)
    result = response.json()
    print result
except Exception as e:
    print("type error: " + str(e))
  • PHP 样例

我们提供的样例是基于 PHP 5.5 与 PHP 5.6 两个版本,其他版本暂不提供,需要您查阅相关资料。

以下样例是基于 PHP 5.5 版本的。

<?php
   $testurl = 'https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result';  
   $filePath = 'C:/Users/bankcard.proto';  //ocr解析结果文件
   $fileContent = '@' . realpath($filePath);
   $post_data = array ('api_id' => 'ID','api_secret' => 'SECRET','type' => 'OCR_TYPE'
             'file' => $fileContent);
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $testurl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//您可以根据需要,决定是否打开SSL验证
   curl_setopt($ch, CURLOPT_POST,1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   $output = curl_exec($ch);
   var_dump($output);
   curl_close($ch);
?>

以下样例是基于 PHP 5.6 版本的。

<?php
   $testurl = 'https://cloudapi.linkface.cn/ocr/parse_bankcard_ocr_result';  
   $filePath = 'C:/Users/bankcard.proto';  //ocr解析结果文件
   $fileContent = new \CURLFile($filePath);
   $post_data = array ('api_id' => 'ID','api_secret' => 'SECRET','type' => 'OCR_TYPE'
             'file' => $fileContent);
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $testurl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//您可以根据需要,决定是否打开SSL验证
   curl_setopt($ch, CURLOPT_POST,1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   $output = curl_exec($ch);
   var_dump($output);
   curl_close($ch);
?>

results matching ""

    No results matching ""