閱讀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介紹_文字識別_人工智能圖像類-阿裏雲