diff --git a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java index e6650568f..6e2837911 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java @@ -44,11 +44,10 @@ public enum ErrorCodeEnum { USER_GROUP_NAME_EXIST(1021076, "用户分组名称已存在", null), USER_GROUP_NOT_EXIST(1021077, "用户分组不存在", null), GET_INFO_ERROR(1021078, "获取信息异常", null), - - - - + GET_PHONENUMBER_INFO_ERROR(1021079, "手机号归属地获取异常", null), + IDENTITY_CARD_PARSE_FAIL(1021080, "身份证解析失败", null), PARAMS_REQUIRED(400002, "参数缺失!", null), + DATA_CONVERT_ERROR(400002, "日期转换异常!", null), LINE_ID_IS_NOT_EXIST(500001, "线索ID不存在!", null), diff --git a/coolstore-partner-model/src/main/java/com/cool/store/dto/partner/DescribePhoneNumberDTO.java b/coolstore-partner-model/src/main/java/com/cool/store/dto/partner/DescribePhoneNumberDTO.java new file mode 100644 index 000000000..5ca976af0 --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/dto/partner/DescribePhoneNumberDTO.java @@ -0,0 +1,33 @@ +package com.cool.store.dto.partner; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author zhangchenbiao + * @FileName: DescribePhoneNumberDTO + * @Description:手机号归属 + * @date 2023-06-15 20:07 + */ +@Data +public class DescribePhoneNumberDTO { + + @ApiModelProperty("基础运营商") + public String basicCarrier; + + @ApiModelProperty("实际运营商") + public String carrier; + + @ApiModelProperty("是否携号转网") + public Boolean isNumberPortability; + + @ApiModelProperty("号码归属号段") + public Long numberSegment; + + @ApiModelProperty("号码归属城市") + public String city; + + @ApiModelProperty("号码归属省份") + public String province; + +} diff --git a/coolstore-partner-model/src/main/java/com/cool/store/vo/cuser/IdentityCardInfoVO.java b/coolstore-partner-model/src/main/java/com/cool/store/vo/cuser/IdentityCardInfoVO.java new file mode 100644 index 000000000..7bea7bbe1 --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/vo/cuser/IdentityCardInfoVO.java @@ -0,0 +1,41 @@ +package com.cool.store.vo.cuser; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author zhangchenbiao + * @FileName: IdentityCardInfoVO + * @Description: + * @date 2023-06-16 10:18 + */ +@Data +public class IdentityCardInfoVO { + + @ApiModelProperty("用户名") + private String username; + + @ApiModelProperty("地址") + private String liveAddress; + + @ApiModelProperty("出生日期") + private String birthdate; + + @ApiModelProperty("性别") + private String sex; + + @ApiModelProperty("身份证号") + private String idCard; + + @ApiModelProperty("民族") + private String nation; + + public IdentityCardInfoVO(String username, String liveAddress, String birthdate, String sex, String idCard, String nation) { + this.username = username; + this.liveAddress = liveAddress; + this.birthdate = birthdate; + this.sex = sex; + this.idCard = idCard; + this.nation = nation; + } +} diff --git a/coolstore-partner-service/coolstore-partner-service.iml b/coolstore-partner-service/coolstore-partner-service.iml index 6cda7d6d9..f7543f465 100644 --- a/coolstore-partner-service/coolstore-partner-service.iml +++ b/coolstore-partner-service/coolstore-partner-service.iml @@ -142,5 +142,17 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/coolstore-partner-service/pom.xml b/coolstore-partner-service/pom.xml index 1422f9c1d..97abbfd41 100644 --- a/coolstore-partner-service/pom.xml +++ b/coolstore-partner-service/pom.xml @@ -63,6 +63,10 @@ com.aliyun dytnsapi20200217 + + com.aliyun + ocr20191230 + \ No newline at end of file diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/AliyunService.java b/coolstore-partner-service/src/main/java/com/cool/store/service/AliyunService.java new file mode 100644 index 000000000..f8a02ab6d --- /dev/null +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/AliyunService.java @@ -0,0 +1,28 @@ +package com.cool.store.service; + +import com.cool.store.dto.partner.DescribePhoneNumberDTO; +import com.cool.store.vo.cuser.IdentityCardInfoVO; + +/** + * @author zhangchenbiao + * @FileName: AliyunService + * @Description:阿里云相关服务 + * @date 2023-06-15 20:04 + */ +public interface AliyunService { + + /** + * 获取手机号归属信息 + * @param phoneNumber + * @return + */ + DescribePhoneNumberDTO getPhoneNumberAttribute(String phoneNumber); + + /** + * 根据身份证正面获取信息 + * @param faceImageUrl + * @return + */ + IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl); + +} diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/AliyunServiceImpl.java b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/AliyunServiceImpl.java new file mode 100644 index 000000000..00df38d16 --- /dev/null +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/AliyunServiceImpl.java @@ -0,0 +1,116 @@ +package com.cool.store.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.aliyun.dytnsapi20200217.Client; +import com.aliyun.dytnsapi20200217.models.DescribePhoneNumberOperatorAttributeRequest; +import com.aliyun.dytnsapi20200217.models.DescribePhoneNumberOperatorAttributeResponse; +import com.aliyun.ocr20191230.models.RecognizeIdentityCardResponse; +import com.aliyun.ocr20191230.models.RecognizeIdentityCardResponseBody; +import com.aliyun.tea.TeaException; +import com.aliyun.tea.TeaModel; +import com.aliyun.teaopenapi.models.Config; +import com.cool.store.dto.partner.DescribePhoneNumberDTO; +import com.cool.store.enums.ErrorCodeEnum; +import com.cool.store.exception.ServiceException; +import com.cool.store.service.AliyunService; +import com.cool.store.vo.cuser.IdentityCardInfoVO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Optional; + +/** + * @author zhangchenbiao + * @FileName: AliyunServiceImpl + * @Description: + * @date 2023-06-15 20:04 + */ +@Slf4j +@Service +public class AliyunServiceImpl implements AliyunService { + + @Override + public DescribePhoneNumberDTO getPhoneNumberAttribute(String phoneNumber) { + try { + Config config = new Config(); + //todo zcb ak sk替换 + config.accessKeyId = "LTAI5t9RaXvABZbHvoXjDFJ1"; + config.accessKeySecret = "zhOK7WWo3yGoUWkOMaatty19k25CMd"; + Client client = new Client(config); + DescribePhoneNumberOperatorAttributeRequest request = new DescribePhoneNumberOperatorAttributeRequest(); + request.authCode = "Y81FVZepk6"; + request.inputNumber = phoneNumber; + request.mask = "NORMAL"; + DescribePhoneNumberOperatorAttributeResponse response = client.describePhoneNumberOperatorAttribute(request); + String code = response.body.code; + if (!com.aliyun.teautil.Common.equalString(code, "OK")) { + log.error("错误信息:" , response.body.message + ""); + throw new ServiceException(ErrorCodeEnum.GET_PHONENUMBER_INFO_ERROR); + } + return JSONObject.parseObject(JSONObject.toJSONString(response.body.data), DescribePhoneNumberDTO.class); + } catch (Exception e) { + log.error("获取手机号异常:", e); + throw new ServiceException(ErrorCodeEnum.GET_PHONENUMBER_INFO_ERROR); + } + } + + @Override + public IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl) { + //todo zcb ak sk替换 + com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() + .setAccessKeyId("LTAI5t9RaXvABZbHvoXjDFJ1") + .setAccessKeySecret("zhOK7WWo3yGoUWkOMaatty19k25CMd"); + // 访问的域名 + config.endpoint = "ocr.cn-shanghai.aliyuncs.com"; + try { + com.aliyun.ocr20191230.Client client = new com.aliyun.ocr20191230.Client(config); + URL url = new URL(faceImageUrl); + InputStream inputStream = url.openConnection().getInputStream(); + com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest recognizeIdentityCardAdvanceRequest = new com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest() + .setImageURLObject(inputStream) + .setSide("face"); + com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); + RecognizeIdentityCardResponse idCardResponse = client.recognizeIdentityCardAdvance(recognizeIdentityCardAdvanceRequest, runtime); + log.info("身份证解析结果:{}", JSONObject.toJSONString(idCardResponse)); + RecognizeIdentityCardResponseBody.RecognizeIdentityCardResponseBodyDataFrontResult frontResult = Optional.ofNullable(idCardResponse).map(o -> o.getBody()).map(o -> o.data).map(o -> o.frontResult).orElse(null); + String username = frontResult.name; + String liveAddress = frontResult.address; + String birthdate = frontResult.birthDate; + if(StringUtils.isNotBlank(birthdate)){ + birthdate = convertDate(birthdate, "yyyyMMdd"); + } + String sex = frontResult.gender; + String idCard = frontResult.IDNumber; + String nation = frontResult.nationality; + IdentityCardInfoVO result = new IdentityCardInfoVO(username, liveAddress, birthdate, sex, idCard, nation); + log.info("身份证解析:{}", JSONObject.toJSONString(result)); + return result; + } catch (com.aliyun.tea.TeaException e) { + log.error("身份证解析报错TeaException:{}", e); + } catch (MalformedURLException e) { + log.error("身份证解析报错MalformedURLException:{}", e); + } catch (IOException e) { + log.error("身份证解析报错IOException:{}", e); + } catch (Exception e) { + log.error("身份证解析报错Exception:{}", e); + } + return null; + } + + public static String convertDate(String date, String format) { + try { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format); + LocalDate localDate = LocalDate.parse(date, formatter); + return localDate.toString(); + } catch (Exception e) { + throw new ServiceException(ErrorCodeEnum.DATA_CONVERT_ERROR); + } + } +} diff --git a/coolstore-partner-webb/coolstore-partner-webb.iml b/coolstore-partner-webb/coolstore-partner-webb.iml index ab3cdc788..af0ff3164 100644 --- a/coolstore-partner-webb/coolstore-partner-webb.iml +++ b/coolstore-partner-webb/coolstore-partner-webb.iml @@ -107,6 +107,18 @@ + + + + + + + + + + + + diff --git a/coolstore-partner-webc/coolstore-partner-webc.iml b/coolstore-partner-webc/coolstore-partner-webc.iml index bef9271d3..9cfa8ce03 100644 --- a/coolstore-partner-webc/coolstore-partner-webc.iml +++ b/coolstore-partner-webc/coolstore-partner-webc.iml @@ -105,6 +105,18 @@ + + + + + + + + + + + + diff --git a/coolstore-partner-webc/src/main/java/com/cool/store/controller/PartnerController.java b/coolstore-partner-webc/src/main/java/com/cool/store/controller/PartnerController.java index d589d8732..e658a9310 100644 --- a/coolstore-partner-webc/src/main/java/com/cool/store/controller/PartnerController.java +++ b/coolstore-partner-webc/src/main/java/com/cool/store/controller/PartnerController.java @@ -1,13 +1,17 @@ package com.cool.store.controller; +import com.cool.store.enums.ErrorCodeEnum; +import com.cool.store.exception.ServiceException; import com.cool.store.request.BaseUserInfoRequest; import com.cool.store.request.PartnerBaseInfoRequest; import com.cool.store.request.PartnerClerkInfoRequest; import com.cool.store.request.PartnerIntentInfoRequest; import com.cool.store.response.ResponseResult; +import com.cool.store.service.AliyunService; import com.cool.store.service.HyPartnerIntentInfoService; import com.cool.store.service.PartnerUserInfoService; import com.cool.store.vo.*; +import com.cool.store.vo.cuser.IdentityCardInfoVO; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -34,7 +38,10 @@ public class PartnerController { private PartnerUserInfoService partnerUserInfoService; @Resource - HyPartnerIntentInfoService hyPartnerIntentInfoService; + private HyPartnerIntentInfoService hyPartnerIntentInfoService; + + @Resource + private AliyunService aliyunService; @PostMapping(path = "/applyBaseInfo") @ApiOperation("提交基本信息") @@ -195,4 +202,16 @@ public class PartnerController { return ResponseResult.success(); } + + @GetMapping(path = "/getIdentityCardInfo") + @ApiOperation("根据身份证正面解析获取数据") + public ResponseResult getIdentityCardInfo(@RequestParam(value = "faceImageUrl")String faceImageUrl){ + try { + IdentityCardInfoVO identityCardInfo = aliyunService.getIdentityCardInfo(faceImageUrl); + return ResponseResult.success(identityCardInfo); + } catch (Exception e) { + throw new ServiceException(ErrorCodeEnum.IDENTITY_CARD_PARSE_FAIL); + } + } + } diff --git a/pom.xml b/pom.xml index 02ccc0a58..2522598c4 100644 --- a/pom.xml +++ b/pom.xml @@ -181,6 +181,11 @@ dytnsapi20200217 1.0.28 + + com.aliyun + ocr20191230 + 1.0.26 +