阅读617 返回首页    go 手机大全


营业执照识别__API介绍_文字识别_人工智能图像类-阿里云

本页面主要介绍服务对应的接口和返回结果中的关键字段的含义,请在阅读本页面之前,了解请求数据格式介绍,了解输入输出的通用数据格式。 此外,在本页最后,附上了营业执照识别服务调用的程序示例,以供参考。(注:目前营业执照识别服务只适用于识别最新的竖版“三证合一”营业执照)

请求接口

  • 云市场接口

    • 请求方法: POST
    • 请求url: 在云市场搜索印刷文字识别-营业执照识别,在API接口中找到调用地址
  • 数加接口

    • 请求方法: POST
    • 请求url: 打开管理控制台,接口名称选择ocr_business,查看请求地址

请求参数

参数名称 参数类型 描述 默认值
image string dataType为50, dataValue是base64编码后的图像数据 空字符串

POST请求body 示例如下:

  1. {
  2. "inputs": [
  3. {
  4. "image": {
  5. "dataType": 50, #50表示image的数据类型为字符串
  6. "dataValue": "base64_image_string" #图片以base64编码的string
  7. }
  8. }]
  9. }

返回结果格式

返回结果格式如下:

  1. {
  2. "outputs": [
  3. {
  4. "outputLabel": "ocr_business",
  5. "outputMulti": {},
  6. "outputValue": {
  7. "dataType": 50,
  8. "dataValue": "{
  9. "config_str": "", #配置字符串信息
  10. "reg_num": "123456765432101", #注册号/统一社会信用代码
  11. "name": "杭州西溪科技有限公司", #公司名称
  12. "person":"张三", #法定代表人
  13. "valid_period" : "20340801", #营业期限结束日期,输出格式为"年月日(YYYYMMDD)"
  14. #证件中的"长期"输出为"长期",若证件没有营业期限,则默认其为"长期"
  15. "address" : "浙江省杭州市文一西路969号", #公司地址
  16. "capital" : "500万元", #注册资本
  17. "success": true #识别成功与否 true/false
  18. "request_id":"84701974fb983158_20160526100112", #请求对应的唯一表示
  19. }"
  20. }
  21. }]
  22. }

每一个请求返回的结果都是一个json字符串,由dataValue关键词可以索引到,主要有如下字段:

  • config_str: 表示发送请求时候的配置字符串,目前该字段没有用,返回为空, 类型为字符串
  • reg_num: 注册号/统一社会信用代码, 类型为字符串
  • name: 公司名称, 类型为字符串
  • person: 法定代表人, 类型为字符串
  • valid_period: 营业期限结束日期—输出格式为”年月日(YYYYMMDD)”,证件中的”长期”输出为”长期”,若证件没有营业期限,则默认其为”长期”, 类型为字符串
  • address: 公司地址, 类型为字符串
  • capital: 注册资本, 类型为字符串
  • request_id: 请求对应的唯一表示, 用户可以保存该字段用以进行问题追溯,类型为字符串
  • success: 识别流程是否出现异常, false表示识别失败,true表示识别成功, 类型为布尔型

程序示例

云市场

云市场搜索印刷文字识别-营业执照识别,在API接口中找到请求示例

数加平台

  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import sun.misc.BASE64Encoder;
  5. import org.json.JSONObject;
  6. import org.json.JSONArray;
  7. import org.json.JSONException;
  8. @SuppressWarnings("restriction")
  9. public class BusinessLicense {
  10. /*
  11. * 获取参数的json对象
  12. */
  13. public static JSONObject getParam(int type, JSONObject dataValue) {
  14. JSONObject obj = new JSONObject();
  15. try {
  16. obj.put("dataType", type);
  17. obj.put("dataValue", dataValue);
  18. } catch (JSONException e) {
  19. e.printStackTrace();
  20. }
  21. return obj;
  22. }
  23. /*
  24. * 获取参数的json对象
  25. */
  26. public static JSONObject getParam(int type, String dataValue) {
  27. JSONObject obj = new JSONObject();
  28. try {
  29. obj.put("dataType", type);
  30. obj.put("dataValue", dataValue);
  31. } catch (JSONException e) {
  32. e.printStackTrace();
  33. }
  34. return obj;
  35. }
  36. public static void main(String[] args) {
  37. String img_file = "business_license.jpg";
  38. String service_url = "your-service-url";
  39. String ak_id = "your access key id";
  40. String ak_secret = "your access key secret";
  41. // 对图像进行base64编码
  42. String img_base64 = "";
  43. try {
  44. File file = new File(img_file);
  45. byte[] content = new byte[(int) file.length()];
  46. FileInputStream finputstream = new FileInputStream(file);
  47. finputstream.read(content);
  48. finputstream.close();
  49. img_base64 = (new BASE64Encoder()).encode(content);
  50. } catch (IOException e) {
  51. e.printStackTrace();
  52. return;
  53. }
  54. // 拼装请求body的json字符串
  55. JSONObject request_obj = new JSONObject();
  56. try {
  57. JSONObject obj = new JSONObject();
  58. JSONArray input_array = new JSONArray();
  59. obj.put("image", getParam(50, img_base64));
  60. input_array.put(obj);
  61. request_obj.put("inputs", input_array);
  62. } catch (JSONException e) {
  63. e.printStackTrace();
  64. }
  65. String body = request_obj.toString();
  66. //Sender代码参考 https://help.aliyun.com/document_detail/shujia/OCR/ocr-api/sender.html
  67. String result = Sender.sendPost(service_url, body, ak_id, ak_secret);
  68. System.out.println(result);
  69. // 解析请求结果
  70. try {
  71. JSONObject result_obj = new JSONObject(result);
  72. JSONArray output_array = result_obj.getJSONArray("outputs");
  73. String output = output_array.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); // 取出结果json字符串
  74. JSONObject out = new JSONObject(output);
  75. if (out.getBoolean("success")) {
  76. String reg_num = out.getString("reg_num"); // 获取注册号/统一社会信用代码
  77. String name = out.getString("name"); // 获取公司名
  78. String person = out.getString("person"); // 获取公司法人
  79. String valid_period = out.getString("valid_period"); // 获取公司有效期
  80. String address = out.getString("address"); // 获取地址
  81. String capital = out.getString("capital"); // 获取注册资本
  82. String request_id = out.getString("request_id"); // 获取request_id
  83. System.out.printf("reg_num: %s n name : %s n person : %sn valid_periode: %s n address : %sn capital : %sn",reg_num,name,person,valid_period,address,capital);
  84. }
  85. else {
  86. System.out.println("predict error");
  87. }
  88. } catch (JSONException e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. }

最后更新:2016-11-23 16:04:16

  上一篇:go 行驶证识别__API介绍_文字识别_人工智能图像类-阿里云
  下一篇:go 门店识别__API介绍_文字识别_人工智能图像类-阿里云