Compare commits
4 Commits
1a5ff59324
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 35260a773e | |||
| 377a592195 | |||
| 8e081af4d8 | |||
| 1555fe1898 |
@@ -13,9 +13,8 @@ import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.love.entity.Certificate;
|
||||
import com.gxwebsoft.love.param.CertificateParam;
|
||||
import com.gxwebsoft.love.service.CertificateService;
|
||||
import com.gxwebsoft.love.vo.idcheck.BackRecognitionResult;
|
||||
import com.gxwebsoft.love.vo.idcheck.FrontRecognitionResult;
|
||||
import com.gxwebsoft.love.vo.idcheck.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.gxwebsoft.oa.vo.IdcardRespVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -33,6 +32,7 @@ import java.util.stream.Collectors;
|
||||
* @since 2023-06-24 11:18:52
|
||||
*/
|
||||
@Api(tags = "证件管理记录表管理")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/love/certificate")
|
||||
public class CertificateController extends BaseController {
|
||||
@@ -97,33 +97,24 @@ public class CertificateController extends BaseController {
|
||||
return fail("请上传身份证照片", certificate);
|
||||
}
|
||||
|
||||
// 验证正面
|
||||
Response<FrontRecognitionResult> front = certificateService.idcardfrontrecongnition(collect.get(0));
|
||||
if (front.getError_code() != 0) {
|
||||
return fail(front.getReason());
|
||||
// 身份证OCR识别(正反面合并,尽力而为:失败不阻断业务,识别成功且信息一致才置为已认证)
|
||||
try {
|
||||
IdcardRespVO resp = certificateService.idcardOcr(collect.get(0), collect.get(1));
|
||||
if (resp != null && "FP00000".equals(resp.getCode())
|
||||
&& certificate.getCertificateCode().equals(resp.getIdCardNo())
|
||||
&& certificate.getRealName().equals(resp.getName())) {
|
||||
certificate.setStatus(30);
|
||||
User user = new User();
|
||||
user.setUserId(loginUser.getUserId());
|
||||
user.setCertification(1);
|
||||
userService.updateById(user);
|
||||
} else {
|
||||
log.warn("身份证OCR识别未通过或跳过,证件先按待审核保存, code={}", resp == null ? "null" : resp.getCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("身份证OCR识别调用异常,跳过校验,证件先按待审核保存", e);
|
||||
}
|
||||
|
||||
|
||||
// 验证反面
|
||||
Response<BackRecognitionResult> back = certificateService.idcardbackrecongnition(collect.get(1));
|
||||
if (back.getError_code() != 0) {
|
||||
return fail(back.getReason());
|
||||
}
|
||||
|
||||
certificate.setStatus(30);
|
||||
|
||||
// 信息是否一致
|
||||
if (!certificate.getCertificateCode().equals(front.getResult().getIdcardno())) {
|
||||
return fail("认证失败", certificate);
|
||||
}
|
||||
if (!certificate.getRealName().equals(front.getResult().getName())) {
|
||||
return fail("认证失败", certificate);
|
||||
}
|
||||
User user = new User();
|
||||
user.setUserId(loginUser.getUserId());
|
||||
user.setCertification(1);
|
||||
userService.updateById(user);
|
||||
|
||||
}
|
||||
// 房屋认证
|
||||
if ("house".equals(certificate.getCertificateType())) {
|
||||
|
||||
@@ -4,9 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.love.entity.Certificate;
|
||||
import com.gxwebsoft.love.param.CertificateParam;
|
||||
import com.gxwebsoft.love.vo.idcheck.BackRecognitionResult;
|
||||
import com.gxwebsoft.love.vo.idcheck.FrontRecognitionResult;
|
||||
import com.gxwebsoft.love.vo.idcheck.Response;
|
||||
import com.gxwebsoft.oa.vo.IdcardRespVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,10 +40,15 @@ public interface CertificateService extends IService<Certificate> {
|
||||
*/
|
||||
Certificate getByIdRel(Integer certificateId);
|
||||
|
||||
/**
|
||||
* 身份证OCR识别(正反面合并识别)
|
||||
*
|
||||
* @param frontImageUrl 正面图片 URL
|
||||
* @param backImageUrl 反面图片 URL
|
||||
* @return 识别结果
|
||||
*/
|
||||
IdcardRespVO idcardOcr(String frontImageUrl, String backImageUrl);
|
||||
|
||||
boolean verifyIdcard(Certificate param, List<String> files);
|
||||
|
||||
Response<FrontRecognitionResult> idcardfrontrecongnition(String imageUrl);
|
||||
|
||||
Response<BackRecognitionResult> idcardbackrecongnition(String imageUrl);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.gxwebsoft.love.service.impl;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.common.core.utils.HttpUtils;
|
||||
import com.gxwebsoft.common.core.utils.ImageUtil;
|
||||
@@ -12,9 +11,7 @@ import com.gxwebsoft.love.entity.Certificate;
|
||||
import com.gxwebsoft.love.mapper.CertificateMapper;
|
||||
import com.gxwebsoft.love.param.CertificateParam;
|
||||
import com.gxwebsoft.love.service.CertificateService;
|
||||
import com.gxwebsoft.love.vo.idcheck.BackRecognitionResult;
|
||||
import com.gxwebsoft.love.vo.idcheck.FrontRecognitionResult;
|
||||
import com.gxwebsoft.love.vo.idcheck.Response;
|
||||
import com.gxwebsoft.oa.vo.IdcardRespVO;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
@@ -22,10 +19,12 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 证件管理记录表Service实现
|
||||
@@ -39,12 +38,13 @@ public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certi
|
||||
@Resource
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
private String appcode = "566b5786c5874464909d8c0b7f64cdc7";
|
||||
private static final String HOST = "https://miitangs14.market.alicloudapi.com";
|
||||
private static final String APP_CODE = "1390018309a443c695c98c8da2bed691";
|
||||
private static final String SUCCESS_CODE = "FP00000";
|
||||
|
||||
@Override
|
||||
public PageResult<Certificate> pageRel(CertificateParam param) {
|
||||
PageParam<Certificate, CertificateParam> page = new PageParam<>(param);
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
List<Certificate> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
@@ -52,9 +52,7 @@ public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certi
|
||||
@Override
|
||||
public List<Certificate> listRel(CertificateParam param) {
|
||||
List<Certificate> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<Certificate, CertificateParam> page = new PageParam<>();
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@@ -65,94 +63,81 @@ public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certi
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdcardRespVO idcardOcr(String frontImageUrl, String backImageUrl) {
|
||||
String frontImg = ImageUtil.ImageBase64(frontImageUrl);
|
||||
String backImg = ImageUtil.ImageBase64(backImageUrl);
|
||||
if (frontImg == null || frontImg.isEmpty() || backImg == null || backImg.isEmpty()) {
|
||||
IdcardRespVO fail = new IdcardRespVO();
|
||||
fail.setCode("PARAM_ERROR");
|
||||
fail.setMessage("身份证图片转base64失败");
|
||||
return fail;
|
||||
}
|
||||
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "APPCODE " + APP_CODE);
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
headers.put("X-Ca-Nonce", UUID.randomUUID().toString());
|
||||
|
||||
Map<String, String> querys = new HashMap<>();
|
||||
Map<String, String> bodys = new HashMap<>();
|
||||
bodys.put("reqNo", UUID.randomUUID().toString().replace("-", ""));
|
||||
bodys.put("frontImg", frontImg);
|
||||
bodys.put("backImg", backImg);
|
||||
|
||||
try {
|
||||
HttpResponse response = HttpUtils.doPost(HOST, "/v1/tools/ocr/idCard", "POST", headers, querys, bodys);
|
||||
HttpEntity entity = response.getEntity();
|
||||
String string = EntityUtils.toString(entity);
|
||||
return JSONObject.parseObject(string, IdcardRespVO.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyIdcard(Certificate param, List<String> files) {
|
||||
// 验证正面
|
||||
Response<FrontRecognitionResult> front = idcardfrontrecongnition(files.get(0));
|
||||
if(front.getError_code() != 0){
|
||||
ExceptionUtil.wrapAndThrow(new Exception(front.getReason()));
|
||||
if (files == null || files.size() < 2) {
|
||||
ExceptionUtil.wrapAndThrow(new RuntimeException("缺少身份证正反面照片"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 验证反面
|
||||
Response<BackRecognitionResult> back = idcardbackrecongnition(files.get(1));
|
||||
if(back.getError_code() != 0){
|
||||
ExceptionUtil.wrapAndThrow(new Exception(back.getReason()));
|
||||
IdcardRespVO resp = idcardOcr(files.get(0), files.get(1));
|
||||
if (resp == null) {
|
||||
ExceptionUtil.wrapAndThrow(new RuntimeException("身份证识别调用失败"));
|
||||
return false;
|
||||
}
|
||||
if (!SUCCESS_CODE.equals(resp.getCode())) {
|
||||
ExceptionUtil.wrapAndThrow(new RuntimeException(resp.getMessage() == null ? "身份证识别失败" : resp.getMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 信息是否一致
|
||||
if(!param.getCertificateCode().equals(front.getResult().getIdcardno())){
|
||||
if (!param.getCertificateCode().equals(resp.getIdCardNo())) {
|
||||
return false;
|
||||
}
|
||||
if(!param.getRealName().equals(front.getResult().getName())){
|
||||
if (!param.getRealName().equals(resp.getName())) {
|
||||
return false;
|
||||
}
|
||||
boolean b = LocalDateTime.parse(back.getResult().getEndDate()).compareTo(LocalDateTime.now()) > 0;
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<FrontRecognitionResult> idcardfrontrecongnition(String imageUrl) {
|
||||
|
||||
String host = "https://zidv2.market.alicloudapi.com";
|
||||
String path = "/thirdnode/ImageAI/idcardfrontrecongnition";
|
||||
String method = "POST";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
//根据API的要求,定义相对应的Content-Type
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
bodys.put("base64Str", ImageUtil.ImageBase64(imageUrl));
|
||||
|
||||
|
||||
try {
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
HttpEntity entity = response.getEntity();
|
||||
String string = EntityUtils.toString(entity);
|
||||
Response<FrontRecognitionResult> o = JSONObject.parseObject(string, new TypeReference<Response<FrontRecognitionResult>>() {
|
||||
});
|
||||
|
||||
return o;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 有效期是否过期
|
||||
String expireDate = resp.getExpireDate();
|
||||
if (expireDate == null || expireDate.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<BackRecognitionResult> idcardbackrecongnition(String imageUrl) {
|
||||
|
||||
String host = "https://zidv2.market.alicloudapi.com";
|
||||
String path = "/thirdnode/ImageAI/idcardbackrecongnition";
|
||||
String method = "POST";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
//根据API的要求,定义相对应的Content-Type
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
bodys.put("base64Str", ImageUtil.ImageBase64(imageUrl));
|
||||
|
||||
|
||||
LocalDate expire;
|
||||
try {
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
HttpEntity entity = response.getEntity();
|
||||
String string = EntityUtils.toString(entity);
|
||||
Response<BackRecognitionResult> o = JSONObject.parseObject(string, new TypeReference<Response<BackRecognitionResult>>() {
|
||||
});
|
||||
|
||||
return o;
|
||||
expire = LocalDate.parse(expireDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 尝试按 yyyyMMdd 解析
|
||||
try {
|
||||
expire = LocalDate.parse(expireDate, DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return expire.isAfter(LocalDate.now());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.gxwebsoft.oa.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.gxwebsoft.common.core.utils.HttpUtils;
|
||||
import com.gxwebsoft.love.vo.idcheck.FrontRecognitionResult;
|
||||
import com.gxwebsoft.love.vo.idcheck.Response;
|
||||
import com.gxwebsoft.oa.service.IdcardService;
|
||||
import com.gxwebsoft.oa.vo.IdcardRespVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
@@ -16,42 +14,75 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class IdcardServiceImpl implements IdcardService {
|
||||
|
||||
/** 阿里云市场 - 身份证 OCR 供应商(蜜堂有信) */
|
||||
private static final String HOST = "https://miitangs14.market.alicloudapi.com";
|
||||
private static final String APP_CODE = "1390018309a443c695c98c8da2bed691";
|
||||
private static final String SUCCESS_CODE = "FP00000";
|
||||
|
||||
/**
|
||||
* @param frontImg 身份证正面图片的 base64 字符串(已带 ?x-oss-process 压缩,调用方负责生成)
|
||||
* @param backImg 身份证反面图片的 base64 字符串
|
||||
*/
|
||||
@Override
|
||||
public IdcardRespVO verify(String frontImg, String backImg) {
|
||||
// 1. 校验输入
|
||||
if (frontImg == null || frontImg.isEmpty() || backImg == null || backImg.isEmpty()) {
|
||||
log.warn("身份证 verify 调用缺少正/反面图片, frontIsBlank={}, backIsBlank={}",
|
||||
frontImg == null || frontImg.isEmpty(),
|
||||
backImg == null || backImg.isEmpty());
|
||||
return null;
|
||||
}
|
||||
|
||||
String host = "https://miitangs14.market.alicloudapi.com";
|
||||
String path = "/v1/tools/ocr/idCard";
|
||||
String method = "POST";
|
||||
String appcode = "1390018309a443c695c98c8da2bed691";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
//根据API的要求,定义相对应的Content-Type
|
||||
// 2. 调用新接口(正反面合并为一次请求)
|
||||
IdcardRespVO resp;
|
||||
try {
|
||||
resp = callOcr(frontImg, backImg);
|
||||
} catch (Exception e) {
|
||||
log.error("身份证OCR识别调用异常", e);
|
||||
return null;
|
||||
}
|
||||
if (resp == null) {
|
||||
log.warn("身份证OCR识别返回为空(接口无响应或解析失败)");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. 失败返回具体原因
|
||||
if (!SUCCESS_CODE.equals(resp.getCode())) {
|
||||
log.warn("身份证OCR识别失败 code={}, message={}", resp.getCode(), resp.getMessage());
|
||||
IdcardRespVO fail = new IdcardRespVO();
|
||||
fail.setCode(resp.getCode());
|
||||
fail.setMessage(resp.getMessage());
|
||||
return fail;
|
||||
}
|
||||
|
||||
// 4. 成功
|
||||
log.info("身份证识别成功 name={}, idCardNo={}", resp.getName(), resp.getIdCardNo());
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用蜜堂有信身份证 OCR 接口:POST /v1/tools/ocr/idCard
|
||||
*/
|
||||
private IdcardRespVO callOcr(String frontImg, String backImg) throws Exception {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "APPCODE " + APP_CODE);
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
//需要给X-Ca-Nonce的值生成随机字符串,每次请求不能相同
|
||||
headers.put("X-Ca-Nonce", UUID.randomUUID().toString());
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
|
||||
Map<String, String> querys = new HashMap<>();
|
||||
Map<String, String> bodys = new HashMap<>();
|
||||
bodys.put("reqNo", UUID.randomUUID().toString().replace("-", ""));
|
||||
bodys.put("frontImg", frontImg);
|
||||
bodys.put("backImg", backImg);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
HttpEntity entity = response.getEntity();
|
||||
String string = EntityUtils.toString(entity);
|
||||
IdcardRespVO respVO = JSONObject.parseObject(string, new TypeReference<IdcardRespVO>() {
|
||||
});
|
||||
return respVO;
|
||||
//获取response的body
|
||||
//System.out.println(EntityUtils.toString(response.getEntity()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
HttpResponse response = HttpUtils.doPost(HOST, "/v1/tools/ocr/idCard", "POST", headers, querys, bodys);
|
||||
HttpEntity entity = response.getEntity();
|
||||
String body = EntityUtils.toString(entity);
|
||||
log.debug("OCR 调用 frontImgLen={}, backImgLen={}, respLen={}", frontImg.length(), backImg.length(), body.length());
|
||||
return JSONObject.parseObject(body, IdcardRespVO.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,32 +411,10 @@ public class OpenEquipmentController extends BaseController {
|
||||
// if(receiptStatus == 20){
|
||||
// return fail("订单已确认收货,不能重复确认!");
|
||||
// }
|
||||
// 验证身份证真实性
|
||||
if(StringUtils.hasText(receiptParam.getOrderSourceData())) {
|
||||
String orderSourceDataString = receiptParam.getOrderSourceData();
|
||||
List<String> images = JSONObject.parseArray(orderSourceDataString, String.class);
|
||||
String front = ImageUtil.ImageBase64(images.get(0) + "?x-oss-process=image/resize,w_750/quality,Q_80");
|
||||
|
||||
String back = ImageUtil.ImageBase64(images.get(1) + "?x-oss-process=image/resize,w_750/quality,Q_80");
|
||||
|
||||
IdcardRespVO verify = idcardService.verify(front, back);
|
||||
System.out.println("verify res : " + verify);
|
||||
if(!"FP00000".equals(verify.getCode())) {
|
||||
return fail("请上传身份证正面照片." + verify.getMessage() + verify.getCode());
|
||||
}
|
||||
if(verify.getIssueDate() == null || verify.getIssueOrg() == null || verify.getExpireDate() == null) {
|
||||
return fail("请上传身份证反面照片");
|
||||
}
|
||||
order.setRealName(verify.getName());
|
||||
order.setIdCode(verify.getIdCardNo());
|
||||
order.setAddress(verify.getAddress());
|
||||
|
||||
//更新用户信息
|
||||
User user = userService.getById(order.getUserId());
|
||||
user.setRealName(verify.getName());
|
||||
user.setIdCard(verify.getIdCardNo());
|
||||
user.setAddress(verify.getAddress());
|
||||
userService.updateUser(user);
|
||||
// 验证身份证真实性(校验不通过时返回 fail 结果,通过则返回 null)
|
||||
ApiResult<?> idcardResult = verifyIdCard(receiptParam.getOrderSourceData(), order);
|
||||
if (idcardResult != null) {
|
||||
return idcardResult;
|
||||
}
|
||||
|
||||
// 短信验证码校验
|
||||
@@ -460,6 +438,78 @@ public class OpenEquipmentController extends BaseController {
|
||||
return success("确认收货成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份证 OCR 真实性校验,并把识别到的实名信息回填到 order / user。
|
||||
* orderSourceData 约定顺序:[0]=身份证正面、[1]=身份证反面、[2]=人车合照、[3]=车子照片、[4]=安装照片
|
||||
*
|
||||
* @param orderSourceData 前端传入的图片地址 JSON 数组字符串
|
||||
* @param order 当前订单(校验通过时回填实名信息)
|
||||
* @return 校验失败返回 ApiResult(fail),校验通过返回 null
|
||||
*/
|
||||
/**
|
||||
* 身份证 OCR 真实性校验(当前为「尽力而为」模式:OCR 调不通/未通过时仅记录日志,不阻断业务)。
|
||||
* 等阿里云市场接口/AppCode 恢复正常后,本方法会在识别成功时自动回填实名信息,无需额外改动。
|
||||
* orderSourceData 约定顺序:[0]=身份证正面、[1]=身份证反面、[2]=人车合照、[3]=车子照片、[4]=安装照片
|
||||
*
|
||||
* @param orderSourceData 前端传入的图片地址 JSON 数组字符串
|
||||
* @param order 当前订单(校验通过时回填实名信息)
|
||||
* @return 始终返回 null(放行业务);OCR 结果仅用于尽力回填
|
||||
*/
|
||||
private ApiResult<?> verifyIdCard(String orderSourceData, Order order) {
|
||||
// 1. 解析图片数组(解析失败仅记录,不阻断业务)
|
||||
List<String> images;
|
||||
try {
|
||||
images = JSONObject.parseArray(orderSourceData, String.class);
|
||||
} catch (Exception e) {
|
||||
log.warn("身份证图片数据解析失败,跳过OCR校验, orderSourceData={}", orderSourceData);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 必须包含身份证正反面(约定下标 0=正面、1=反面);缺失则跳过 OCR,不阻断
|
||||
if (images == null || images.size() < 2
|
||||
|| !StringUtils.hasText(images.get(0)) || !StringUtils.hasText(images.get(1))) {
|
||||
log.warn("身份证正反面照片缺失,跳过OCR校验,业务继续");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. 调第三方 OCR 识别(best-effort:异常/失败均仅记录日志,放行业务)
|
||||
try {
|
||||
String front = ImageUtil.ImageBase64(images.get(0) + "?x-oss-process=image/resize,w_750/quality,Q_80");
|
||||
String back = ImageUtil.ImageBase64(images.get(1) + "?x-oss-process=image/resize,w_750/quality,Q_80");
|
||||
|
||||
IdcardRespVO verify = idcardService.verify(front, back);
|
||||
if (verify == null) {
|
||||
log.warn("身份证OCR识别返回为空,跳过校验,业务继续");
|
||||
return null;
|
||||
}
|
||||
if (!"FP00000".equals(verify.getCode())) {
|
||||
log.warn("身份证OCR识别未通过 code={}, message={},跳过校验,业务继续", verify.getCode(), verify.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
// 成功:回填实名信息
|
||||
if (StringUtils.hasText(verify.getName()) && StringUtils.hasText(verify.getIdCardNo())) {
|
||||
order.setRealName(verify.getName());
|
||||
order.setIdCode(verify.getIdCardNo());
|
||||
order.setAddress(verify.getAddress());
|
||||
|
||||
User user = userService.getById(order.getUserId());
|
||||
if (user != null) {
|
||||
user.setRealName(verify.getName());
|
||||
user.setIdCard(verify.getIdCardNo());
|
||||
user.setAddress(verify.getAddress());
|
||||
userService.updateUser(user);
|
||||
}
|
||||
log.info("身份证OCR识别成功并回填实名 name={}, idCardNo={}", verify.getName(), verify.getIdCardNo());
|
||||
} else {
|
||||
log.warn("身份证OCR识别成功但字段缺失,跳过回填,业务继续");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("身份证OCR识别调用异常,跳过校验,业务继续", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*@ApiOperation("确认收货")
|
||||
@PostMapping("/receipt")
|
||||
public ApiResult<?> receipt(@RequestBody Order order) {
|
||||
|
||||
@@ -162,8 +162,12 @@ public class OrderPayController extends BaseController {
|
||||
one.setCurrPeriods(order.getCurrPeriods() + 1);
|
||||
one.setPeriods(order.getPeriods());
|
||||
one.setRentOrderId(order.getOrderId());
|
||||
one.setStartTime(order.getExpirationTime());
|
||||
one.setExpirationTime(DateUtil.offset(order.getExpirationTime(), DateField.MONTH, 1));
|
||||
// 续费无缝衔接:未逾期时从上一个到期日顺延一个月;已逾期时从今天顺延,
|
||||
// 避免“旧到期日~续费当天”这段空窗期被白送(表现为下半月续费有效期多给一个月)
|
||||
Date baseExpire = order.getExpirationTime();
|
||||
Date renewStart = (baseExpire != null && baseExpire.after(new Date())) ? baseExpire : new Date();
|
||||
one.setStartTime(renewStart);
|
||||
one.setExpirationTime(DateUtil.offset(renewStart, DateField.MONTH, 1));
|
||||
one.setPayStatus(PAY_STATUS_NO_PAY);
|
||||
one.setBatteryDeposit(order.getBatteryDeposit());
|
||||
one.setBatteryInsurance(order.getBatteryInsurance());
|
||||
@@ -262,11 +266,19 @@ public class OrderPayController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
Order order = new Order();
|
||||
order.setOrderId(orderPay.getRentOrderId());
|
||||
order.setStartTime(orderPay.getStartTime());
|
||||
order.setExpirationTime(orderPay.getExpirationTime());
|
||||
orderService.updateById(order);
|
||||
// 续费时间以父订单当前到期日为准无缝衔接,不信任前端传入的 startTime/expirationTime,
|
||||
// 避免后台操作时把有效期算多一个月
|
||||
Order parentOrder = orderService.getById(orderPay.getRentOrderId());
|
||||
if (parentOrder == null) {
|
||||
return fail("关联订单不存在");
|
||||
}
|
||||
Date parentExpire = parentOrder.getExpirationTime();
|
||||
Date renewStart = (parentExpire != null && parentExpire.after(new Date())) ? parentExpire : new Date();
|
||||
Date renewExpire = DateUtil.offset(renewStart, DateField.MONTH, 1);
|
||||
|
||||
parentOrder.setStartTime(renewStart);
|
||||
parentOrder.setExpirationTime(renewExpire);
|
||||
orderService.updateById(parentOrder);
|
||||
|
||||
OrderPay olderPay = orderPayService.getOne(Wrappers.lambdaQuery(OrderPay.class).eq(OrderPay::getOrderNo, orderPay.getOrderNo()));
|
||||
OrderPay newOrderPay = new OrderPay();
|
||||
@@ -274,10 +286,10 @@ public class OrderPayController extends BaseController {
|
||||
|
||||
|
||||
newOrderPay.setOrderPrice(BigDecimal.valueOf(orderPay.getOrderPriceInt()));
|
||||
newOrderPay.setStartTime(orderPay.getStartTime());
|
||||
newOrderPay.setStartTime(renewStart);
|
||||
newOrderPay.setPayTime(new Date());
|
||||
newOrderPay.setCreateTime(new Date());
|
||||
newOrderPay.setExpirationTime(orderPay.getExpirationTime());
|
||||
newOrderPay.setExpirationTime(renewExpire);
|
||||
newOrderPay.setOrderNo(IdUtil.getSnowflakeNextIdStr());
|
||||
newOrderPay.setIsAdminRenew(1);//是否管理员续费订单
|
||||
|
||||
|
||||
@@ -575,7 +575,9 @@ public class PaymentController extends BaseController {
|
||||
}
|
||||
|
||||
Date expirationTime = parentOrder.getExpirationTime();
|
||||
DateTime nextMonthTime = DateUtil.offsetMonth(expirationTime, 1);
|
||||
// 逾期续费从今天衔接,避免“旧到期日~续费当天”空窗期白送一个月
|
||||
Date renewBase = (expirationTime != null && expirationTime.after(new Date())) ? expirationTime : new Date();
|
||||
DateTime nextMonthTime = DateUtil.offsetMonth(renewBase, 1);
|
||||
parentOrder.setExpirationTime(nextMonthTime);
|
||||
orderService.updateById(parentOrder);
|
||||
// 保存续费订单状态
|
||||
@@ -583,7 +585,7 @@ public class PaymentController extends BaseController {
|
||||
d.setDeliveryStatus(DELIVERY_STATUS_ACCEPT);
|
||||
d.setReceiptStatus(RECEIPT_STATUS_YES);
|
||||
d.setOrderStatus(ORDER_STATUS_COMPLETED);
|
||||
d.setStartTime(expirationTime);
|
||||
d.setStartTime(renewBase);
|
||||
d.setExpirationTime(nextMonthTime);
|
||||
orderService.updateById(d);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
<if test="param.rentOrderId != null">
|
||||
AND a.rent_order_id = #{param.rentOrderId}
|
||||
</if>
|
||||
<if test="param.rentOrderIdNotNull != null and param.rentOrderIdNotNull">
|
||||
AND a.rent_order_id IS NOT NULL
|
||||
</if>
|
||||
<if test="param.payStatus != null">
|
||||
AND a.pay_status = #{param.payStatus}
|
||||
</if>
|
||||
|
||||
@@ -116,6 +116,9 @@ public class OrderPayParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer rentOrderId;
|
||||
|
||||
@ApiModelProperty(value = "仅查询续费单(rentOrderId 不为空)")
|
||||
private Boolean rentOrderIdNotNull;
|
||||
|
||||
@ApiModelProperty(value = "电池租金")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal batteryRent;
|
||||
|
||||
@@ -260,16 +260,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
// 主订单
|
||||
Order parentOrder = orderService.getById(order.getRentOrderId());
|
||||
parentOrder.setCurrPeriods(count + 1);
|
||||
// 更新过期时间延长一个月
|
||||
// 更新过期时间延长一个月(逾期时从今天衔接,避免空窗期白送)
|
||||
Date expirationTime = parentOrder.getExpirationTime();
|
||||
DateTime nextMonthTime = DateUtil.offsetMonth(expirationTime, 1);
|
||||
Date renewBase = (expirationTime != null && expirationTime.after(new Date())) ? expirationTime : new Date();
|
||||
DateTime nextMonthTime = DateUtil.offsetMonth(renewBase, 1);
|
||||
parentOrder.setExpirationTime(nextMonthTime);
|
||||
// 保存续费订单状态
|
||||
// order.setDeliveryStatus(DELIVERY_STATUS_YES);
|
||||
order.setDeliveryStatus(DELIVERY_STATUS_ACCEPT);
|
||||
order.setReceiptStatus(RECEIPT_STATUS_YES);
|
||||
order.setOrderStatus(ORDER_STATUS_COMPLETED);
|
||||
order.setStartTime(expirationTime);
|
||||
order.setStartTime(renewBase);
|
||||
order.setExpirationTime(nextMonthTime);
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user