Commit df1d7dc5 authored by kang.nie@inzymeits.com's avatar kang.nie@inzymeits.com
Browse files

初始化代码

parent 565dfc9e
Pipeline #3110 failed with stages
in 0 seconds
package com.cusc.nirvana.user.rnr.openapi.util;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.fp.common.ResponseCode;
import com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum;
import com.cusc.nirvana.user.rnr.openapi.constants.IdentifyConstants;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.Optional;
/**
* 校验工具类
*
* @author yubo
* @since 2022-04-19 13:49
*/
public class ValidationUtil {
/**
* 检查手机格式
* @param phone
* @return
*/
public static Response checkPhone(String phone){
if(!phone.matches(IdentifyConstants.PHONE_REGEX)){
return Response.createError("手机格式错误", ResponseCode.INVALID_DATA.getCode());
}
return Response.createSuccess();
}
/**
* 使用正则表达式检查证件合法性
*
* @param certType
* @param identityNumber
*/
public static Response checkIdentifyNumber(String certType, String identityNumber) {
Optional<CertTypeEnum> first = Arrays.stream(CertTypeEnum.values())
.filter(c -> StringUtils.equalsIgnoreCase(c.getCode(), certType))
.findFirst();
if (!first.isPresent()) {
return Response.createError("证件类型错误", ResponseCode.INVALID_DATA.getCode());
}
CertTypeEnum certTypeEnum = first.get();
//如果是身份证,判断号码是否合法
if (certTypeEnum == CertTypeEnum.IDCARD && !identityNumber.matches(IdentifyConstants.ID_CARD_REGEX)) {
return Response.createError("身份证号码格式错误", ResponseCode.INVALID_DATA.getCode());
} else if (certTypeEnum == CertTypeEnum.HKIDCARD && !identityNumber.matches(IdentifyConstants.HK_MACAU_REGEX)) {
return Response.createError("港澳通行证号码格式错误", ResponseCode.INVALID_DATA.getCode());
} else if (certTypeEnum == CertTypeEnum.TAIBAOZHENG && !identityNumber.matches(IdentifyConstants.HK_TAIWAN_CITIZEN_REGEX)) {
return Response.createError("台湾居民来往大陆通行证号码格式错误", ResponseCode.INVALID_DATA.getCode());
}
return Response.createSuccess();
}
//验证证件照片数量
//身份证、港澳通行证、台湾通行证 需要正反面两张照片
public static Response checkIdentifyPics(String certType, int size) {
// if (StringUtils.equalsIgnoreCase(CertTypeEnum.IDCARD.getCode(), certType)
// || StringUtils.equalsIgnoreCase(CertTypeEnum.HKIDCARD.getCode(), certType)
// || StringUtils.equalsIgnoreCase(CertTypeEnum.TAIBAOZHENG.getCode(), certType)) {
if (size < 2) {
return Response.createError("证件正反面照片不能为空", ResponseCode.INVALID_DATA.getCode());
}
// }
// if (size < 1) {
// return Response.createError("证件照不能为空", ResponseCode.INVALID_DATA.getCode());
// }
return Response.createSuccess();
}
}
This diff is collapsed.
#server:
# port: 8082
spring:
application:
name: local-rnr-openapi
# profiles:
# active: dev
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment