DriverYKDTravel/guns-admin/pom.xml
@@ -26,6 +26,11 @@ <!-- <systemPath>${pom.basedir}/lib/ncoss-java-sdk-1.0.5.jar</systemPath>--> <!-- </dependency>--> <dependency> <groupId>com.tencentcloudapi</groupId> <artifactId>tencentcloud-sdk-java-faceid</artifactId> <version>3.1.1417</version> </dependency> <dependency> <groupId>cn.rongcloud.im</groupId> DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
@@ -383,6 +383,12 @@ @Override public ResultUtil updateDriver(RegisteredWarpper registeredWarpper, Integer uid) throws Exception { Driver driver = this.selectById(uid); Boolean auth = UserUtil.idCardAuth(registeredWarpper.getName(), registeredWarpper.getIdCard()); if(!auth){ return ResultUtil.error("实名认证失败,请输入正确的姓名和身份证号码"); } driver.setName(registeredWarpper.getName()); driver.setSex(registeredWarpper.getSex()); driver.setIdCard(registeredWarpper.getIdCard()); DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/UserUtil.java
New file @@ -0,0 +1,83 @@ package com.stylefeng.guns.modular.system.util; import com.tencentcloudapi.common.AbstractModel; import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.faceid.v20180301.FaceidClient; import com.tencentcloudapi.faceid.v20180301.models.*; public class UserUtil { public static Boolean idCardAuth(String name, String idCard){ try{ // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 // 请参见:https://cloud.tencent.com/document/product/1278/85305 // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 Credential cred = new Credential("AKIDRlDTWVIrDOMAl8LMCoF6nGXdXEh19EHC", "tsjPtFQPwX6kGdpgSSI0UmyFQRZeboqe"); // 使用临时密钥示例 // Credential cred = new Credential("SecretId", "SecretKey", "Token"); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 FaceidClient client = new FaceidClient(cred, "", clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 IdCardVerificationRequest req = new IdCardVerificationRequest(); req.setIdCard(idCard); req.setName(name); // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应 IdCardVerificationResponse resp = client.IdCardVerification(req); // 输出json格式的字符串回包 System.out.println(AbstractModel.toJsonString(resp)); if(resp.getResult().equals("0")){ return true; } } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } return false; } public static void main(String [] args) { try{ // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 // 请参见:https://cloud.tencent.com/document/product/1278/85305 // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 Credential cred = new Credential("AKIDZBew0rJbghYnt20oRr44qQpDViu6HMGx", "pRvd9ez71iBSXO1PYrwnPyMVRAew53mH"); // 使用临时密钥示例 // Credential cred = new Credential("SecretId", "SecretKey", "Token"); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 FaceidClient client = new FaceidClient(cred, "", clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 IdCardVerificationRequest req = new IdCardVerificationRequest(); req.setIdCard("511028200002150816"); req.setName("刘1"); // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应 IdCardVerificationResponse resp = client.IdCardVerification(req); if(resp.getResult().equals("0")){ System.out.println("认证成功"); } // 输出json格式的字符串回包 System.out.println(AbstractModel.toJsonString(resp)); } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } } } ManagementYKDTravel/guns-admin/pom.xml
@@ -17,6 +17,20 @@ <packaging>jar</packaging> <dependencies> <dependency> <groupId>com.tencentcloudapi</groupId> <artifactId>tencentcloud-sdk-java-faceid</artifactId> <version>3.1.1417</version> </dependency> <!-- 腾讯云COS依赖 --> <dependency> <groupId>com.qcloud</groupId> <artifactId>cos_api</artifactId> <version>5.6.155</version> </dependency> <dependency> <groupId>com.stylefeng</groupId> <artifactId>guns-core</artifactId> ManagementYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TDriverController.java
@@ -894,6 +894,10 @@ if(ToolUtil.isEmpty(tDriver.getIdCard())){ return "身份证号不能为空"; } Boolean b = UserUtil.idCardAuth(tDriver.getName(), tDriver.getIdCard()); if(!b){ return "司机姓名和身份证号不匹配"; } if (1 == roleType){ //平台 if (2 == companyType.intValue()){ @@ -1061,6 +1065,12 @@ if(ToolUtil.isEmpty(tDriver.getIdCard())){ return "身份证号不能为空"; } Boolean b = UserUtil.idCardAuth(tDriver.getName(), tDriver.getIdCard()); if(!b){ return "司机姓名和身份证号不匹配"; } if (1 == roleType){ //平台 if (2 == companyType.intValue()){ if (SinataUtil.isNotEmpty(oneId)){ @@ -1530,6 +1540,11 @@ if (count > 0){ continue; } Boolean b = UserUtil.idCardAuth(zero, seven); if(!b){ drivers.add(zero); continue; } //判断所属机构 if (!one.equals("平台司机") && !one.equals("加盟司机")){ return new ErrorTip(500, "所属机构内容不正确"); @@ -1875,6 +1890,11 @@ continue; } Boolean b = UserUtil.idCardAuth(zero, seven); if(!b){ drivers.add(zero); continue; } //判断性别 if (!two.equals("男") && !two.equals("女")){ return new ErrorTip(500, "性别内容不正确"); @@ -2206,6 +2226,12 @@ if (count > 0){ continue; } Boolean b = UserUtil.idCardAuth(zero, four); if(!b){ drivers.add(zero); continue; } //判断性别 if (!one.equals("男") && !one.equals("女")){ return new ErrorTip(500, "性别内容不正确"); ManagementYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/COSUploadService.java
New file @@ -0,0 +1,146 @@ package com.stylefeng.guns.modular.system.util; import com.qcloud.cos.COSClient; import com.qcloud.cos.exception.CosClientException; import com.qcloud.cos.exception.CosServiceException; import com.qcloud.cos.model.PutObjectRequest; import com.qcloud.cos.model.PutObjectResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.UUID; @Service public class COSUploadService { @Autowired private COSClient cosClient; @Value("${cos.bucketName}") private String bucketName; @Value("${cos.base-url}") private String baseUrl; /** * 上传MultipartFile到COS * @param file MultipartFile文件 * @return 文件访问URL */ public String uploadFile(MultipartFile file) { // 参数校验 if (file == null || file.isEmpty()) { throw new IllegalArgumentException("文件不能为空"); } String originalFilename = file.getOriginalFilename(); String fileExtension = getFileExtension(originalFilename); String fileName = generateFileName(fileExtension); String key = fileName; try (InputStream inputStream = file.getInputStream()) { // 创建上传请求 PutObjectRequest putObjectRequest = new PutObjectRequest( bucketName, key, inputStream, null ); // 执行上传 PutObjectResult result = cosClient.putObject(putObjectRequest); // 返回文件访问URL return baseUrl + "/" + key; } catch (IOException e) { throw new RuntimeException("文件读取失败:" + e.getMessage(), e); } catch (CosServiceException e) { throw new RuntimeException("COS服务异常:" + e.getErrorMessage(), e); } catch (CosClientException e) { throw new RuntimeException("COS客户端异常:" + e.getMessage(), e); } } /** * 上传MultipartFile到COS(带自定义文件名) */ public String uploadFile(MultipartFile file, String directory, String customFileName) { if (file == null || file.isEmpty()) { throw new IllegalArgumentException("文件不能为空"); } String fileExtension = getFileExtension(file.getOriginalFilename()); String fileName = customFileName + fileExtension; String key = directory + fileName; try (InputStream inputStream = file.getInputStream()) { PutObjectRequest putObjectRequest = new PutObjectRequest( bucketName, key, inputStream, null ); cosClient.putObject(putObjectRequest); return baseUrl + "/" + key; } catch (IOException e) { throw new RuntimeException("文件读取失败:" + e.getMessage(), e); } } /** * 上传图片并压缩(示例:可以结合其他工具实现) */ public String uploadImage(MultipartFile file, boolean compress) { // 校验图片格式 String contentType = file.getContentType(); if (contentType == null || !contentType.startsWith("image/")) { throw new IllegalArgumentException("只能上传图片文件"); } return uploadFile(file); } /** * 生成唯一文件名 */ private String generateFileName(String fileExtension) { return UUID.randomUUID().toString().replace("-", "") + fileExtension; } /** * 获取文件扩展名 */ private String getFileExtension(String filename) { if (filename == null || filename.lastIndexOf(".") == -1) { return ""; } return filename.substring(filename.lastIndexOf(".")); } /** * 批量上传文件 */ public List<String> uploadFiles(MultipartFile[] files, String directory) { List<String> urls = new ArrayList<>(); for (MultipartFile file : files) { try { String url = uploadFile(file); urls.add(url); } catch (Exception e) { // 记录失败的文件,继续上传其他文件 e.printStackTrace(); } } return urls; } } ManagementYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/UserUtil.java
New file @@ -0,0 +1,84 @@ package com.stylefeng.guns.modular.system.util; import com.tencentcloudapi.common.AbstractModel; import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.faceid.v20180301.FaceidClient; import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationRequest; import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationResponse; public class UserUtil { public static Boolean idCardAuth(String name, String idCard){ try{ // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 // 请参见:https://cloud.tencent.com/document/product/1278/85305 // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 Credential cred = new Credential("AKIDRlDTWVIrDOMAl8LMCoF6nGXdXEh19EHC", "tsjPtFQPwX6kGdpgSSI0UmyFQRZeboqe"); // 使用临时密钥示例 // Credential cred = new Credential("SecretId", "SecretKey", "Token"); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 FaceidClient client = new FaceidClient(cred, "", clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 IdCardVerificationRequest req = new IdCardVerificationRequest(); req.setIdCard(idCard); req.setName(name); // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应 IdCardVerificationResponse resp = client.IdCardVerification(req); // 输出json格式的字符串回包 System.out.println(AbstractModel.toJsonString(resp)); if(resp.getResult().equals("0")){ return true; } } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } return false; } public static void main(String [] args) { try{ // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 // 请参见:https://cloud.tencent.com/document/product/1278/85305 // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 Credential cred = new Credential("AKIDZBew0rJbghYnt20oRr44qQpDViu6HMGx", "pRvd9ez71iBSXO1PYrwnPyMVRAew53mH"); // 使用临时密钥示例 // Credential cred = new Credential("SecretId", "SecretKey", "Token"); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 FaceidClient client = new FaceidClient(cred, "", clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 IdCardVerificationRequest req = new IdCardVerificationRequest(); req.setIdCard("511028200002150816"); req.setName("刘1"); // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应 IdCardVerificationResponse resp = client.IdCardVerification(req); if(resp.getResult().equals("0")){ System.out.println("认证成功"); } // 输出json格式的字符串回包 System.out.println(AbstractModel.toJsonString(resp)); } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } } } UserYKDTravel/guns-admin/pom.xml
@@ -17,6 +17,14 @@ <packaging>jar</packaging> <dependencies> <dependency> <groupId>com.tencentcloudapi</groupId> <artifactId>tencentcloud-sdk-java-faceid</artifactId> <version>3.1.1417</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> UserYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/shunfeng/controller/rideCommentController.java
@@ -21,10 +21,7 @@ import com.stylefeng.guns.modular.system.service.ISystemNoticeService; import com.stylefeng.guns.modular.system.service.ITCarBrandService; import com.stylefeng.guns.modular.system.service.IUserInfoService; import com.stylefeng.guns.modular.system.util.DateUtil; import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; import com.stylefeng.guns.modular.system.util.PushUtil; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.util.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -137,8 +134,8 @@ apply.setName(name); apply.setIdentity(identity); apply.setApplyState(1); //TODO 实名认证 if(true){ Boolean aBoolean = UserUtil.idCardAuth(name, identity); if(aBoolean){ apply.setApplyState(2); /*修改用户实名认证通过*/ UserInfo userInfo=new UserInfo(); UserYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/UserUtil.java
New file @@ -0,0 +1,83 @@ package com.stylefeng.guns.modular.system.util; import com.tencentcloudapi.common.AbstractModel; import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.faceid.v20180301.FaceidClient; import com.tencentcloudapi.faceid.v20180301.models.*; public class UserUtil { public static Boolean idCardAuth(String name, String idCard){ try{ // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 // 请参见:https://cloud.tencent.com/document/product/1278/85305 // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 Credential cred = new Credential("AKIDRlDTWVIrDOMAl8LMCoF6nGXdXEh19EHC", "tsjPtFQPwX6kGdpgSSI0UmyFQRZeboqe"); // 使用临时密钥示例 // Credential cred = new Credential("SecretId", "SecretKey", "Token"); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 FaceidClient client = new FaceidClient(cred, "", clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 IdCardVerificationRequest req = new IdCardVerificationRequest(); req.setIdCard(idCard); req.setName(name); // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应 IdCardVerificationResponse resp = client.IdCardVerification(req); // 输出json格式的字符串回包 System.out.println(AbstractModel.toJsonString(resp)); if(resp.getResult().equals("0")){ return true; } } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } return false; } public static void main(String [] args) { try{ // 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY // 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性 // 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等 // 请参见:https://cloud.tencent.com/document/product/1278/85305 // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 Credential cred = new Credential("AKIDZBew0rJbghYnt20oRr44qQpDViu6HMGx", "pRvd9ez71iBSXO1PYrwnPyMVRAew53mH"); // 使用临时密钥示例 // Credential cred = new Credential("SecretId", "SecretKey", "Token"); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 FaceidClient client = new FaceidClient(cred, "", clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 IdCardVerificationRequest req = new IdCardVerificationRequest(); req.setIdCard("511028200002150816"); req.setName("刘1"); // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应 IdCardVerificationResponse resp = client.IdCardVerification(req); if(resp.getResult().equals("0")){ System.out.println("认证成功"); } // 输出json格式的字符串回包 System.out.println(AbstractModel.toJsonString(resp)); } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } } }