From b70ca2faa5e56f36b93a4a102d56c60d5a66c2c6 Mon Sep 17 00:00:00 2001 From: Guo YuKun <1458871005@qq.com> Date: Fri, 3 May 2024 09:00:44 +0800 Subject: [PATCH] OCR --- bwie-modules/bwie-authentication/pom.xml | 74 +++++++++ .../com/bwie/authentication/AuthenApp.java | 14 ++ .../controller/AuthenticationController.java | 87 +++++++++++ .../service/AuthenticationService.java | 25 +++ .../impl/AuthenticationServiceImpl.java | 143 ++++++++++++++++++ .../bwie/authentication/util/AliveUtil.java | 59 ++++++++ .../bwie/authentication/util/IdCheckUtil.java | 66 ++++++++ .../com/bwie/authentication/util/OCRUtil.java | 84 ++++++++++ .../bwie/authentication/util/OSSupload.java | 105 +++++++++++++ .../util/ThreadPoolExecutorConfig.java | 31 ++++ .../com/bwie/authentication/vo/AliveData.java | 13 ++ .../bwie/authentication/vo/AliveMotions.java | 11 ++ .../com/bwie/authentication/vo/AliveReq.java | 14 ++ .../com/bwie/authentication/vo/AliveRes.java | 19 +++ .../com/bwie/authentication/vo/AuthenReq.java | 29 ++++ .../bwie/authentication/vo/IdCheckReq.java | 13 ++ .../authentication/vo/IdCheckResponse.java | 28 ++++ .../com/bwie/authentication/vo/IdData.java | 16 ++ .../com/bwie/authentication/vo/OCRConfig.java | 13 ++ .../com/bwie/authentication/vo/OCRReq.java | 12 ++ .../bwie/authentication/vo/OCRResponse.java | 27 ++++ .../src/main/resources/bootstrap.yml | 58 +++++++ .../src/main/resources/mapper/SysMapper.xml | 5 + 23 files changed, 946 insertions(+) create mode 100644 bwie-modules/bwie-authentication/pom.xml create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/AuthenApp.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/controller/AuthenticationController.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/AuthenticationService.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/impl/AuthenticationServiceImpl.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/AliveUtil.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/IdCheckUtil.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OCRUtil.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OSSupload.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/ThreadPoolExecutorConfig.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveData.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveMotions.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveReq.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveRes.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AuthenReq.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckReq.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckResponse.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdData.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRConfig.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRReq.java create mode 100644 bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRResponse.java create mode 100644 bwie-modules/bwie-authentication/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-authentication/src/main/resources/mapper/SysMapper.xml diff --git a/bwie-modules/bwie-authentication/pom.xml b/bwie-modules/bwie-authentication/pom.xml new file mode 100644 index 0000000..48eb667 --- /dev/null +++ b/bwie-modules/bwie-authentication/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.bwie + bwie-modules + 1.0.0 + ../pom.xml + + + bwie-authentication + + + 8 + 8 + UTF-8 + + + + + com.bwie + bwie-common + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.aliyun.oss + aliyun-sdk-oss + 3.10.2 + + + io.netty + netty-codec-http + + + + diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/AuthenApp.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/AuthenApp.java new file mode 100644 index 0000000..05de5f3 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/AuthenApp.java @@ -0,0 +1,14 @@ +package com.bwie.authentication; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) +@EnableDiscoveryClient +public class AuthenApp { + public static void main(String[] args) { + SpringApplication.run(AuthenApp.class); + } +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/controller/AuthenticationController.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/controller/AuthenticationController.java new file mode 100644 index 0000000..d634bc2 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/controller/AuthenticationController.java @@ -0,0 +1,87 @@ +package com.bwie.authentication.controller; +import com.bwie.authentication.service.AuthenticationService; +import com.bwie.authentication.vo.AliveReq; +import com.bwie.authentication.vo.AuthenReq; +import com.bwie.authentication.vo.IdCheckReq; +import com.bwie.common.result.Result; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +@RestController +public class AuthenticationController { + private final AuthenticationService authenService; + public AuthenticationController(AuthenticationService authenService) { + this.authenService = authenService; + } + + /** + * 解析身份证 + * @param side + * @param url + * @return + * @throws IOException + */ + @PostMapping("ocrScan") + public Result ocrScan(@RequestParam String side,@RequestParam("file") MultipartFile url) throws IOException { + Result result = authenService.ocrScan(side,url); + return result; + } + + /** + * 单线程的验证,身份证正面,身份证反面,活体检测 + * @param img1 + * @param img2 + * @param movie + * @param authenReq + * @return + * @throws ExecutionException + * @throws InterruptedException + */ + @PostMapping("commitAuthen") + public Result commitAuthen(@RequestParam("face") MultipartFile img1, + @RequestParam("back") MultipartFile img2, + @RequestParam("file") MultipartFile movie, + AuthenReq authenReq) throws ExecutionException, InterruptedException { + Result result = authenService.commitAuthen(img1,img2,movie,authenReq); + return result; + } + + /** + * 照片上传 + * @param multipartFile + * @return + * @throws IOException + */ + @PostMapping("upload") + public Result upload(@RequestParam("file")MultipartFile multipartFile) throws IOException { + String upload = authenService.upload(multipartFile); + return Result.success(upload); + } + + /** + * 身份验证 + * @param ocrReq + * @return + */ + @PostMapping("idCheck") + public Result idCheck(@RequestBody IdCheckReq ocrReq) { + Result result = authenService.idCheck(ocrReq); + return result; + } + + /** + * 视频上传校验 + * @param ocrReq + * @return + */ + @PostMapping("alive") + public Result alive(@RequestBody AliveReq ocrReq) { + Result result = authenService.alive(ocrReq); + return result; + } +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/AuthenticationService.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/AuthenticationService.java new file mode 100644 index 0000000..e777abd --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/AuthenticationService.java @@ -0,0 +1,25 @@ +package com.bwie.authentication.service; + + +import com.bwie.authentication.vo.AliveReq; +import com.bwie.authentication.vo.AuthenReq; +import com.bwie.authentication.vo.IdCheckReq; +import com.bwie.common.result.Result; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public interface AuthenticationService { + Result ocrScan(String side, MultipartFile url) throws IOException;//识别身份证 + Result commitAuthen(MultipartFile img1, MultipartFile img2, MultipartFile movie, AuthenReq authenReq) throws ExecutionException, InterruptedException;//上传图片视频等等进行验证 + + String upload(MultipartFile multipartFile) throws IOException;//普通上传图片等等 + + Result idCheck(IdCheckReq ocrReq);//身份校验信息 + + Result alive(AliveReq ocrReq);//活体检测,上传动作等等 + + + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/impl/AuthenticationServiceImpl.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/impl/AuthenticationServiceImpl.java new file mode 100644 index 0000000..09f17b5 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/service/impl/AuthenticationServiceImpl.java @@ -0,0 +1,143 @@ +package com.bwie.authentication.service.impl; + +import com.bwie.authentication.service.AuthenticationService; +import com.bwie.authentication.util.*; +import com.bwie.authentication.vo.*; +import com.bwie.common.result.Result; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.Serializable; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ThreadPoolExecutor; + +@Service +@Log4j2 +public class AuthenticationServiceImpl implements AuthenticationService { + + private final OSSupload osSupload; + private final IdCheckUtil idCheckUtil; + private final OCRUtil ocrUtil; + private final AliveUtil aliveUtil; + private final ThreadPoolExecutorConfig config; + + public AuthenticationServiceImpl(OSSupload osSupload, IdCheckUtil idCheckUtil, OCRUtil ocrUtil, AliveUtil aliveUtil, ThreadPoolExecutorConfig config) { + this.osSupload = osSupload; + this.idCheckUtil = idCheckUtil; + this.ocrUtil = ocrUtil; + this.aliveUtil = aliveUtil; + this.config = config; + } + + + /** + * 身份证解析,解析正反面 + * @param side + * @param url + * @return + * @throws IOException + */ + @Override + public Result ocrScan( String side, MultipartFile url) throws IOException { + OCRResponse send = ocrUtil.send(side,url); + return Result.success(send); + } + + //验证校验,线程解决 + @Override + public Result commitAuthen(MultipartFile img1, MultipartFile img2, MultipartFile movie, AuthenReq authenReq) throws ExecutionException, InterruptedException { + ThreadPoolExecutor threadPoolExecutor = config.threadPoolExecutor(); + CompletableFuture f1 = CompletableFuture.supplyAsync(() -> { + IdCheckReq idCheckReq = new IdCheckReq(); + idCheckReq.setName(authenReq.getName()); + idCheckReq.setIdCardNo(authenReq.getIdCord()); + IdCheckResponse idcheck = idCheckUtil.idcheck(idCheckReq); + Integer result = idcheck.getIdData().getResult(); + if(result!=0){ + return 1; + } + try { + OCRResponse send = ocrUtil.send("face", img1); + if(send.getNum().equals(authenReq.getIdCord())&&send.getName().equals(authenReq.getName())){ + return 0; + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return 1; + },threadPoolExecutor); + + CompletableFuture f2= CompletableFuture.supplyAsync(() -> { + + String upload = null; + try { + upload = osSupload.upload(movie); + } catch (IOException e) { + throw new RuntimeException(e); + } + + + if(upload==null){ + return false; + } + //url添加数据库 + AliveReq aliveReq = new AliveReq(); + aliveReq.setUrl(upload); + aliveReq.setMotions(authenReq.getMotions()); + AliveRes alive = aliveUtil.alive(aliveReq); + String success = alive.getSuccess(); + return success; + },threadPoolExecutor); + + CompletableFuture f3 = CompletableFuture.supplyAsync(() -> { + String upload = null; + try { + upload = osSupload.upload(img2); + } catch (IOException e) { + throw new RuntimeException(e); + } + String upload2 = null; + try { + upload2 = osSupload.upload(movie); + } catch (IOException e) { + throw new RuntimeException(e); + } + if(upload==null ||upload2==null){ + return 1; + } + //存入数据库 + return 0; + },threadPoolExecutor); + + Integer i = f1.get(); + Serializable serializable = f2.get(); + Integer b1 = f3.get(); + + if ((i == 0) && serializable.equals("true")||b1==0) { + return Result.success(); + } + return Result.error(); + } + + + //图片上传 + @Override + public String upload(MultipartFile multipartFile) throws IOException { + return osSupload.upload(multipartFile); + } + //身份校验 + @Override + public Result idCheck(IdCheckReq ocrReq) { + IdCheckResponse idcheck = idCheckUtil.idcheck(ocrReq); + return Result.success(idcheck); + } + //活体检测,上传视频 + @Override + public Result alive(AliveReq ocrReq) { + AliveRes alive = aliveUtil.alive(ocrReq); + return Result.success(alive); + } +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/AliveUtil.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/AliveUtil.java new file mode 100644 index 0000000..4766ad7 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/AliveUtil.java @@ -0,0 +1,59 @@ +package com.bwie.authentication.util; + +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.bwie.authentication.vo.*; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; +import java.util.Map; + + +@Configuration +public class AliveUtil { + @Value("${alive.appcode}") + private String appcode; + @Value("${alive.host}") + private String host; + + public AliveRes alive(AliveReq aliveReq){ + Map stringStringMap = new HashMap<>(); + stringStringMap.put("url", aliveReq.getUrl()); + stringStringMap.put("motions", aliveReq.getMotions()); + String result = HttpUtil.createPost(host ) // 不在URL中拼接查询参数,因为我们将它们放在请求体中 + .header("Authorization", "APPCODE " + appcode) + .form(stringStringMap) + .execute() + .body(); + System.out.println("result = " + result); + AliveRes aliveRes = JSON.parseObject(result, AliveRes.class); + AliveData aliveData = JSON.parseObject(aliveRes.getData(), AliveData.class); + AliveMotions aliveMotions = JSON.parseObject(aliveData.getMotions(), AliveMotions.class); + aliveData.setAliveMotions(aliveMotions); + aliveRes.setAliveData(aliveData); +// msgResponse.setIdData(idData); + if(aliveRes.getCode()!=200){ + System.out.println("msgResponse = -------------------" + aliveRes.getMsg()); + throw new RuntimeException(aliveRes.getMsg()); + } + return aliveRes; + + } + + + + + + + + + + + + + + + + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/IdCheckUtil.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/IdCheckUtil.java new file mode 100644 index 0000000..6613261 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/IdCheckUtil.java @@ -0,0 +1,66 @@ +package com.bwie.authentication.util; + +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.bwie.authentication.vo.IdCheckReq; +import com.bwie.authentication.vo.IdCheckResponse; + +import com.bwie.authentication.vo.IdData; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class IdCheckUtil { + @Value("${idcheck.appcode}") + private String appcode; + @Value("${idcheck.host}") + private String host; + @Value("${idcheck.path}") + private String path; + + +public IdCheckResponse idcheck(IdCheckReq idCheckReq){ + + Map stringStringMap = new HashMap<>(); + stringStringMap.put("name", idCheckReq.getName()); + stringStringMap.put("idCardNo", idCheckReq.getIdCardNo()); + String result = HttpUtil.createPost(host + path) // 不在URL中拼接查询参数,因为我们将它们放在请求体中 + .header("Authorization", "APPCODE " + appcode) + .form(stringStringMap) + .execute() + .body(); + System.out.println("result = " + result); + IdCheckResponse msgResponse = JSON.parseObject(result, IdCheckResponse.class); + IdData idData = JSON.parseObject(msgResponse.getData(), IdData.class); + msgResponse.setIdData(idData); + if(msgResponse.getCode()!=200){ + System.out.println("msgResponse = -------------------" + msgResponse); + throw new RuntimeException(msgResponse.getMsg()); + } + return msgResponse; + + + + +} + + + + + + + + + + + + + + + + + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OCRUtil.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OCRUtil.java new file mode 100644 index 0000000..4f41f05 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OCRUtil.java @@ -0,0 +1,84 @@ +package com.bwie.authentication.util; +import cn.hutool.core.codec.Base64; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.bwie.authentication.vo.OCRResponse; + + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.multipart.MultipartFile; + + +import java.io.IOException; + + +@Configuration +public class OCRUtil { + @Value("${ocr.appcode}") + private String appcode; + @Value("${ocr.host}") + private String host; + @Value("${ocr.Content-Type}") + private String contentType; + @Value("${ocr.path}") + private String path; + + public OCRResponse send(String side, MultipartFile url) throws IOException { + + +// 对图像进行base64编码 + + String encode = Base64.encode(url.getBytes()); + +// 拼装请求body的json字符串 + JSONObject requestObj = new JSONObject(); + requestObj.put("image", encode); + requestObj.put("side", side); // 假设ocrReq有getSide()方法返回要识别的身份证面(正/反) +// 如果API还有其他配置参数,可以从ocrReq中获取并添加到requestObj中 + + String bodys = requestObj.toString(); + + try { + // 创建并执行POST请求 + String result = HttpUtil.createPost(host + path) // 不在URL中拼接查询参数,因为我们将它们放在请求体中 + .header("Authorization", "APPCODE " + appcode) + .header("Content-Type", contentType) // 确保这里与headers中的Content-Type一致 + .body(bodys) // 设置请求体 + .execute() + .body(); + + System.out.println("result = " + result); + + OCRResponse msgResponse = JSON.parseObject(result, OCRResponse.class); + + // 检查是否成功,而不是使用Assert(Assert通常用于测试) + if (!msgResponse.getSuccess().equals("true")) { + // 处理失败情况,例如记录日志或返回错误信息给调用者 + throw new RuntimeException("扫描失败" ); // 假设OCRResponse有一个getErrorMessage方法 + } + + // 成功处理逻辑 + return msgResponse; + } catch (Exception e) { + // 处理异常,例如记录日志或返回错误信息给调用者 + e.printStackTrace(); + throw new RuntimeException("请求OCR服务时发生异常", e); + } + + } + + + + +} + + + + + + + + + diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OSSupload.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OSSupload.java new file mode 100644 index 0000000..985cb23 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/OSSupload.java @@ -0,0 +1,105 @@ +package com.bwie.authentication.util; + +import com.aliyun.oss.OSSClient; +import com.aliyun.oss.model.ObjectMetadata; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.security.SecureRandom; +import java.text.SimpleDateFormat; +import java.util.Date; +@Log4j2 +@Configuration +public class OSSupload { + @Value("${aliyun.end-point}") + private String endPoint; + + + @Value("${aliyun.access-key-id}") + private String accessKeyId; + + @Value("${aliyun.access-key-secret}") + private String accesskeySecret; + +// @Value("${aliyun.access-pre}") +// private String accessPre; + + @Value("${aliyun.bucket-name}") + private String bucketName; + + public String upload(MultipartFile multipartFile) throws IOException { + + + OSSClient ossClient = new OSSClient(endPoint, accessKeyId, accesskeySecret); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); +// 获取文件名 + String fileName = multipartFile.getOriginalFilename(); +// 获取文件后缀名 + String suffixName = fileName.substring(fileName.lastIndexOf(".")); +// 最后上传生成的文件名 + String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + suffixName; +// oss中的文件夹名 + String objectName = sdf.format(new Date()) + "/" + finalFileName; +// 创建上传文件的元信息,可以通过文件元信息设置HTTP header(设置了才能通过返回的链接直接访问)。 + ObjectMetadata objectMetadata = new ObjectMetadata(); + String contentType = getcontentType(suffixName.substring(suffixName.lastIndexOf("."))); // 注意这里加1 + objectMetadata.setContentType(contentType); + // 设置Content-Disposition为inline + objectMetadata.setContentDisposition("inline"); +// 文件上传 + ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(multipartFile.getBytes()), objectMetadata); +//// 设置URL过期时间为1小时。 +// Date expiration = new Date(System.currentTimeMillis() + 3600 * 1000); + // 构造对象的完整URL + String url = "http://" + bucketName + "." + endPoint + "/" + objectName; + + log.info("阿里云OSS的文件url:{}", url); + ossClient.shutdown(); + return url; + } + public static String getcontentType(String FilenameExtension) { + if (FilenameExtension.equalsIgnoreCase(".bmp")) { + return "image/bmp"; + } + if (FilenameExtension.equalsIgnoreCase(".gif")) { + return "image/gif"; + } + if (FilenameExtension.equalsIgnoreCase(".jpeg") || + FilenameExtension.equalsIgnoreCase(".jpg") || + FilenameExtension.equalsIgnoreCase(".png")) { + return "image/jpg"; + } + if (FilenameExtension.equalsIgnoreCase(".html")) { + return "text/html"; + } + if (FilenameExtension.equalsIgnoreCase(".txt")) { + return "text/plain"; + } + if (FilenameExtension.equalsIgnoreCase(".vsd")) { + return "application/vnd.visio"; + } + if (FilenameExtension.equalsIgnoreCase(".pptx") || + FilenameExtension.equalsIgnoreCase(".ppt")) { + return "application/vnd.ms-powerpoint"; + } + if (FilenameExtension.equalsIgnoreCase(".docx") || + FilenameExtension.equalsIgnoreCase(".doc")) { + return "application/msword"; + } + if (FilenameExtension.equalsIgnoreCase(".xml")) { + return "text/xml"; + } + return "image/jpg"; + } + + + + + + + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/ThreadPoolExecutorConfig.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/ThreadPoolExecutorConfig.java new file mode 100644 index 0000000..e4837e6 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/util/ThreadPoolExecutorConfig.java @@ -0,0 +1,31 @@ +package com.bwie.authentication.util; + +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +@Configuration +@Log4j2 +public class ThreadPoolExecutorConfig { + @Value("${authen.coreSize}") + private Integer coreSize; + @Value("${authen.coreMax}") + private Integer coreMax; + + + + @Bean + public ThreadPoolExecutor threadPoolExecutor(){ +// int coreSize = 3 * Runtime.getRuntime().availableProcessors(); +// int coreMax = coreSize + 30; + ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(coreSize, coreMax, 5, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(100)); + return threadPoolExecutor; + } + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveData.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveData.java new file mode 100644 index 0000000..f122d81 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveData.java @@ -0,0 +1,13 @@ +package com.bwie.authentication.vo; + +import lombok.Data; + +@Data +public class AliveData{ + private boolean passed; + private String feature_image_id; + private String hack_score; + private String order_no; + private String motions; + private AliveMotions aliveMotions; +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveMotions.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveMotions.java new file mode 100644 index 0000000..10064f4 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveMotions.java @@ -0,0 +1,11 @@ +package com.bwie.authentication.vo; + +import lombok.Data; + +@Data +public class AliveMotions{ + private Double score; + private String motion; + private boolean passed; + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveReq.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveReq.java new file mode 100644 index 0000000..5a519f6 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveReq.java @@ -0,0 +1,14 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AliveReq { + private String url; + private String motions; +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveRes.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveRes.java new file mode 100644 index 0000000..c731440 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AliveRes.java @@ -0,0 +1,19 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AliveRes { + + private Integer code; + private String msg; + private String data; + private String success; + private AliveData aliveData; + + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AuthenReq.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AuthenReq.java new file mode 100644 index 0000000..310d5e8 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/AuthenReq.java @@ -0,0 +1,29 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AuthenReq { + + private String motions; + private String name; + private String idCord; + + + + + + + + + + + + + + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckReq.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckReq.java new file mode 100644 index 0000000..935db4a --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckReq.java @@ -0,0 +1,13 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class IdCheckReq { + private String name; + private String idCardNo; +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckResponse.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckResponse.java new file mode 100644 index 0000000..dcf5881 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdCheckResponse.java @@ -0,0 +1,28 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class IdCheckResponse { + + private Integer code; + private String msg; + private String taskNo; // 本次请求号 + private IdData idData; + private String data; + + + + + + + + + + + +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdData.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdData.java new file mode 100644 index 0000000..94bf01e --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/IdData.java @@ -0,0 +1,16 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class IdData { + private Integer result;// 0: 一致,1: 不一致 + private String desc;//描述 + private String sex;//性别 + private String birthday; + private String address;//地址 +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRConfig.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRConfig.java new file mode 100644 index 0000000..a6f76b1 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRConfig.java @@ -0,0 +1,13 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class OCRConfig { + private String side; + private String url; +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRReq.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRReq.java new file mode 100644 index 0000000..a8af575 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRReq.java @@ -0,0 +1,12 @@ +package com.bwie.authentication.vo; + +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.web.multipart.MultipartFile; + +@Data +@NoArgsConstructor +public class OCRReq { + private String side; + private MultipartFile url; +} diff --git a/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRResponse.java b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRResponse.java new file mode 100644 index 0000000..8c91329 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/java/com/bwie/authentication/vo/OCRResponse.java @@ -0,0 +1,27 @@ +package com.bwie.authentication.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class OCRResponse { + private String address; + private String name; + private String sex; + private String num; + private String birth; + private String success; + + + + + + + + + + +} diff --git a/bwie-modules/bwie-authentication/src/main/resources/bootstrap.yml b/bwie-modules/bwie-authentication/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..aeaaea9 --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/resources/bootstrap.yml @@ -0,0 +1,58 @@ +# Tomcat +server: + port: 9004 +# Spring +spring: + main: + allow-circular-references: true + allow-bean-definition-overriding: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: bwie-authentication + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.30.134:8848 + config: + # 配置中心地址 + server-addr: 124.221.30.134:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + + +aliyun: + end-point: oss-cn-shanghai.aliyuncs.com + access-key-id: LTAI5tLHZKYrEbp5FVPa1r6g + access-key-secret: 503OGWrDojxpI5fNrojaXaRJC6ya6y +# access-pre: https://dongxiaojie.oss-cn-shanghai.aliyuncs.com + bucket-name: ueana + +ocr: + host: https://cardnumber.market.alicloudapi.com + path: /rest/160601/ocr/ocr_idcard.json + appcode: 5gvXdYPNlD7orfh8NpVqVhP3m6c0Ki + Content-Type: application/json; charset=UTF-8 + +idcheck: + host: https://jumdata.market.alicloudapi.com + path: /idcard/validate + appcode: 5gvXdYPNlD7orfh8NpVqVhP3m6c0Ki + +alive: + appcode: 5gvXdYPNlD7orfh8NpVqVhP3m6c0Ki + host: https://life.shumaidata.com/checklife + + +authen: + coreSize: 21 + coreMax: 51 diff --git a/bwie-modules/bwie-authentication/src/main/resources/mapper/SysMapper.xml b/bwie-modules/bwie-authentication/src/main/resources/mapper/SysMapper.xml new file mode 100644 index 0000000..d8da7bb --- /dev/null +++ b/bwie-modules/bwie-authentication/src/main/resources/mapper/SysMapper.xml @@ -0,0 +1,5 @@ + + + + +