身份证识别
This commit is contained in:
@@ -10,6 +10,8 @@ public class CommonConstants {
|
|||||||
|
|
||||||
public static final String REQUEST_ID = "requestId";
|
public static final String REQUEST_ID = "requestId";
|
||||||
|
|
||||||
|
public static final String MESSAGE_ID = "messageId";
|
||||||
|
|
||||||
public static final String ACCESS_TOKEN_KEY = "access_token";
|
public static final String ACCESS_TOKEN_KEY = "access_token";
|
||||||
|
|
||||||
public static final String REFRESH_TOKEN_KEY = "refresh_token";
|
public static final String REFRESH_TOKEN_KEY = "refresh_token";
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.cool.store.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangchenbiao
|
||||||
|
* @FileName: IDCardSideEnum
|
||||||
|
* @Description: 身份证正反面类型
|
||||||
|
* @date 2023-06-16 16:49
|
||||||
|
*/
|
||||||
|
public enum IDCardSideEnum {
|
||||||
|
|
||||||
|
FACE("face", "正面"),
|
||||||
|
BACK("back", "反面")
|
||||||
|
;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
IDCardSideEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,10 +45,9 @@ public class RocketMqLogAspect {
|
|||||||
Object[] args = joinPoint.getArgs();
|
Object[] args = joinPoint.getArgs();
|
||||||
Message message = (Message)args[0];
|
Message message = (Message)args[0];
|
||||||
String traceId = message.getMsgID() + Constants.TOPIC_PARTITION_SEPARATOR + message.getReconsumeTimes();
|
String traceId = message.getMsgID() + Constants.TOPIC_PARTITION_SEPARATOR + message.getReconsumeTimes();
|
||||||
Map<String, String> context = MDC.getCopyOfContextMap();
|
String requestId = message.getUserProperties(CommonConstants.REQUEST_ID);
|
||||||
if(Objects.isNull(context)){
|
MDC.put(CommonConstants.REQUEST_ID, requestId);
|
||||||
MDC.put(CommonConstants.REQUEST_ID, traceId);
|
MDC.put(CommonConstants.MESSAGE_ID, traceId);
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.info("MDC mqBeforeLog", e);
|
log.info("MDC mqBeforeLog", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.cool.store.service;
|
package com.cool.store.service;
|
||||||
|
|
||||||
import com.cool.store.dto.partner.DescribePhoneNumberDTO;
|
import com.cool.store.dto.partner.DescribePhoneNumberDTO;
|
||||||
|
import com.cool.store.enums.IDCardSideEnum;
|
||||||
import com.cool.store.exception.ApiException;
|
import com.cool.store.exception.ApiException;
|
||||||
import com.cool.store.vo.cuser.IdentityCardInfoVO;
|
import com.cool.store.vo.cuser.IdentityCardInfoVO;
|
||||||
|
|
||||||
@@ -24,6 +25,6 @@ public interface AliyunService {
|
|||||||
* @param faceImageUrl
|
* @param faceImageUrl
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl) throws ApiException;
|
IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl, IDCardSideEnum sideEnum) throws ApiException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.aliyun.ocr20191230.models.RecognizeIdentityCardResponseBody;
|
|||||||
import com.aliyun.teaopenapi.models.Config;
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
import com.cool.store.dto.partner.DescribePhoneNumberDTO;
|
import com.cool.store.dto.partner.DescribePhoneNumberDTO;
|
||||||
import com.cool.store.enums.ErrorCodeEnum;
|
import com.cool.store.enums.ErrorCodeEnum;
|
||||||
|
import com.cool.store.enums.IDCardSideEnum;
|
||||||
import com.cool.store.exception.ApiException;
|
import com.cool.store.exception.ApiException;
|
||||||
import com.cool.store.exception.ServiceException;
|
import com.cool.store.exception.ServiceException;
|
||||||
import com.cool.store.service.AliyunService;
|
import com.cool.store.service.AliyunService;
|
||||||
@@ -61,7 +62,7 @@ public class AliyunServiceImpl implements AliyunService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl) throws ApiException {
|
public IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl, IDCardSideEnum sideEnum) throws ApiException {
|
||||||
//todo zcb ak sk替换
|
//todo zcb ak sk替换
|
||||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||||
.setAccessKeyId("LTAI5t9RaXvABZbHvoXjDFJ1")
|
.setAccessKeyId("LTAI5t9RaXvABZbHvoXjDFJ1")
|
||||||
@@ -74,7 +75,7 @@ public class AliyunServiceImpl implements AliyunService {
|
|||||||
InputStream inputStream = url.openConnection().getInputStream();
|
InputStream inputStream = url.openConnection().getInputStream();
|
||||||
com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest recognizeIdentityCardAdvanceRequest = new com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest()
|
com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest recognizeIdentityCardAdvanceRequest = new com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest()
|
||||||
.setImageURLObject(inputStream)
|
.setImageURLObject(inputStream)
|
||||||
.setSide("face");
|
.setSide(sideEnum.getCode());
|
||||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
RecognizeIdentityCardResponse idCardResponse = client.recognizeIdentityCardAdvance(recognizeIdentityCardAdvanceRequest, runtime);
|
RecognizeIdentityCardResponse idCardResponse = client.recognizeIdentityCardAdvance(recognizeIdentityCardAdvanceRequest, runtime);
|
||||||
log.info("身份证解析结果:{}", JSONObject.toJSONString(idCardResponse));
|
log.info("身份证解析结果:{}", JSONObject.toJSONString(idCardResponse));
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.cool.store.entity.HyOpenAreaInfoDO;
|
|||||||
|
|
||||||
import com.cool.store.entity.EnterpriseUserDO;
|
import com.cool.store.entity.EnterpriseUserDO;
|
||||||
import com.cool.store.enums.ErrorCodeEnum;
|
import com.cool.store.enums.ErrorCodeEnum;
|
||||||
|
import com.cool.store.enums.IDCardSideEnum;
|
||||||
import com.cool.store.exception.ApiException;
|
import com.cool.store.exception.ApiException;
|
||||||
import com.cool.store.exception.ServiceException;
|
import com.cool.store.exception.ServiceException;
|
||||||
import com.cool.store.mapper.HyOpenAreaInfoMapper;
|
import com.cool.store.mapper.HyOpenAreaInfoMapper;
|
||||||
@@ -205,7 +206,7 @@ public class TestController {
|
|||||||
@ApiOperation("根据身份证正面解析获取数据")
|
@ApiOperation("根据身份证正面解析获取数据")
|
||||||
public ResponseResult<IdentityCardInfoVO> getIdentityCardInfo(@RequestParam(value = "faceImageUrl")String faceImageUrl){
|
public ResponseResult<IdentityCardInfoVO> getIdentityCardInfo(@RequestParam(value = "faceImageUrl")String faceImageUrl){
|
||||||
try {
|
try {
|
||||||
IdentityCardInfoVO identityCardInfo = aliyunService.getIdentityCardInfo(faceImageUrl);
|
IdentityCardInfoVO identityCardInfo = aliyunService.getIdentityCardInfo(faceImageUrl, IDCardSideEnum.FACE);
|
||||||
return ResponseResult.success(identityCardInfo);
|
return ResponseResult.success(identityCardInfo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException(ErrorCodeEnum.IDENTITY_CARD_PARSE_FAIL);
|
throw new ServiceException(ErrorCodeEnum.IDENTITY_CARD_PARSE_FAIL);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.cool.store.controller;
|
|||||||
|
|
||||||
import com.cool.store.context.PartnerUserHolder;
|
import com.cool.store.context.PartnerUserHolder;
|
||||||
import com.cool.store.enums.ErrorCodeEnum;
|
import com.cool.store.enums.ErrorCodeEnum;
|
||||||
|
import com.cool.store.enums.IDCardSideEnum;
|
||||||
import com.cool.store.exception.ServiceException;
|
import com.cool.store.exception.ServiceException;
|
||||||
import com.cool.store.request.BaseUserInfoRequest;
|
import com.cool.store.request.BaseUserInfoRequest;
|
||||||
import com.cool.store.request.PartnerBaseInfoRequest;
|
import com.cool.store.request.PartnerBaseInfoRequest;
|
||||||
@@ -208,9 +209,9 @@ public class PartnerController {
|
|||||||
|
|
||||||
@GetMapping(path = "/getIdentityCardInfo")
|
@GetMapping(path = "/getIdentityCardInfo")
|
||||||
@ApiOperation("根据身份证正面解析获取数据")
|
@ApiOperation("根据身份证正面解析获取数据")
|
||||||
public ResponseResult<IdentityCardInfoVO> getIdentityCardInfo(@RequestParam(value = "faceImageUrl")String faceImageUrl){
|
public ResponseResult<IdentityCardInfoVO> getIdentityCardInfo(@RequestParam(value = "faceImageUrl")String faceImageUrl, @RequestParam("side")IDCardSideEnum sideEnum){
|
||||||
try {
|
try {
|
||||||
IdentityCardInfoVO identityCardInfo = aliyunService.getIdentityCardInfo(faceImageUrl);
|
IdentityCardInfoVO identityCardInfo = aliyunService.getIdentityCardInfo(faceImageUrl, sideEnum);
|
||||||
return ResponseResult.success(identityCardInfo);
|
return ResponseResult.success(identityCardInfo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException(ErrorCodeEnum.IDENTITY_CARD_PARSE_FAIL);
|
throw new ServiceException(ErrorCodeEnum.IDENTITY_CARD_PARSE_FAIL);
|
||||||
|
|||||||
Reference in New Issue
Block a user