8.3
luodangjia
2024-08-03 67157345fe1878681e39ec186ef37ff6b3b5c1fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.ruoyi.admin.utils;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.cvm.v20170312.CvmClient;
import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest;
import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.*;
 
public class DescribeInstances {
    public static AddressDto  orcr(String args) {
        try {
            // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。
            // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
            // Credential cred = new Credential("SecretId", "SecretKey");
            Credential cred = new Credential("AKIDHVcchrvvtBiRJB25bHFFJc2Laq4NnHsY", "pgUGwX4Z1SrAPXYk1PxgXVem2HlRJG9k");
            OcrClient client = new OcrClient(cred, "ap-shanghai");
 
 
            SmartStructuralOCRV2Request waybillOCRRequest = new SmartStructuralOCRV2Request();
//            waybillOCRRequest.setImageUrl("https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/e1bb6062-fc05-4b68-ba35-c70cb8067fff.png");
            waybillOCRRequest.setImageBase64(args);
            waybillOCRRequest.setItemNames(new String[]{"收件人", "手机号", "所在地区","详细地址"});
            SmartStructuralOCRV2Response resp = client.SmartStructuralOCRV2(waybillOCRRequest);
 
            GroupInfo[] structuralList = resp.getStructuralList();
            AddressDto addressDto = new AddressDto();
            for (GroupInfo groupInfo : structuralList) {
                LineInfo[] groups = groupInfo.getGroups();
                for (LineInfo group : groups) {
                    ItemInfo[] lines = group.getLines();
                    for (ItemInfo line : lines) {
                        if (line.getKey().getAutoName().equals("收件人")){
                            System.err.println(line.getValue().getAutoContent());
                            addressDto.setName(line.getValue().getAutoContent());
                        }else if (line.getKey().getAutoName().equals("手机号")){
                            System.err.println(line.getValue().getAutoContent());
                            addressDto.setPhone(line.getValue().getAutoContent());
                        }else if (line.getKey().getAutoName().equals("所在地区")){
                            System.err.println(line.getValue().getAutoContent());
                            addressDto.setAddress(line.getValue().getAutoContent());
                        }else if (line.getKey().getAutoName().equals("详细地址")){
                            System.err.println(line.getValue().getAutoContent());
                            addressDto.setDetail(line.getValue().getAutoContent());
                        }
 
                    }
                }
 
            }
 
 
            return addressDto;
 
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
            System.out.println(e.toString());
        }
        throw new RuntimeException("当前内容无法识别");
    }
}