您的位置:首页 > 娱乐 > 明星 > 机械加工外协加工网_网络营销产品的五个层次_公司网站推广方案_想学编程去哪里找培训班

机械加工外协加工网_网络营销产品的五个层次_公司网站推广方案_想学编程去哪里找培训班

2024/10/7 2:25:11 来源:https://blog.csdn.net/qq_39594419/article/details/142489682  浏览:    关键词:机械加工外协加工网_网络营销产品的五个层次_公司网站推广方案_想学编程去哪里找培训班
机械加工外协加工网_网络营销产品的五个层次_公司网站推广方案_想学编程去哪里找培训班

前言:

Hello亲爱的uu们,在读过了一个愉快的周末后(摸鱼了一会),我又回来更新啦,感谢uu们的阅读,话不多说~

 

 

司机认证

当司机点击开始接单的时候,会先判断该司机有没有通过认证,如果没有认证,会先跳转到认证界面进行认证。
司机认证模块需要集成腾讯云存储COS、腾讯云OCR证件识别及腾讯云人脸模型库创建。

开通腾讯云对象存储COS

进入官网直接搜索对象存储,进入之后点击立即使用,如果第一次使用的话需要认证

8eaf480696ec494fbaa8184bbcbb8ba0.png

70216026aadf4ce096cb307ca699bb17.png 

认证完成之后开通COS服务 

7c736014bb8045b19c9a12fc53432cfb.png

开通之后界面 4e9588d8a513418d9a92da78dd2553a2.png点击创建存储桶,创建完成之后可以在存储桶列表查看创建的桶。c639917b2bf94559bf73657bc7887a10.png


如果要使用java代码进行操作,需要获取腾讯云账号的id和key,点击右上角的账户 ->访问管理2cdba89aa13d414484964aad8b51058c.png 

在API秘钥管理的创建秘钥,记得保存好SecretId和SecretKey(很重要,后续代码编写都用到他)1ca8d657055543b5b309fa968294f4a6.png

远程调用编写,web-driver下的CosController

	@Autowiredprivate CosService cosService;// 文件上传接口@Operation(summary = "上传")@GuiGuLogin@PostMapping("/upload")public Result<CosUploadVo> upload(@RequestPart("file")MultipartFile file,@RequestParam(name = "path", defaultValue = "auth") String path){CosUploadVo cosUploadVo = cosService.uploadFile(file, path);return Result.ok(cosUploadVo);}

CosServiceImpl

	@Autowiredprivate CosFeignClient cosFeignClient;// 文件上传接口@Overridepublic CosUploadVo uploadFile(MultipartFile file, String path) {// 远程调用Result<CosUploadVo> cosUploadVoResult = cosFeignClient.upload(file, path);CosUploadVo cosUploadVo = cosUploadVoResult.getData();return cosUploadVo;}

CosFeignClient,MediaType.MULTIPART_FORM_DATA_VALUE表示传的类型是文件

	//文件上传@PostMapping(value = "/cos/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)Result<CosUploadVo> upload(@RequestPart("file") MultipartFile file, @RequestParam("path") String path);

在service-driver里引入依赖

<dependency><groupId>com.qcloud</groupId><artifactId>cos_api</artifactId>
</dependency>

把腾讯云需要的值放到相关配置文件中,在common-account.yaml中进行修改,修改其中的值

dc8bfa4390944bd6b238e93edb6bda21.png

在service-driver的config包下创建类读取相关信息配置

@Data
@Component
@ConfigurationProperties(prefix = "tencent.cloud")
public class TencentCloudProperties {private String secretId;private String secretKey;private String region;private String bucketPrivate;
}

CosServiceImpl

	@Autowiredprivate TencentCloudProperties tencentCloudProperties;// 文件上传@Overridepublic CosUploadVo upload(MultipartFile file, String path) {// 1.初始化用户身份信息(secretId, secretKey)String secretId = tencentCloudProperties.getSecretId();String secretKey = tencentCloudProperties.getSecretKey();COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);// 2.设置bucket的地域,COS地域Region region = new Region(tencentCloudProperties.getRegion());ClientConfig clientConfig = new ClientConfig(region);// 这里建议设置使用https协议clientConfig.setHttpProtocol(HttpProtocol.https);// 3.生成cos客户端COSClient cosClient = new COSClient(cred, clientConfig);// 文件上传// 元数据信息ObjectMetadata meta = new ObjectMetadata();meta.setContentLength(file.getSize());meta.setContentEncoding("UTF-8");meta.setContentType(file.getContentType());// 向存储桶中保存文件String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); //文件后缀名String uploadPath = "/driver/" + path + "/" + UUID.randomUUID().toString().replaceAll("-", "") + fileType;// 01.jpg// /driver/auth/0o98754.jpgPutObjectRequest putObjectRequest = null;try {//1 bucket名称//2putObjectRequest = new PutObjectRequest(tencentCloudProperties.getBucketPrivate(),uploadPath,file.getInputStream(),meta);} catch (IOException e) {throw new RuntimeException(e);}putObjectRequest.setStorageClass(StorageClass.Standard);PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); //上传文件cosClient.shutdown();//返回vo对象CosUploadVo cosUploadVo = new CosUploadVo();cosUploadVo.setUrl(uploadPath);//TODO 图片临时访问url,回显使用cosUploadVo.setShowUrl("");return cosUploadVo;}

