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("当前内容无法识别");
|
}
|
}
|