欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

百度OCR图像识别(包含自定义模板)

程序员文章站 2022-07-03 18:26:04
...

OCR识别身份证、营业执照、增值税发票、自定义模板

应用场景:

最近在做一个票据平台,需要使用者上传营业执照和法人身份证进行识别,同时还有一些增值税发票识别、票据识别等图像识别功能,因此整理一下OCR图像识别相关接口信息

一:前置条件准备

第一步:登录注册百度AI开放平台,添加文字识别应用
传送门:https://login.bce.baidu.com/
百度OCR图像识别(包含自定义模板)
添加好应用之后,就可以得到调用接口所用的 API KeySecret Key

二:配置SDK

链接:https://ai.baidu.com/sdk#ocr
百度OCR图像识别(包含自定义模板)
同时也可以使用maven加载依赖,添加以下依赖即可。其中版本号可在maven官网查询

<dependency>
    <groupId>com.baidu.aip</groupId>
    <artifactId>java-sdk</artifactId>
    <version>${version}</version>
</dependency>

三:准备接口相关工具类

    * 重要提示代码中所需工具类
    * FileUtil,Base64Util,HttpUtil,GsonUtils请从
    * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
    * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
    * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
    * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
    * 下载
    */

复制以上下载链接下载相应的工具类即可,最新版本的工具类可以参考官方demo示例
链接:https://ai.baidu.com/ai-doc/OCR/rk3h7xzck

四:直接贴代码

AuthService工具类

该工具类需要手动配置一下API Key和Secret Key,这两个参数我们在创建应用的时候已经拿到了。

package utils;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;

/**
 * 百度OCR识别工具获取token类
 */
public class AuthService {

    /**
     * 获取权限token
     * @return 返回示例:
     * {
     * "access_token": "24.460da4889caad24cccdb1fea17221975.2592000.1491995545.282335-1234567",
     * "expires_in": 2592000
     * }
     */
    public static String getAuth() {
        // 官网获取的 API Key 更新为你注册的
        String clientId = "创建应用时拿到的API Key";
        // 官网获取的 Secret Key 更新为你注册的
        String clientSecret = "创建应用时拿到的Secret Key";
        return getAuth(clientId, clientSecret);
    }

    /**
     * 获取API访问token
     * 该token有一定的有效期,需要自行管理,当失效时需重新获取.
     * @param ak - 百度云官网获取的 API Key
     * @param sk - 百度云官网获取的 Securet Key
     * @return assess_token 示例:
     * "24.460da4889caad24cccdb1fea17221975.2592000.1491995545.282335-1234567"
     */
    public static String getAuth(String ak, String sk) {
        // 获取token地址
        String authHost = "https://aip.baidubce.com/oauth/2.0/token?";
        String getAccessTokenUrl = authHost
                // 1. grant_type为固定参数
                + "grant_type=client_credentials"
                // 2. 官网获取的 API Key
                + "&client_id=" + ak
                // 3. 官网获取的 Secret Key
                + "&client_secret=" + sk;

        try {
            URL realUrl = new URL(getAccessTokenUrl);
            // 打开和URL之间的连接
            HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = connection.getHeaderFields();
            // 遍历所有的响应头字段
            for (String key : map.keySet()) {
                System.err.println(key + "--->" + map.get(key));
            }
            // 定义 BufferedReader输入流来读取URL的响应
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String result = "";
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
            /**
             * 返回结果示例
             */
            System.err.println("result:" + result);
            JSONObject jsonObject = new JSONObject(result);
            String access_token = jsonObject.getString("access_token");
            return access_token;
        } catch (Exception e) {
            System.err.printf("获取token失败!");
            e.printStackTrace(System.err);
        }
        return null;
    }

}

OCRUtil 工具类

此工具类用来调用ocr识别接口,返回识别内容

package utils;

import java.net.URLEncoder;

/**
 * OCR识别工具类
 * 接口文档地址:https://ai.baidu.com/ai-doc/OCR/rk3h7xzck
 */
public class OCRUtil {