启动相关服务进行测试

a14b8845f52143d0a00a54355d6c48d5.png

在地址栏输入路径http://localhost:8602/doc.html#/home打开接口文档进行测试
注意:这里需要把CosController接口的@GuiguLogin注解注释了,不然会提示未登录

9da7e803832a4cb295092d31829b9e98.png

上传接口完善,回显图片,可以参考官方文档->生成预签名URL
对CosServiceImpl的upload方法中的代码进行封装

	public COSClient getCosClient(){// 1.初始化用户身份信息(secretId, secretKey)String secretId = tencentCloudProperties.getSecretId();String secretKey = tencentCloudProperties.getSecretKey();COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);// 2.设置bucket的地域,COS地域Region region = new Region(tencentCloudProperties.getRegion());ClientConfig clientConfig = new ClientConfig(region);// 这里建议设置使用https协议clientConfig.setHttpProtocol(HttpProtocol.https);// 3.生成cos客户端COSClient cosClient = new COSClient(cred, clientConfig);return cosClient;}

CosServiceImpl

//获取临时签名URL@Overridepublic String getImageUrl(String path) {if(!StringUtils.hasText(path)) return "";//获取cosclient对象COSClient cosClient = this.getCosClient();//GeneratePresignedUrlRequestGeneratePresignedUrlRequest request =new GeneratePresignedUrlRequest(tencentCloudProperties.getBucketPrivate(),path, HttpMethodName.GET);//设置临时URL有效期为15分钟Date date = new DateTime().plusMinutes(15).toDate();request.setExpiration(date);//调用方法获取URL url = cosClient.generatePresignedUrl(request);cosClient.shutdown();return url.toString();}

将upload的中TODO进行完善
9975c73396944741a86d1f3d34f1597c.png

腾讯云身份证认证接口

司机注册成功之后,应该引导他去做实名认证,这就需要用到腾讯云身份证识别和云存储功能了

542192eeba6d4c518db97df80cea99dc.png

在service-driver引入ocr依赖

<dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><version>${tencentcloud.version}</version>
</dependency>

OcrController

	@Autowiredprivate OcrService ocrService;@Operation(summary = "身份证识别")@PostMapping("/idCardOcr")public Result<IdCardOcrVo> idCardOcr(@RequestPart("file") MultipartFile file) {IdCardOcrVo idCardOcrVo = ocrService.idCardOcr(file);return Result.ok(idCardOcrVo);}

OcrServiceImpl

	@Autowiredprivate TencentCloudProperties tencentCloudProperties;@Autowiredprivate CosService cosService;//身份证识别@Overridepublic IdCardOcrVo idCardOcr(MultipartFile file) {try{//图片转换base64格式字符串byte[] base64 = Base64.encodeBase64(file.getBytes());String fileBase64 = new String(base64);// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密Credential cred = new Credential(tencentCloudProperties.getSecretId(),tencentCloudProperties.getSecretKey());// 实例化一个http选项,可选的,没有特殊需求可以跳过HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint("ocr.tencentcloudapi.com");// 实例化一个client选项,可选的,没有特殊需求可以跳过ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);// 实例化要请求产品的client对象,clientProfile是可选的OcrClient client = new OcrClient(cred,tencentCloudProperties.getRegion(), clientProfile);// 实例化一个请求对象,每个接口都会对应一个request对象IDCardOCRRequest req = new IDCardOCRRequest();//设置文件req.setImageBase64(fileBase64);// 返回的resp是一个IDCardOCRResponse的实例,与请求对象对应IDCardOCRResponse resp = client.IDCardOCR(req);//转换为IdCardOcrVo对象IdCardOcrVo idCardOcrVo = new IdCardOcrVo();if (StringUtils.hasText(resp.getName())) {//身份证正面idCardOcrVo.setName(resp.getName());idCardOcrVo.setGender("男".equals(resp.getSex()) ? "1" : "2");idCardOcrVo.setBirthday(DateTimeFormat.forPattern("yyyy/MM/dd").parseDateTime(resp.getBirth()).toDate());idCardOcrVo.setIdcardNo(resp.getIdNum());idCardOcrVo.setIdcardAddress(resp.getAddress());//上传身份证正面图片到腾讯云cosCosUploadVo cosUploadVo = cosService.upload(file, "idCard");idCardOcrVo.setIdcardFrontUrl(cosUploadVo.getUrl());idCardOcrVo.setIdcardFrontShowUrl(cosUploadVo.getShowUrl());} else {//身份证反面//证件有效期:"2010.07.21-2020.07.21"String idcardExpireString = resp.getValidDate().split("-")[1];idCardOcrVo.setIdcardExpire(DateTimeFormat.forPattern("yyyy.MM.dd").parseDateTime(idcardExpireString).toDate());//上传身份证反面图片到腾讯云cosCosUploadVo cosUploadVo = cosService.upload(file, "idCard");idCardOcrVo.setIdcardBackUrl(cosUploadVo.getUrl());idCardOcrVo.setIdcardBackShowUrl(cosUploadVo.getShowUrl());}return idCardOcrVo;} catch (Exception e) {throw new GuiguException(ResultCodeEnum.DATA_ERROR);}}

service-client定义接口
OcrFeignClient

	/*** 身份证识别* @param file* @return*/@PostMapping(value = "/ocr/idCardOcr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)Result<IdCardOcrVo> idCardOcr(@RequestPart("file") MultipartFile file);

在web-driver中
OcrController

	@Autowiredprivate OcrService ocrService;@Operation(summary = "身份证识别")@GuiguLogin@PostMapping("/idCardOcr")public Result<IdCardOcrVo> uploadDriverLicenseOcr(@RequestPart("file") MultipartFile file) {return Result.ok(ocrService.idCardOcr(file));}

OcrServiceImpl

	@Autowiredprivate OcrFeignClient ocrFeignClient;//身份证识别@Overridepublic IdCardOcrVo idCardOcr(MultipartFile file) {Result<IdCardOcrVo> ocrVoResult = ocrFeignClient.idCardOcr(file);IdCardOcrVo idCardOcrVo = ocrVoResult.getData();return idCardOcrVo;}

腾讯云驾驶证识别接口

在service-driver中
OcrController

	@Operation(summary = "驾驶证识别")@PostMapping("/driverLicenseOcr")public Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file) {return Result.ok(ocrService.driverLicenseOcr(file));}

OcrServiceImpl

	// 驾驶证识别@Overridepublic DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {try{//图片转换base64格式字符串byte[] base64 = Base64.encodeBase64(file.getBytes());String fileBase64 = new String(base64);// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密Credential cred = new Credential(tencentCloudProperties.getSecretId(),tencentCloudProperties.getSecretKey());// 实例化一个http选项,可选的,没有特殊需求可以跳过HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint("ocr.tencentcloudapi.com");// 实例化一个client选项,可选的,没有特殊需求可以跳过ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);// 实例化要请求产品的client对象,clientProfile是可选的OcrClient client = new OcrClient(cred, tencentCloudProperties.getRegion(),clientProfile);// 实例化一个请求对象,每个接口都会对应一个request对象DriverLicenseOCRRequest req = new DriverLicenseOCRRequest();req.setImageBase64(fileBase64);// 返回的resp是一个DriverLicenseOCRResponse的实例,与请求对象对应DriverLicenseOCRResponse resp = client.DriverLicenseOCR(req);//封装到vo对象里面DriverLicenseOcrVo driverLicenseOcrVo = new DriverLicenseOcrVo();if (StringUtils.hasText(resp.getName())) {//驾驶证正面//驾驶证名称要与身份证名称一致driverLicenseOcrVo.setName(resp.getName());driverLicenseOcrVo.setDriverLicenseClazz(resp.getClass_());driverLicenseOcrVo.setDriverLicenseNo(resp.getCardCode());driverLicenseOcrVo.setDriverLicenseIssueDate(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(resp.getDateOfFirstIssue()).toDate());driverLicenseOcrVo.setDriverLicenseExpire(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(resp.getEndDate()).toDate());//上传驾驶证反面图片到腾讯云cosCosUploadVo cosUploadVo = cosService.upload(file, "driverLicense");driverLicenseOcrVo.setDriverLicenseFrontUrl(cosUploadVo.getUrl());driverLicenseOcrVo.setDriverLicenseFrontShowUrl(cosUploadVo.getShowUrl());} else {//驾驶证反面//上传驾驶证反面图片到腾讯云cosCosUploadVo cosUploadVo =  cosService.upload(file, "driverLicense");driverLicenseOcrVo.setDriverLicenseBackUrl(cosUploadVo.getUrl());driverLicenseOcrVo.setDriverLicenseBackShowUrl(cosUploadVo.getShowUrl());}return driverLicenseOcrVo;} catch (Exception e) {e.printStackTrace();throw new GuiguException(ResultCodeEnum.DATA_ERROR);}}

service-client中
OcrFeignClient

	/*** 驾驶证识别* @param file* @return*/@PostMapping(value = "/ocr/driverLicenseOcr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file);

web-driver中
OcrController

	@Operation(summary = "驾驶证识别")@GuiGuLogin@PostMapping("/driverLicenseOcr")public Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file) {return Result.ok(ocrService.driverLicenseOcr(file));}

OcrServiceImpl

	//驾驶证识别@Overridepublic DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {Result<DriverLicenseOcrVo> driverLicenseOcrVoResult = ocrFeignClient.driverLicenseOcr(file);DriverLicenseOcrVo driverLicenseOcrVo = driverLicenseOcrVoResult.getData();return driverLicenseOcrVo;}

启动相关服务进行测试接口,点击开始接单会进入认证界面,这段我就不认证了,没有示例图片。

先到这里哈~接下来的下篇继续,有点多了看着审美疲劳,谢谢你的观赏~~~

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com