/** * 使用AK&SK初始化账号Client * @param accessKeyId * @param accessKeySecret * @return Client * @throws Exception */ public static com.aliyun.ocr20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception { com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() // 必填,您的 AccessKey ID .setAccessKeyId(accessKeyId) // 必填,您的 AccessKey Secret .setAccessKeySecret(accessKeySecret); // Endpoint 请参考 https://api.aliyun.com/product/ocr config.endpoint = "ocr.cn-shanghai.aliyuncs.com"; return new com.aliyun.ocr20191230.Client(config); } public static void main(String[] args) throws Exception { com.aliyun.ocr20191230.Client client = createClient("阿里key", "阿里秘钥"); // 场景一,使用本地文件 // InputStream inputStream = new FileInputStream(new File("/tmp/RecognizeVATInvoice1.jpg")); // 场景二,使用任意可访问的url URL url = new URL("http://192.198.202.128:9203/statics/upload/2023/11/09/0_1(3)_20231109100801A024.jpg"); InputStream inputStream = url.openConnection().getInputStream(); com.aliyun.ocr20191230.models.RecognizeVATInvoiceAdvanceRequest recognizeVATInvoiceAdvanceRequest = new com.aliyun.ocr20191230.models.RecognizeVATInvoiceAdvanceRequest() .setFileURLObject(inputStream) .setFileType("jpg"); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); try { // 复制代码运行请自行打印 API 的返回值 RecognizeVATInvoiceResponse response = client.recognizeVATInvoiceAdvance(recognizeVATInvoiceAdvanceRequest, runtime); System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(response))); } catch (TeaException error) { // 获取整体报错信息 System.out.println(com.aliyun.teautil.Common.toJSONString(error)); // 获取单个字段 System.out.println(error.getCode()); } }
阿里云openAI Java 增值税发票识别非本地URL问题
最新推荐文章于 2024-10-20 23:43:10 发布