这里只有实现代码,其他实体类等请上腾讯云官网下载SDK :文字识别 驾驶证识别 - 服务端 API 文档 - 文档中心 - 腾讯云
上代码:
import com.ruoyi.app.controller.service.TencentService;
import com.ruoyi.app.controller.tencent.OcrClient;
import com.ruoyi.app.controller.tencent.common.Credential;
import com.ruoyi.app.controller.tencent.common.exception.TencentCloudSDKException;
import com.ruoyi.app.controller.tencent.common.profile.ClientProfile;
import com.ruoyi.app.controller.tencent.common.profile.HttpProfile;
import com.ruoyi.app.controller.tencent.domain.*;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.DriverwalletBankCard;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sun.misc.base64Encoder;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
@Slf4j
@Service
public class TencentServiceImpl implements TencentService {
//腾讯云的密钥Id
private String secretId = "";
//腾讯云的密钥Key
private String secretKey = "";
private String endpoint = "ocr.tencentcloudapi.com";
@Override
public DriverLicenseOCRResponse driverLicenseOCR(DriverLicenseOCRRequest req) throws TencentCloudSDKException {
DriverLicenseOCRResponse resp = new DriverLicenseOCRResponse();
// try{
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential(secretId, secretKey);
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint(endpoint);
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
OcrClient client = new OcrClient(cred, region, clientProfile);
// 实例化一个请求对象,每个接口都会对应一个request对象
req.setImageUrl("E:/2021-08-24/license162976861903332ac912dc46b4a5684f89eb9f075bc2e.jpg");
//驾驶证正面照为:FRONT,反面为:BACK
req.setCardSide("FRONT");
// 返回的resp是一个DriverLicenseOCRResponse的实例,与请求对象对应
//resp = client.DriverLicenseOCR(req);
// 输出json格式的字符串回包
log.info("驾驶证(正、副页):{}",DriverLicenseOCRResponse.toJsonString(resp));
// } catch (TencentCloudSDKException e) {
// log.error("驾驶证(正、副页)识别异常:{}", e);
// }
return resp;
}
}



