BusinessLicense.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package com.ruoyi.web.controller.Idcard;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.ruoyi.common.utils.Base64Util;
  4. import com.ruoyi.common.utils.FileUtil;
  5. import com.ruoyi.common.utils.HttpUtil;
  6. import java.net.URLEncoder;
  7. /**
  8. * 营业执照识别
  9. * @Author: tjf
  10. * @Date: 2024/4/17 9:57
  11. * @Describe:
  12. */
  13. public class BusinessLicense {
  14. /**
  15. * 重要提示代码中所需工具类
  16. * FileUtil,Base64Util,HttpUtil,GsonUtils请从
  17. * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
  18. * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
  19. * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
  20. * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
  21. * 下载
  22. */
  23. public static JSONObject businessLicense(String image) {
  24. // 请求url
  25. String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license";
  26. try {
  27. // 本地文件路径
  28. byte[] imgData = FileUtil.readFileByBytes(image);
  29. String imgStr = Base64Util.encode(imgData);
  30. String imgParam = URLEncoder.encode(imgStr, "UTF-8");
  31. String param = "image=" + imgParam;
  32. // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
  33. String accessToken = Idcard.getAccessToken();
  34. String result = HttpUtil.post(url, accessToken, param);
  35. /**
  36. *
  37. {
  38. "words_result": {
  39. "经营范围": {
  40. "location": {
  41. "top": 589,
  42. "left": 381,
  43. "width": 90,
  44. "height": 19
  45. },
  46. "words": "商务服务业"
  47. },
  48. "组成形式": {
  49. "location": {
  50. "top": -1,
  51. "left": -1,
  52. "width": 0,
  53. "height": 0
  54. },
  55. "words": "无"
  56. },
  57. "法人": {
  58. "location": {
  59. "top": 537,
  60. "left": 381,
  61. "width": 36,
  62. "height": 19
  63. },
  64. "words": "方平"
  65. },
  66. "证件编号": {
  67. "location": {
  68. "top": 218,
  69. "left": 302,
  70. "width": 140,
  71. "height": 15
  72. },
  73. "words": "921MA190538210301"
  74. },
  75. "注册资本": {
  76. "location": {
  77. "top": 431,
  78. "left": 1044,
  79. "width": 152,
  80. "height": 21
  81. },
  82. "words": "200万元"
  83. },
  84. "单位名称": {
  85. "location": {
  86. "top": 431,
  87. "left": 384,
  88. "width": 71,
  89. "height": 20
  90. },
  91. "words": "有限公司"
  92. },
  93. "有效期": {
  94. "location": {
  95. "top": 536,
  96. "left": 1044,
  97. "width": 198,
  98. "height": 20
  99. },
  100. "words": "长期"
  101. },
  102. "社会信用代码": {
  103. "location": {
  104. "top": 300,
  105. "left": 241,
  106. "width": 156,
  107. "height": 16
  108. },
  109. "words": "10440119MA06M85"
  110. },
  111. "实收资本": {
  112. "location": {
  113. "top": -1,
  114. "left": -1,
  115. "width": 0,
  116. "height": 0
  117. },
  118. "words": "无"
  119. },
  120. "有效期起始日期": {
  121. "location": {
  122. "top": 536,
  123. "left": 1044,
  124. "width": 198,
  125. "height": 20
  126. },
  127. "words": "2019年01月01日"
  128. },
  129. "核准日期": {
  130. "location": {
  131. "top": 884,
  132. "left": 1188,
  133. "width": 199,
  134. "height": 22
  135. },
  136. "words": "2019年01月01日"
  137. },
  138. "成立日期": {
  139. "location": {
  140. "top": 484,
  141. "left": 1043,
  142. "width": 126,
  143. "height": 19
  144. },
  145. "words": "2019年01月01日"
  146. },
  147. "税务登记号": {
  148. "location": {
  149. "top": -1,
  150. "left": -1,
  151. "width": 0,
  152. "height": 0
  153. },
  154. "words": "无"
  155. },
  156. "地址": {
  157. "location": {
  158. "top": 588,
  159. "left": 1043,
  160. "width": 55,
  161. "height": 22
  162. },
  163. "words": "广州市"
  164. },
  165. "登记机关": {
  166. "location": {
  167. "top": 0,
  168. "left": 0,
  169. "width": 0,
  170. "height": 0
  171. },
  172. "words": "无"
  173. },
  174. "类型": {
  175. "location": {
  176. "top": 484,
  177. "left": 382,
  178. "width": 258,
  179. "height": 20
  180. },
  181. "words": "有限责任公司(自然人投资或控股)"
  182. }
  183. },
  184. "direction": 0,
  185. "words_result_num": 16,
  186. "log_id": "3166723741167575145"
  187. }
  188. */
  189. JSONObject jsonObject = JSONObject.parseObject(result);
  190. return jsonObject;
  191. } catch (Exception e) {
  192. e.printStackTrace();
  193. }
  194. return null;
  195. }
  196. }