提交修改

This commit is contained in:
quyixiao 2025-03-22 16:34:56 +08:00
parent 395494a09e
commit 173ed5fe82
9 changed files with 736 additions and 13 deletions

View File

@ -2,10 +2,16 @@ package com.heyu.api.data.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lz.mybatis.plugins.interceptor.utils.PNumberUtils;
import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
@ -56,13 +62,98 @@ public class MapUtils {
} catch (Exception e) {
log.error("getByExpr error map:" + JSON.toJSONString(map) + ",expression" + expression, e);
}
return (T) value;
if(value == null){
return null;
}
return (T)( value + "");
}
public static Object parseBasicTypeWrapper(Class<?> parameterType, Object value) {
if (Number.class.isAssignableFrom(parameterType)) {
if (parameterType == Integer.class || parameterType == int.class) {
return PNumberUtils.objToIntDefault(value, null);
} else if (parameterType == Short.class || parameterType == short.class) {
return PNumberUtils.objToShortDefault(value, null);
} else if (parameterType == Long.class || parameterType == long.class) {
return PNumberUtils.objToLongDefault(value, null);
} else if (parameterType == Float.class || parameterType == float.class) {
return PNumberUtils.objToFloatDefault(value, null);
} else if (parameterType == Double.class || parameterType == double.class) {
return PNumberUtils.objToDoubleDefault(value, null);
} else if (parameterType == Byte.class || parameterType == byte.class) {
return PNumberUtils.objToByteDefault(value, null);
} else if (parameterType == BigDecimal.class) {
return PNumberUtils.objToBigDecimalDefault(value, null);
}
} else if (parameterType == Boolean.class || parameterType == boolean.class) {
return PNumberUtils.objToBooleanDefault(value, null);
} else if (parameterType == Character.class || parameterType == char.class) {
return PNumberUtils.objToCharacterDefault(value, null);
} else if (parameterType == String.class) {
return value !=null ? value.toString() : null ;
}else if (parameterType == Date.class && value instanceof Date){
return value;
} else if (parameterType == Date.class && value instanceof String) {
Object target = parseStr2Date((String) value, YYYY_MM_DD_HH_MM_SS);
if (target == null) {
target = parseStr2Date((String) value, YYYY_MM_DD);
if(target == null){
target = parseStr2Date((String) value, YYYY);
if(target == null){
target = parseStr2Date((String) value, YYYY_MM);
if(target == null){
target = parseStr2Date((String) value, YYYY_MM_DD_HH);
if(target == null){
target = parseStr2Date((String) value, YYYY_MM_DD_HH_MM);
}
}
}
}
}
return target;
}
return null;
}
public static final Date parseStr2Date(String value, final String format) {
if (Objects.isNull(value)) {
return null;
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.parse(value);
} catch (ParseException e) {
}
return null;
}
public static String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM";
public static String YYYY_MM_DD = "yyyy-MM-dd";
public static String YYYY_MM_DD_HH = "yyyy-MM-dd HH";
public static String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
public static String upperCaseFirst(String v) {
String a = v.substring(0, 1).toUpperCase();
String b = v.substring(1);
return a + b;
}
public static boolean isUpperCase(char c) {
if (c >= 'A' && c <= 'Z') {
return true;
}
return false;
}
public static void main(String[] args) {
String a = "{\n" +
" \"words_result\": {\n" +

View File

@ -1,16 +1,16 @@
package com.heyu.api.baidu.handle.certificate;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.certificate.BMultiIdcardRequest;
import com.heyu.api.data.annotation.CustomPath;
import com.heyu.api.data.constants.ApiConstants;
import com.heyu.api.data.utils.StringUtils;
import com.heyu.api.baidu.BaiduBaseHandle;
import com.heyu.api.baidu.request.certificate.BMultiIdcardRequest;
import com.heyu.api.baidu.response.certificate.BMultiIdcardResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740302247547#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8D%A1%E8%AF%81OCR&api=rest%2F2.0%2Focr%2Fv1%2Fmulti_idcard&method=post
* <p>
@ -21,7 +21,7 @@ import org.springframework.stereotype.Component;
@Component
@Slf4j
@CustomPath("multiIdcard")
public class BMultiIdcardHandle extends BaiduBaseHandle<BMultiIdcardRequest, BMultiIdcardResp> {
public class BMultiIdcardHandle extends BaiduBaseHandle<BMultiIdcardRequest, Map> {
@Override
public String getUri() {

View File

@ -11,7 +11,7 @@ public class BMultiIdcardRequest extends BaiduImageUrlRequest {
* - true开启请查看返回参数risk_type
* - false不开启
*/
private String detectRisk = "false";
private String detectRisk = "true";
/**
@ -19,7 +19,7 @@ public class BMultiIdcardRequest extends BaiduImageUrlRequest {
* - true开启请查看返回参数card_quality
* - false不开启
*/
private String detectQuality = "false";
private String detectQuality = "true";
/**
@ -27,7 +27,7 @@ public class BMultiIdcardRequest extends BaiduImageUrlRequest {
* - true检测头像并返回头像的 base64 编码及位置信息
* - false不检测
*/
private String detectPhoto = "false";
private String detectPhoto = "true";
/**
@ -35,6 +35,6 @@ public class BMultiIdcardRequest extends BaiduImageUrlRequest {
* - true检测身份证并返回证照的 base64 编码及位置信息
* - false不检测
*/
private String detectCard = "false";
private String detectCard = "true";
}

View File

@ -0,0 +1,95 @@
package com.heyu.api.controller.certificate;
import com.heyu.api.baidu.handle.certificate.BMarriageCertificateHandle;
import com.heyu.api.baidu.request.certificate.BMarriageCertificateRequest;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.MapUtils;
import com.heyu.api.data.utils.R;
import com.heyu.api.resp.certificate.MarriageCertificateResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740314877734#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8D%A1%E8%AF%81OCR&api=rest%2F2.0%2Focr%2Fv1%2Fmarriage_certificate&method=post
* <p>
* <p>
* 结婚证识别
*/
@Slf4j
@RestController
@RequestMapping("/marriage")
@NotIntercept
public class MarriageCertificateController extends BaseController {
@Autowired
private BMarriageCertificateHandle bMarriageCertificateHandle;
@RequestMapping("/recognize")
@CacheResult
public R recognize(BMarriageCertificateRequest request) {
MarriageCertificateResp resp = new MarriageCertificateResp();
ApiR<Map> bR = bMarriageCertificateHandle.handle(request);
if (bR.isSuccess()) {
Map<String, Object> data = bR.getData();
resp.setManRealName(MapUtils.getByExpr(data, "words_result.姓名_男.word"));
resp.setManRealNameConfidence(MapUtils.getByExpr(data, "words_result.姓名_男.probability"));
resp.setManIdCard(MapUtils.getByExpr(data, "words_result.身份证件号_男.word"));
resp.setManIdCardConfidence(MapUtils.getByExpr(data, "words_result.身份证件号_男.probability"));
resp.setManBirthday(MapUtils.getByExpr(data, "words_result.出生日期_男.word"));
resp.setManBirthdayConfidence(MapUtils.getByExpr(data, "words_result.出生日期_男.probability"));
resp.setManNationality(MapUtils.getByExpr(data, "words_result.国籍_男.word"));
resp.setManNationalityConfidence(MapUtils.getByExpr(data, "words_result.国籍_男.probability"));
resp.setManGender(MapUtils.getByExpr(data, "words_result.性别_男.word"));
resp.setManGenderConfidence(MapUtils.getByExpr(data, "words_result.性别_男.probability"));
resp.setWomanRealName(MapUtils.getByExpr(data, "words_result.姓名_女.word"));
resp.setWomanRealNameConfidence(MapUtils.getByExpr(data, "words_result.姓名_女.probability"));
resp.setWomanIdCard(MapUtils.getByExpr(data, "words_result.身份证件号_女.word"));
resp.setWomanIdCardConfidence(MapUtils.getByExpr(data, "words_result.身份证件号_女.probability"));
resp.setWomanBirthday(MapUtils.getByExpr(data, "words_result.出生日期_女.word"));
resp.setWomanBirthdayConfidence(MapUtils.getByExpr(data, "words_result.出生日期_女.probability"));
resp.setWomanNationality(MapUtils.getByExpr(data, "words_result.国籍_女.word"));
resp.setWomanNationalityConfidence(MapUtils.getByExpr(data, "words_result.国籍_女.probability"));
resp.setWomanGender(MapUtils.getByExpr(data, "words_result.性别_女.word"));
resp.setWomanGenderConfidence(MapUtils.getByExpr(data, "words_result.性别_女.probability"));
resp.setRegisterDate(MapUtils.getByExpr(data, "words_result.登记日期.word"));
resp.setRegisterDateConfidence(MapUtils.getByExpr(data, "words_result.登记日期.probability"));
resp.setDivorceNumber(MapUtils.getByExpr(data, "words_result.结婚证字号.word"));
resp.setDivorceNumberConfidence(MapUtils.getByExpr(data, "words_result.结婚证字号.probability"));
resp.setHolderCertified(MapUtils.getByExpr(data, "words_result.持证人.word"));
resp.setHolderCertifiedConfidence(MapUtils.getByExpr(data, "words_result.持证人.probability"));
resp.setRemark(MapUtils.getByExpr(data, "words_result.备注.word"));
resp.setRemarkConfidence(MapUtils.getByExpr(data, "words_result.备注.probability"));
return R.ok().setData(resp);
}
return R.error();
}
}

View File

@ -0,0 +1,89 @@
package com.heyu.api.controller.idcard;
import com.heyu.api.baidu.handle.certificate.BMultiIdcardHandle;
import com.heyu.api.baidu.request.certificate.BMultiIdcardRequest;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.MapUtils;
import com.heyu.api.data.utils.R;
import com.heyu.api.resp.certificate.IdCardMultiBackResp;
import com.heyu.api.resp.certificate.IdCardMultiFrontResp;
import com.heyu.api.resp.certificate.IdCardMultiResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/***
* 识别身份证
*/
@Slf4j
@RestController
@RequestMapping("/id/card")
@NotIntercept
public class IdCardMultiController extends BaseController {
@Autowired
private BMultiIdcardHandle bMultiIdcardHandle;
@RequestMapping("/recognize")
@CacheResult
public R recognize(BMultiIdcardRequest request) {
IdCardMultiResp resp = new IdCardMultiResp();
ApiR<Map> apiR = bMultiIdcardHandle.handle(request);
if (apiR.isSuccess()) {
Map<String,Object> data = apiR.getData();
IdCardMultiFrontResp front = new IdCardMultiFrontResp();
IdCardMultiBackResp back = new IdCardMultiBackResp();
try {
front.setRiskType(MapUtils.getByExpr(data,"words_result.[0].card_info.risk_type"));//": "normal",
front.setIdcardNumberType(MapUtils.getByExpr(data,"words_result.[0].card_info.idcard_number_type"));//": 1,
front.setEditTool(MapUtils.getByExpr(data,"words_result.[0].card_info.edit_tool"));//": "",
front.setImageStatus(MapUtils.getByExpr(data,"words_result.[0].card_info.image_status"));//": "normal",
front.setCardType(MapUtils.getByExpr(data,"words_result.[0].card_info.card_type"));//": "idcard_front",
front.setDirection(MapUtils.getByExpr(data,"words_result.[0].card_info.direction"));//": 0
front.setAddress(MapUtils.getByExpr(data,"words_result.[0].card_result.住址.words"));
front.setGender(MapUtils.getByExpr(data,"words_result.[0].card_result.性别.words"));
front.setBirthday(MapUtils.getByExpr(data,"words_result.[0].card_result.出生.words"));
front.setIdCardNumber(MapUtils.getByExpr(data,"words_result.[0].card_result.公民身份号码.words"));
front.setNationality(MapUtils.getByExpr(data,"words_result.[0].card_result.民族.words"));
front.setRealName(MapUtils.getByExpr(data,"words_result.[0].card_result.姓名.words"));
} catch (Exception e) {
log.error("正向解决 ",e);
}
try {
back.setRiskType(MapUtils.getByExpr(data,"words_result.[1].card_info.risk_type"));//": "normal",
back.setEditTool(MapUtils.getByExpr(data,"words_result.[1].card_info.edit_tool"));//": "",
back.setImageStatus(MapUtils.getByExpr(data,"words_result.[1].card_info.image_status"));//": "normal",
back.setCardType(MapUtils.getByExpr(data,"words_result.[1].card_info.card_type"));//": "idcard_front",
back.setDirection(MapUtils.getByExpr(data,"words_result.[1].card_info.direction"));//": 0
back.setStartDate(MapUtils.getByExpr(data,"words_result.[1].card_result.签发日期.words"));
back.setIssue(MapUtils.getByExpr(data,"words_result.[1].card_result.签发机关.words"));
back.setEndDate(MapUtils.getByExpr(data,"words_result.[1].card_result.失效日期.words"));
} catch (Exception e) {
log.error("反向解析",e);
}
resp.setFront(front);
resp.setBack(back);
return R.ok().setData(resp);
}
return R.error(apiR.getErrorMsg());
}
}

View File

@ -0,0 +1,63 @@
package com.heyu.api.resp.certificate;
import com.heyu.api.data.dto.BaseResp;
import lombok.Data;
@Data
public class IdCardMultiBackResp extends BaseResp {
/**
* 输入参数 detect_risk = true 则返回该字段识别身份证类型: normal-正常身份证copy-复印件temporary-临时身份证screen-翻拍unknown-其他未知情况
*/
private String riskType;//": "normal",
/***
* 如果参数 detect_risk = true 则返回此字段如果检测身份证被编辑过该字段指定编辑软件名称:Adobe Photoshop CC 2014 (Macintosh),如果没有被编辑过则返回值无此参数
*/
private String editTool;//": "",
/***
* normal-识别正常
* non_idcard-上传的图片中不包含身份证
* blurred-身份证模糊
* other_type_card-其他类型证照
* over_exposure-身份证关键字段反光或过曝
* over_dark-身份证欠曝亮度过低
* unknown-未知状态
*/
private String imageStatus;//": "normal",
/**
* - idcard_front身份证正面头像面
* - idcard_back身份证反面国徽面
*/
private String cardType;//": "idcard_front",
/***
* 图像方向
* - - 1未定义
* - 0正向
* - 1逆时针90度
* - 2逆时针180度
* - 3逆时针270度
*/
private String direction;//": 0
/***
*StartDate 20191011 有效期起始时间格式YYYYMMDD例如19800101即1980年01月01日
*/
private String startDate;
/***
* Issue城步苗族自治县公安局签发机关
*/
private String issue;
/***
* EndDate20391011 有效期结束时间格式YYYYMMDD例如19800101即1980年01月01日
*/
private String endDate;
}

View File

@ -0,0 +1,84 @@
package com.heyu.api.resp.certificate;
import com.heyu.api.data.dto.BaseResp;
import lombok.Data;
@Data
public class IdCardMultiFrontResp extends BaseResp {
/**
* 输入参数 detect_risk = true 则返回该字段识别身份证类型: normal-正常身份证copy-复印件temporary-临时身份证screen-翻拍unknown-其他未知情况
*/
private String riskType;//": "normal",
/**
* 用于校验身份证号码性别出生是否一致输出结果及其对应关系如下
* - 1 身份证正面所有字段全为空
* 0 身份证证号不合法此情况下不返回身份证证号
* 1 身份证证号和性别出生信息一致
* 2 身份证证号和性别出生信息都不一致
* 3 身份证证号和出生信息不一致
* 4 身份证证号和性别信息不一致
*/
private String idcardNumberType;//": 1,
/***
* 如果参数 detect_risk = true 则返回此字段如果检测身份证被编辑过该字段指定编辑软件名称:Adobe Photoshop CC 2014 (Macintosh),如果没有被编辑过则返回值无此参数
*/
private String editTool;//": "",
/***
* normal-识别正常
* non_idcard-上传的图片中不包含身份证
* blurred-身份证模糊
* other_type_card-其他类型证照
* over_exposure-身份证关键字段反光或过曝
* over_dark-身份证欠曝亮度过低
* unknown-未知状态
*/
private String imageStatus;//": "normal",
/**
* - idcard_front身份证正面头像面
* - idcard_back身份证反面国徽面
*/
private String cardType;//": "idcard_front",
/***
* 图像方向
* - - 1未定义
* - 0正向
* - 1逆时针90度
* - 2逆时针180度
* - 3逆时针270度
*/
private String direction;//": 0
/**
* 详细地址
*/
private String address;
/**
* 性别名称
*/
private String gender;
/**
* 生日
*/
private String birthday;
/**
* 请求订单编号
*/
protected String idCardNumber;
/***
* 民族
*/
private String nationality;
/**
* 真实姓名
*/
private String realName;
}

View File

@ -0,0 +1,140 @@
package com.heyu.api.resp.certificate;
import com.heyu.api.data.dto.BaseResp;
import lombok.Data;
@Data
public class IdCardMultiResp extends BaseResp {
private IdCardMultiFrontResp front;
private IdCardMultiBackResp back;
}
/**
* {
* "words_result": [
* {
* "card_info": {
* "card_location": {
* "top": 121,
* "left": 687,
* "width": 501,
* "height": 323
* },
* "risk_type": "normal",
* "idcard_number_type": 1,
* "edit_tool": "",
* "image_status": "normal",
* "card_type": "idcard_front",
* "direction": 0
* },
* "card_result": {
* "姓名": {
* "words": "王媛",
* "location": {
* "top": 158,
* "left": 788,
* "width": 67,
* "height": 26
* }
* },
* "民族": {
* "words": "",
* "location": {
* "top": 204,
* "left": 884,
* "width": 19,
* "height": 21
* }
* },
* "住址": {
* "words": "北京市海淀区西北旺东路10号院",
* "location": {
* "top": 282,
* "left": 782,
* "width": 205,
* "height": 51
* }
* },
* "公民身份号码": {
* "words": "410433199510104518",
* "location": {
* "top": 385,
* "left": 863,
* "width": 266,
* "height": 29
* }
* },
* "出生": {
* "words": "19951010",
* "location": {
* "top": 240,
* "left": 784,
* "width": 163,
* "height": 25
* }
* },
* "性别": {
* "words": "",
* "location": {
* "top": 202,
* "left": 789,
* "width": 19,
* "height": 22
* }
* }
* }
* },
* {
* "card_info": {
* "card_location": {
* "top": 526,
* "left": 66,
* "width": 524,
* "height": 323
* },
* "risk_type": "normal",
* "edit_tool": "",
* "image_status": "normal",
* "card_type": "idcard_back",
* "direction": 0
* },
* "card_result": {
* "失效日期": {
* "words": "20350413",
* "location": {
* "top": 801,
* "left": 394,
* "width": 95,
* "height": 19
* }
* },
* "签发机关": {
* "words": "北京市公安局海淀分局",
* "location": {
* "top": 760,
* "left": 290,
* "width": 180,
* "height": 19
* }
* },
* "签发日期": {
* "words": "20150413",
* "location": {
* "top": 801,
* "left": 289,
* "width": 89,
* "height": 19
* }
* }
* }
* }
* ],
* "direction": 0,
* "log_id": 1397109704106180608
* }
*/

View File

@ -0,0 +1,161 @@
package com.heyu.api.resp.certificate;
import com.heyu.api.data.dto.BaseResp;
import lombok.Data;
@Data
public class MarriageCertificateResp extends BaseResp {
/***
* 姓名_男
*/
private String manRealName;
/***
* 姓名_男 置信度
*/
private String manRealNameConfidence;
/***
* 身份证件号_男
*/
private String manIdCard;
/***
* 身份证件号_男 置信度
*/
private String manIdCardConfidence;
/**
* 出生日期_男
*/
private String manBirthday;
/**
* 出生日期_男 置信度
*/
private String manBirthdayConfidence;
/**
* 国籍_男
*
*/
private String manNationality;
/***
* 国籍_男 置信度
*/
private String manNationalityConfidence;
/***
* 性别_男
*/
private String manGender;
/***
* 性别_男 置信度
*/
private String manGenderConfidence;
/***
* 姓名_女
*/
private String womanRealName;
/***
* 姓名_女 置信度
*/
private String womanRealNameConfidence;
/***
* 身份证件号_女
*/
private String womanIdCard;
/***
* 身份证件号_女 置信度
*/
private String womanIdCardConfidence;
/***
* 出生日期_女
*/
private String womanBirthday;
/***
* 出生日期_女 置信度
*/
private String womanBirthdayConfidence;
/***
* 国籍_女
*/
private String womanNationality;
/***
* 出生日期_女 置信度
*/
private String womanNationalityConfidence;
/***
* 性别_女
*/
private String womanGender;
/***
* 性别_女 置信度
*/
private String womanGenderConfidence;
/***
* 登记日期
*
*/
private String registerDate ;
/***
* 登记日期 置信度
*
*/
private String registerDateConfidence;
/***
* 结婚证字号
*/
private String divorceNumber;
/***
* 结婚证字号 置信度
*/
private String divorceNumberConfidence;
/***
* 持证人
*/
private String holderCertified;
/***
* 持证人 置信度
*/
private String holderCertifiedConfidence;
/***
* 备注
*/
private String remark;
/***
* 备注 置信度
*/
private String remarkConfidence;
}