企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**插件中安装OCR插件** 支持以下几种识别。 一般已内置在其他需要此功能的插件中。 * 接口请求 ~~~ /plugins/ocr/api/v1.php?type=Invoice&appkey=358597b9e72f0096ba1dfcd223aba37e&img=https%3A%2F%2Fapp.qihetaiji.com%2Fuploads%2F1.jpg ~~~ * type 如Invoice为增值税发票识别。具体看OCR插件页面 /plugins/ocr/config.php * appkey 商家appkey,唯一值 ,用于统计商家使用次数。 * img 远程图片URL,经过urlencode后传入 * is_local 如果img是本地的且带有https://完整链接的情况,is_local值必须为1 除了以上方式,有可能上传的是图片内容。则采用POST方式。 参数 ~~~ $bodys = [ 'appkey'=>$appkey, 'type'=>$type, 'img_body'=>$img, ]; ~~~ 事例: ~~~ 营业执照识别 $type = "BusinessLicense"; $img = base64_encode(file_get_contents(__DIR__ . '/营业执照.jpg')); $res = ocr_curl($img, $img); print_r($res); function ocr_curl($type, $img) { $app = Config::get('app'); $url = $app['ocr_url']; $appkey = $app['ocr_key']; if(!$url || !$appkey){ return false; } $bodys = [ 'appkey'=>$appkey, 'type'=>$type, 'img_body'=>$img, ]; $querys = ""; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); $data = curl_exec($curl); return $data; } ~~~ ![](https://img.kancloud.cn/a1/34/a134850c50fd67fb3ced7e0f0ea09d7d_825x894.png) data结构如下: ~~~ { "INVOICE_OCR_STATUS": "青", "INVOICE_SELLER_NAME": "上海有限责任公司", "INVOICE_SELLER_BANK": "浙商银0120100594122", "INVOICE_SELLER_ADDRESS": "上海市黄64973702", "INVOICE_SELLER_REGISTER_ID": "912Q21", "INVOICE_TOTAL_AMOUNT": "1500.88", "INVOICE_TOTAL_AMOUNT_AND_TAX_SMALL": "1696.00", -- 发票总金额 "INVOICE_TOTAL_AMOUNT_AND_TAX_BIG": "壹仟陆佰玖拾陆圆整", "INVOICE_SELLER_TAX_RATE": "13%", -- 税点 "INVOICE_TOTAL_TAX": "195.12", "INVOICE_TIME": "2022年03月15日", "INVOICE_PURCHASER_NAME": "上海械有限公司", "INVOICE_PURCHASER_BANK": "中国银8257037", "INVOICE_PURCHASER_ADDRESS": "上海市2009", "INVOICE_PURCHASER_REGISTER_ID": "91339343T", "INVOICE_ID": "12444890", ---- 右上角 NO号 "INVOICE_CODE": "3100214130", ---- 左上角号 "INVOICE_TYPE": "专用发票", "INVOICE_TYPE_ORG": "上海增值税专用发票", "INVOICE_DETAIL": [ { "ITEM_ROW_NUMBER": "1", "ITEM_PRODUCT_NAME": "产品名称", --- 货物或应劳务、服务名称 "ITEM_PRODUCT_TYPE": "产品规格", -- 规格型号 "ITEM_PRODUCT_UNIT": "个", --- 单位 "ITEM_PRODUCT_AMOUNT": "8", --- 数量 "ITEM_PRODUCT_PRICE": "187.61061947", -- 单价 "ITEM_PRODUCT_SUM_MONEY": "1500.88", -- 金额 "ITEM_PRODUCT_TAX_RATE": "13%", -- 税率 "ITEM_PRODUCT_SUM_TAX": "195.12" -- 税额 } ], "INVOICE_MACHINE_CODE": "", "INVOICE_CHECKED_CODE": "" } ~~~