阿里云openAI Java 增值税发票识别非本地URL问题

阿里云OpenAPI开发者门户

/**
 * 使用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());
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值