    /**
     * 身份证识别
     * @param picUrl 图片URL
     * @return 返回值json示例:
     * {"log_id": 9101702628775372587, "words_result_num": 6, "image_status": "normal", "words_result": {"住址": {"location": {"width": 1468, "top": 1593, "left": 900, "height": 324}, "words": "山东省临沂市临沭县XXXXXXX"}, "出生": {"location": {"width": 1132, "top": 1302, "left": 906, "height": 126}, "words": "19960522"}, "姓名": {"location": {"width": 462, "top": 716, "left": 890, "height": 156}, "words": "李文强"}, "公民身份号码": {"location": {"width": 1873, "top": 2289, "left": 1484, "height": 134}, "words": "371329199699999999"}, "性别": {"location": {"width": 99, "top": 1037, "left": 898, "height": 121}, "words": "男"}, "民族": {"location": {"width": 93, "top": 1037, "left": 1619, "height": 115}, "words": "汉"}}, "idcard_number_type": 1}
     */
    public static String idcard(String picUrl) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";
        try {
            // 身份证图片路径
            String filePath = picUrl;
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "id_card_side=" + "front" + "&image=" + imgParam;

            //每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
            String auth = AuthService.getAuth();
            System.out.println("access_token:"+auth);
            String accessToken = auth;

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println("身份证识别返回值:" + result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 营业执照识
     * @param picUrl 图片URL
     * @return 返回值json示例:
     * {"log_id": 1048764596700986027, "words_result_num": 11, "words_result": {"注册资本": {"location": {"width": 0, "top": 0, "height": 0, "left": 0}, "words": "无"}, "社会信用代码": {"location": {"width": 0, "top": 0, "height": 0, "left": 0}, "words": "无"}, "单位名称": {"location": {"width": 255, "top": 354, "height": 20, "left": 376}, "words": "深圳市易白文化传媒有限公司"}, "法人": {"location": {"width": 53, "top": 481, "height": 28, "left": 378}, "words": "王XX"}, "证件编号": {"location": {"width": 142, "top": 315, "height": 12, "left": 845}, "words": "440301109090290"}, "组成形式": {"location": {"width": 0, "top": 0, "height": 0, "left": 0}, "words": "无"}, "成立日期": {"location": {"width": 176, "top": 524, "height": 29, "left": 377}, "words": "2014年04月03日"}, "地址": {"location": {"width": 366, "top": 439, "height": 27, "left": 378}, "words": "深圳市龙岗区"}, "经营范围": {"location": {"width": 921, "top": 613, "height": 45, "left": 157}, "words": "由章程确定经营范围中属于法律、法规规定应当经批准的项目要取得许可审批文件后方可开展相关经营活动登记机关深圳市场监督管理局"}, "类型": {"location": {"width": 116, "top": 396, "height": 27, "left": 381}, "words": "有限责任公司"}, "有效期": {"location": {"width": 0, "top": 0, "height": 0, "left": 0}, "words": "无"}}}
     */
    public static String businessLicense(String picUrl) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license";
        try {
            // 本地文件路径
            String filePath = picUrl;
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
            String auth = AuthService.getAuth();
            System.out.println("access_token:"+auth);
            String accessToken = auth;

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println("营业执照识别返回值:" + result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 增值税发票识别
     * @param picUrl 图片URL
     * @return 返回值json示例:
     *{"log_id": 2944724819899424811, "direction": 0, "words_result_num": 31, "words_result": {"InvoiceNum": "73426227", "SellerName": "山东顺丰速运有限公司临沂分公司", "CommodityTaxRate": [{"word": "6%", "row": "1"}], "SellerBank": "中国工商银行股份有限公司xxx支行161002011", "Checker": "郭x", "NoteDrawer": "张xx", "CommodityAmount": [{"word": "20.75", "row": "1"}], "InvoiceDate": "2019年01月20日", "CommodityTax": [{"word": "1.25", "row": "1"}], "PurchaserName": "XXXX开发有限公司", "InvoiceTypeOrg": "山东增值税电子普通发票", "CommodityNum": [{"word": "1.000000", "row": "1"}], "PurchaserBank": "", "Remarks": "", "Password": "", "SellerAddress": "山东省临沂市兰山区银凤", "PurchaserAddress": "", "InvoiceCode": "037001600111", "CommodityUnit": [{"word": "次", "row": "1"}], "Payee": "楚xx", "PurchaserRegisterNum": "91371300795346987L", "CommodityPrice": [{"word": "20.750000", "row": "1"}], "TotalAmount": "20.75", "AmountInWords": "贰拾贰元整", "AmountInFiguers": "22.00", "TotalTax": "1.25", "InvoiceType": "电子普通发票", "SellerRegisterNum": "91371302348987686X", "CommodityName": [{"word": "*物流辅助服务*派服务费", "row": "1"}], "CommodityType": [], "CheckCode": "01273274016238351722"}}
     */
    public static String vatInvoice(String picUrl) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/vat_invoice";
        try {
            // 本地文件路径
            String filePath = picUrl;
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            //注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
            String auth = AuthService.getAuth();
            System.out.println("access_token:"+auth);
            String accessToken = auth;

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println("增值税发票识别返回值:" + result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 通用票据识别
     * @param picUrl 图片URL
     * @return 返回值json示例:
     * {"log_id": 245228189904398571, "words_result_num": 28, "words_result": [{"location": {"width": 340, "top": 40, "left": 308, "height": 44}, "words": "电子商业承兑汇票"}, {"location": {"width": 141, "top": 110, "left": 9, "height": 17}, "words": "出票日期:2020/01/19"}, {"location": {"width": 144, "top": 110, "left": 548, "height": 17}, "words": "票据状态:背书已签收"}, {"location": {"width": 157, "top": 130, "left": 9, "height": 17}, "words": "汇票到期日:2021/01/18"}, {"location": {"width": 322, "top": 131, "left": 549, "height": 16}, "words": "票据号码:230547300008520200119575584322"}, {"location": {"width": 324, "top": 175, "left": 13, "height": 35}, "words": "出全称临沂城市建设投资集团有限公司"}, {"location": {"width": 319, "top": 177, "left": 532, "height": 28}, "words": "收全称临沂铁路建设投资集团有限公司"}, {"location": {"width": 194, "top": 204, "left": 17, "height": 17}, "words": "票账号626603694"}, {"location": {"width": 101, "top": 204, "left": 530, "height": 19}, "words": "款账号"}, {"location": {"width": 72, "top": 208, "left": 654, "height": 13}, "words": "630744851"}, {"location": {"width": 17, "top": 222, "left": 18, "height": 17}, "words": "人"}, {"location": {"width": 334, "top": 231, "left": 58, "height": 18}, "words": "开户银行中国民生银行股份有限公司临沂兰山支行"}, {"location": {"width": 376, "top": 219, "left": 531, "height": 30}, "words": "人开户银行中国民生银行股份有限公司临沂兰山支行"}, {"location": {"width": 181, "top": 259, "left": 29, "height": 17}, "words": "出票保证信息保证人名称"}, {"location": {"width": 86, "top": 259, "left": 403, "height": 17}, "words": "保证人地址:"}, {"location": {"width": 65, "top": 259, "left": 669, "height": 16}, "words": "保证日期:"}, {"location": {"width": 59, "top": 290, "left": 43, "height": 17}, "words": "票据金额"}, {"location": {"width": 128, "top": 280, "left": 147, "height": 23}, "words": "人民币壹拾万元整"}, {"location": {"width": 250, "top": 279, "left": 696, "height": 23}, "words": "亿千百万百元角分"}, {"location": {"width": 33, "top": 299, "left": 152, "height": 17}, "words": "大写"}, {"location": {"width": 263, "top": 319, "left": 165, "height": 17}, "words": "全称临沂城市建设投资集团有限公司"}, {"location": {"width": 183, "top": 318, "left": 567, "height": 19}, "words": "开户行行号305473000085"}, {"location": {"width": 71, "top": 334, "left": 36, "height": 17}, "words": "承兑人信息"}, {"location": {"width": 31, "top": 347, "left": 163, "height": 17}, "words": "账号"}, {"location": {"width": 69, "top": 350, "left": 234, "height": 12}, "words": "26603694"}, {"location": {"width": 341, "top": 346, "left": 566, "height": 19}, "words": "开户行名称中国民生银行股份有限公司临沂兰山支行"}, {"location": {"width": 70, "top": 375, "left": 36, "height": 17}, "words": "交易合同号"}, {"location": {"width": 338, "top": 375, "left": 533, "height": 17}, "words": "承出票人承诺:本汇票请予以承兑,到期无条件付款"}]}
     * @return
     */
    public static String receipt(String picUrl) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/receipt";
        try {
            // 本地文件路径
//            String filePath = picUrl;
            String filePath = "E:\\Project\\ChengToupj\\public\\assets\\images\\typj2.png";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            //这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
            String auth = AuthService.getAuth();
            System.out.println("access_token:"+auth);
            String accessToken = auth;

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println("通用票据识别返回值:" + result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 自定义模板识别
     * @param picUrl
     * @return 返回值示例:
     * {"data":{"ret":[{"probability":{"average":0.997027,"min":0.985316,"variance":0.00002},"location":{"height":15,"left":415,"top":196,"width":74},"word_name":"takerNo","word":"630744851"},{"probability":{"average":0.997607,"min":0.989751,"variance":0.000011},"location":{"height":17,"left":190,"top":296,"width":59},"word_name":"billAmount2","word":"壹拾万元整"},{"location":{"height":29,"left":96,"top":415,"width":227},"word_name":"contractNo","word":""},{"location":{"height":25,"left":164,"top":513,"width":124},"word_name":"acceptoGuarantorName","word":""},{"location":{"height":37,"left":569,"top":548,"width":107},"word_name":"drawerDueDate","word":""},{"probability":{"average":0.999552,"min":0.9963,"variance":0.000001},"location":{"height":16,"left":348,"top":458,"width":264},"word_name":"acceptorPromise","word":"承兑人承诺:本汇票已经承兑,到期无条件付款"},{"location":{"height":33,"left":380,"top":547,"width":122},"word_name":"drawerCredit","word":""},{"probability":{"average":0.999568,"min":0.994961,"variance":0.000001},"location":{"height":18,"left":349,"top":418,"width":301},"word_name":"drawerPromise","word":"出票人承诺:本汇票信息请予以承兑,到期无条件付款"},{"probability":{"average":0.995827,"min":0.902706,"variance":0.000326},"location":{"height":20,"left":416,"top":219,"width":226},"word_name":"takerBankName","word":"中国民生银行股份有限公司临沂兰山支行"},{"location":{"height":23,"left":360,"top":250,"width":124},"word_name":"drawerGuarantorAddr","word":""},{"probability":{"average":0.992614,"min":0.973733,"variance":0.000071},"location":{"height":13,"left":483,"top":312,"width":182},"word_name":"billAmount","word":"¥10000000"},{"location":{"height":24,"left":543,"top":248,"width":132},"word_name":"drawerGuarantorDate","word":""},{"probability":{"average":0.999024,"min":0.993459,"variance":0.000003},"location":{"height":16,"left":147,"top":389,"width":76},"word_name":"AcceptorNo","word":"626603694"},{"probability":{"average":0.970141,"min":0.703548,"variance":0.007897},"location":{"height":15,"left":402,"top":119,"width":60},"word_name":"billStatus","word":"背书已签收"},{"probability":{"average":0.999005,"min":0.987407,"variance":0.000009},"location":{"height":20,"left":98,"top":166,"width":174},"word_name":"drawerName","word":"临沂城市建设投资集团有限公司"},{"location":{"height":33,"left":207,"top":599,"width":118},"word_name":"acceptorGrade","word":""},{"probability":{"average":0.987302,"min":0.590116,"variance":0.001054},"location":{"height":15,"left":55,"top":124,"width":77},"word_name":"issueDate","word":"20191101"},{"probability":{"average":0.99432,"min":0.827453,"variance":0.000824},"location":{"height":15,"left":399,"top":139,"width":238},"word_name":"billNo","word":"230547300008520191101507979807"},{"probability":{"average":0.999246,"min":0.992471,"variance":0.000003},"location":{"height":15,"left":415,"top":390,"width":226},"word_name":"AcceptorBankName","word":"中国民生银行股份有限公司临沂兰山支行"},{"probability":{"average":0.998876,"min":1.294835,"variance":0.0000020},"location":{"height":14,"left":69,"top":144,"width":75},"word_name":"expirationDate","word":"20201031"},{"probability":{"average":0.999625,"min":0.998369,"variance":0.0},"location":{"height":19,"left":415,"top":168,"width":174},"word_name":"takerName","word":"临沂铁路建设投资集团有限公司"},{"probability":{"average":0.999804,"min":0.999353,"variance":0.0},"location":{"height":14,"left":96,"top":470,"width":34},"word_name":"isTransfer","word":"可转让"},{"probability":{"average":0.999964,"min":0.999964,"variance":0.0},"location":{"height":39,"left":149,"top":338,"width":165},"word_name":"AcceptorName","word":"临沂城市建设投资集团有限公司"},{"probability":{"average":0.996107,"min":0.975287,"variance":0.000052},"location":{"height":15,"left":415,"top":350,"width":88},"word_name":"AcceptorBankNo","word":"305473000085"},{"probability":{"average":0.999147,"min":0.996727,"variance":0.000001},"location":{"height":15,"left":94,"top":196,"width":76},"word_name":"drawerNo","word":"626603694"},{"probability":{"average":0.995827,"min":0.902706,"variance":0.000326},"location":{"height":20,"left":97,"top":219,"width":227},"word_name":"drawerBankName","word":"中国民生银行股份有限公司临沂兰山支行"},{"location":{"height":28,"left":542,"top":512,"width":131},"word_name":"acceptoGuarantorDate","word":""},{"location":{"height":26,"left":360,"top":513,"width":123},"word_name":"acceptoGuarantorAddr","word":""},{"location":{"height":37,"left":570,"top":599,"width":108},"word_name":"acceptorDueDate","word":""},{"location":{"height":38,"left":207,"top":546,"width":119},"word_name":"drawerGrade","word":""},{"location":{"height":23,"left":165,"top":250,"width":123},"word_name":"drawerGuarantorName","word":""},{"location":{"height":35,"left":381,"top":599,"width":120},"word_name":"acceptorCredit","word":""},{"location":{"height":21,"left":95,"top":642,"width":581},"word_name":"drawerRemark","word":""}],"templateSign":"6da5acd78d691486a3e494835ef4062a","templateName":"typj","scores":1.0,"isStructured":true,"logId":"158917724812656","templateMatchDegree":1.0,"clockwiseAngle":0.0},"error_code":0,"error_msg":"","log_id":"158917724812656"}
     */
    public static String recognise(String picUrl){
        // iocr识别apiUrl
        String recogniseUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise";

        String filePath = picUrl;
        try {
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            // 请求模板参数
            String recogniseParams = "templateSign=你的模板ID&image=" + URLEncoder.encode(imgStr, "UTF-8");
            // 请求分类器参数
            String classifierParams = "classifierId=分类器的classifierId&image=" + URLEncoder.encode(imgStr, "UTF-8");

            String auth = AuthService.getAuth();
            System.out.println("access_token:"+auth);
            String accessToken = auth;
            // 请求模板识别
            String result = HttpUtil.post(recogniseUrl, accessToken, recogniseParams);
            // 请求分类器识别
            // String result = HttpUtil.post(recogniseUrl, accessToken, classifierParams);

            System.out.println(result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {

    }

}

五:自定义模板部分

百度AI平台已经提供了很多识别的接口,但是由于业务逻辑的复杂性,有很多特别的识别需求导致识别模板并不符合,这个时候需要我们去进行自定义文字识别模板,定制模板进行图像文字识别。

1:自定义识别模板

先上文档链接:https://ai.baidu.com/ai-doc/OCR/0k3h7y8ip
再上模板管理链接:https://ai.baidu.com/iocr#/templatelist

进入模板管理这个链接,可以创建识别模板,根据提示进行即可。
第一步先选择框选参照字段,尽量选择四个角的字段
百度OCR图像识别(包含自定义模板)
第二步:框选识别区,定义区域字段,示例图如下:
百度OCR图像识别(包含自定义模板)
先框选要识别的区域(蓝底部分),每个框域都可以在右方自定义字段名,该区域文字识别后将用此字段名返回。
框选识别区设置完之后就可以保存了。这个时候我们可以拿到 模板ID
百度OCR图像识别(包含自定义模板)

2:定义分类器

选择分类器管理,创建分类器,添加两个模板就可以了
百度OCR图像识别(包含自定义模板)

3:代码部分

此代码在上面的OCRUtil工具类中已经贴过了,此处单独拿出来在展示一次。

    public static String recognise(String picUrl){
        // iocr识别apiUrl
        String recogniseUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise";

        String filePath = picUrl;
        try {
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            // 请求模板参数
            String recogniseParams = "templateSign=你创建的模板的ID&image=" + URLEncoder.encode(imgStr, "UTF-8");
            // 请求分类器参数
            String classifierParams = "classifierId=你创建的分类器的ID&image=" + URLEncoder.encode(imgStr, "UTF-8");

            String auth = AuthService.getAuth();
            System.out.println("access_token:"+auth);
            String accessToken = auth;
            // 请求模板识别
            String result = HttpUtil.post(recogniseUrl, accessToken, recogniseParams);
            // 请求分类器识别
            // String result = HttpUtil.post(recogniseUrl, accessToken, classifierParams);

            System.out.println(result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

至此,包括身份证识别、营业执照识别、增值税发票识别、以及自定义模板识别就大功告成了,如有问题,请在评论区纠正~