package com.keao.edu.thirdparty.ocr;

import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

public class Ocr {

    public static final String APP_ID = "20569335";
    public static final String API_KEY = "82FCqipUDtTqmy2qbrCRaHCo";
    public static final String SECRET_KEY = "ab6QZclNrzzX1Hw8uQ05n787euLq7KXX";

    public static JSONObject idcard(MultipartFile file, String idCardSide) throws IOException {
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        // 调用接口
        byte[] imgBytes = file.getBytes();
        JSONObject res = client.idcard(imgBytes, idCardSide, null);
        return res;
    }


}
