提交 bfe05eb3 作者: zhenjie

实名认证

上级 1404d83a
package com.mmc.iuav.user.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author: zj
* @Date: 2023/7/27 14:49
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "实名认证DTO")
public class RealNameAuthDTO implements Serializable {
private static final long serialVersionUID = -1449716605649423527L;
@ApiModelProperty(value = "实名认证id")
private Integer id;
@ApiModelProperty(value = "用户userAccountId")
private Integer userAccountId;
@ApiModelProperty(value = "实名认证状态")
private Integer checkStatus;
@ApiModelProperty(value = "真实姓名")
private String userName;
@ApiModelProperty(value = "身份证号码")
private String idNumber;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "用户uid")
private String uid;
@ApiModelProperty(value = "用户昵称")
private String nickName;
@ApiModelProperty(value = "用户常驻地址")
private String resAddress;
@ApiModelProperty(value = "手机号")
private String phoneNum;
@ApiModelProperty(value = "实名认证时间")
private String createTime;
}
package com.mmc.iuav.user.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author: zj
* @Date: 2023/7/27 14:49
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "实名认证详情DTO")
public class RealNameAuthDetailDTO implements Serializable {
private static final long serialVersionUID = 3101785098483923008L;
@ApiModelProperty(value = "实名认证id")
private Integer id;
@ApiModelProperty(value = "用户userAccountId")
private Integer userAccountId;
@ApiModelProperty(value = "身份证正面")
private String frontIdImg;
@ApiModelProperty(value = "身份证背面")
private String backIdImg;
@ApiModelProperty(value = "身份证好")
private String idNumber;
@ApiModelProperty(value = "姓名")
private String userName;
@ApiModelProperty(value = "状态")
private Integer checkStatus;
}
package com.mmc.iuav.user.model.qo;
import com.mmc.iuav.group.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* author:zhenjie
* Date:2021/10/27
* time:20:08
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "实名认证查询QO")
public class RealNameAuthQO implements Serializable {
private static final long serialVersionUID = 3767938308251944541L;
@ApiModelProperty(value = "关键字")
private String keyword;
@ApiModelProperty(value = "地区", hidden = true)
private String area;
@ApiModelProperty(value = "实名认证状态", hidden = true)
private Integer checkStatus;
@ApiModelProperty(value = "单位id集合", hidden = true)
private List<Integer> companyIds;
@ApiModelProperty(value = "页码", required = true)
@NotNull(message = "页码不能为空", groups = Page.class)
@Min(value = 1, groups = Page.class)
private Integer pageNo;
@ApiModelProperty(value = "每页显示数", required = true)
@NotNull(message = "每页显示数不能为空", groups = Page.class)
@Min(value = 1, groups = Page.class)
private Integer pageSize;
public void buildCurrentPage() {
this.pageNo = (pageNo - 1) * pageSize;
}
}
package com.mmc.iuav.user.model.vo;
import com.mmc.iuav.group.Create;
import com.mmc.iuav.group.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author: zj
* @Date: 2023/7/27 14:49
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "新增/修改参数类")
public class RealNameAuthVO implements Serializable {
private static final long serialVersionUID = -8096210744248682679L;
@ApiModelProperty(value = "用户ID")
@NotNull(message = "用户ID不能为空", groups = {Update.class, Create.class})
private Integer userAccountId;
@ApiModelProperty(value = "名字")
@NotBlank(message = "名字不能为空", groups = {Create.class})
private String userName;
@ApiModelProperty(value = "身份证号码")
@NotBlank(message = "身份证号码不能为空", groups = {Create.class})
private String idNumber;
@ApiModelProperty(value = "身份证正面照片地址")
@NotBlank(message = "身份证正面照片不能为空", groups = {Create.class})
private String frontIdImg;
@ApiModelProperty(value = "身份证反面照片地址")
@NotBlank(message = "身份证反面照片不能为空", groups = {Create.class})
private String backIdImg;
@ApiModelProperty(value = "unionId")
private String unionId;
}
...@@ -43,7 +43,6 @@ public enum ResultEnum implements BaseErrorInfoInterface { ...@@ -43,7 +43,6 @@ public enum ResultEnum implements BaseErrorInfoInterface {
PWD_CONPARED_ERROR("6002", "密码错误"), PWD_ALERT_ERROR("6003", "密码不一致"), PWD_CONPARED_ERROR("6002", "密码错误"), PWD_ALERT_ERROR("6003", "密码不一致"),
PWD_REQUEST_AUTH_ERROR("6003", "密码请求验证"), PWD_REQUEST_AUTH_ERROR("6003", "密码请求验证"),
APPLET_PORT_TYPE_ERROR("7001", "小程序端口类型错误"), APPLET_PORT_TYPE_ERROR("7001", "小程序端口类型错误"),
APPLET_LOGIN_ERROR("7002", "获取小程序登录信息失败"), APPLET_LOGIN_ERROR("7002", "获取小程序登录信息失败"),
UPDATE_USER_ACCOUNT_REPEAT("7003", "修改后的账户名已存在"), UPDATE_USER_ACCOUNT_REPEAT("7003", "修改后的账户名已存在"),
...@@ -56,7 +55,21 @@ public enum ResultEnum implements BaseErrorInfoInterface { ...@@ -56,7 +55,21 @@ public enum ResultEnum implements BaseErrorInfoInterface {
UPDATE_ADMIN_ROLE_ERROR("8009", "禁止修改admin账号的角色"), UPDATE_ADMIN_ROLE_ERROR("8009", "禁止修改admin账号的角色"),
ONLY_ONE_ADMIN_ERROR("8010", "禁止该账号获取超级管理员角色"), ONLY_ONE_ADMIN_ERROR("8010", "禁止该账号获取超级管理员角色"),
DELETE_ADMIN_ERROR("8011", "禁止删除超级管理员角色账号"), DELETE_ADMIN_ERROR("8011", "禁止删除超级管理员角色账号"),
DELETE_YOURSELF_ERROR("8011", "禁止删除自己的账号"); DELETE_YOURSELF_ERROR("8011", "禁止删除自己的账号"),
ID_INFO_AND_ID_card_MISMATCH("3904", "身份信息与身份证不匹配"),
INTERFACE_ACCESS_EXCEPTION("36894", "接口访问异常/次数用尽"),
FRONT_BACK_VAGUE("35556", "身份证正反面不明确"),
ID_CARD_THOTO_MESSAGE_ERROR("36651", "身份照信息错误"),
EXPTION_ID_CARD_THOTO_MESSAGE_ERROR("36651", "信息异常"),
PHOTO_FORMAT_ERROR("12138", "身份证图片格式错误"),
VALIDATION_INFO_EXPIRED("32815", "认证时间过长信息过期或认证信息不完整,请重新开始认证"),
REAL_IMAGE_AUTHENTICATION_SUCESS("38844", "验证成功"),
REAL_IMAGE_AUTHENTICATION_FAILED("38855", "验证失败,请再次进行人脸识别"),
IDENTITY_HAS_BEEN_AUTHENTICATED("34444", "此身份证信息已经被认证,请重试"),
REAL_NAME_ACCOUNT_ID_ERROR("36771", "账户id错误"),
REAL_NAME_FUSING_ERROR("36772", "认证失败,请重新认证"),
REAL_NAME_PASS_ERROR("36773", "已成功认证");
/** /**
* 错误码 * 错误码
......
package com.mmc.iuav.user.controller;
import com.mmc.iuav.group.Create;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.dto.RealNameAuthDTO;
import com.mmc.iuav.user.model.qo.RealNameAuthQO;
import com.mmc.iuav.user.model.vo.RealNameAuthVO;
import com.mmc.iuav.user.service.RealNameAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
/**
* @author: zj
* @Date: 2023/7/27 10:04
*/
@Api(tags = "实名认证")
@RequestMapping("/real-name-auth/")
@RestController
public class RealNameAuthController extends BaseController {
@Autowired
private RealNameAuthService realNameAuthService;
@ApiOperation(value = "提交实名认证")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("add")
public ResultBody add(@Validated(value = {Create.class}) @RequestBody RealNameAuthVO realNameAuthVO) {
return realNameAuthService.add(realNameAuthVO);
}
@ApiOperation(value = "实名认证详情")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = RealNameAuthDTO.class)})
@GetMapping("detail")
public ResultBody<RealNameAuthDTO> detail(@RequestParam Integer id) {
return realNameAuthService.detail(id);
}
@ApiOperation(value = "用户实名认证详情")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = RealNameAuthDTO.class)})
@GetMapping("userDetail")
public ResultBody<RealNameAuthDTO> userDetail(HttpServletRequest request) {
return realNameAuthService.userDetail(this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
@ApiOperation(value = "实名认证列表")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("listPage")
public ResultBody listPage(@RequestBody RealNameAuthQO realNameAuthQO) {
return realNameAuthService.listPage(realNameAuthQO);
}
}
package com.mmc.iuav.user.dao;
import com.mmc.iuav.user.entity.RealNameAuthDO;
import com.mmc.iuav.user.model.qo.RealNameAuthQO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @author: zj
* @Date: 2023/7/27 10:05
*/
@Mapper
public interface RealNameAuthDao {
int existHasBeenAuth(String unionId, String idNumber);
RealNameAuthDO getRealNameAuthByUnionId(String unionId);
RealNameAuthDO getRealNameAuthBakByUnionId(String unionId);
void addRealNameAuth(RealNameAuthDO realNameAuthDO);
void updateRealNameAuth(RealNameAuthDO realNameAuthDO);
RealNameAuthDO getRealNameAuthByUId(Integer userAccountId);
RealNameAuthDO getRealNameAuthById(Integer id);
int countListRealNameAuth(RealNameAuthQO realNameAuthQO);
List<RealNameAuthDO> listRealNameAuth(RealNameAuthQO realNameAuthQO);
RealNameAuthDO userDetail(Integer userAccountId);
}
package com.mmc.iuav.user.entity;
import com.mmc.iuav.user.model.dto.RealNameAuthDTO;
import com.mmc.iuav.user.model.dto.RealNameAuthDetailDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author: zj
* @Date: 2023/7/27 14:49
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RealNameAuthDO implements Serializable {
private static final long serialVersionUID = -1752966940978678911L;
private Integer id;
private Integer cuId;
private Integer userAccountId;
private String frontIdImg;
private String backIdImg;
private String idNumber;
private String userName;
private Integer sex;
private String nationality;
private Date birthday;
private String address;
private String issue;
private Date startDate;
private Date endDate;
private Integer fakeFront;
private Integer fakeBack;
private Integer checkStatus;
private String remark;
private Date createTime;
private Date updateTime;
private String uid;
private String nickName;
private String resAddress;
private String phoneNum;
private String unionId;
public RealNameAuthDetailDTO buildRealNameAuthDetailDTO() {
return RealNameAuthDetailDTO.builder().id(this.id).userAccountId(this.userAccountId).frontIdImg(this.frontIdImg)
.backIdImg(this.backIdImg).idNumber(this.idNumber).userName(this.userName).checkStatus(this.checkStatus)
.build();
}
public RealNameAuthDTO buildRealNameAuthDTO() {
SimpleDateFormat cur = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return RealNameAuthDTO.builder().id(this.id).userAccountId(this.userAccountId).uid(this.id + "")
.nickName(this.nickName).userName(this.userName).phoneNum(this.phoneNum).idNumber(this.idNumber)
.resAddress(this.resAddress).checkStatus(this.checkStatus)
.createTime((this.createTime == null) ? null : cur.format(this.createTime)).remark(this.remark).build();
}
}
package com.mmc.iuav.user.service;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.dto.RealNameAuthDTO;
import com.mmc.iuav.user.model.qo.RealNameAuthQO;
import com.mmc.iuav.user.model.vo.RealNameAuthVO;
/**
* @author: zj
* @Date: 2023/7/27 10:07
*/
public interface RealNameAuthService {
ResultBody add(RealNameAuthVO realNameAuthVO);
ResultBody<RealNameAuthDTO> detail(Integer id);
ResultBody listPage(RealNameAuthQO realNameAuthQO);
ResultBody<RealNameAuthDTO> userDetail(Integer userAccountId);
}
...@@ -10,6 +10,7 @@ import com.mmc.iuav.user.auth.PwdUtil; ...@@ -10,6 +10,7 @@ import com.mmc.iuav.user.auth.PwdUtil;
import com.mmc.iuav.user.client.PayClient; import com.mmc.iuav.user.client.PayClient;
import com.mmc.iuav.user.constant.WxConstant; import com.mmc.iuav.user.constant.WxConstant;
import com.mmc.iuav.user.dao.CompanyAuthDao; import com.mmc.iuav.user.dao.CompanyAuthDao;
import com.mmc.iuav.user.dao.RealNameAuthDao;
import com.mmc.iuav.user.dao.RoleDao; import com.mmc.iuav.user.dao.RoleDao;
import com.mmc.iuav.user.entity.*; import com.mmc.iuav.user.entity.*;
import com.mmc.iuav.user.enums.UserAccountStatus; import com.mmc.iuav.user.enums.UserAccountStatus;
...@@ -56,6 +57,9 @@ public class AuthServiceImpl implements AuthService { ...@@ -56,6 +57,9 @@ public class AuthServiceImpl implements AuthService {
private RoleDao roleDao; private RoleDao roleDao;
@Autowired @Autowired
private RealNameAuthDao realNameAuthDao;
@Autowired
private CompanyService companyService; private CompanyService companyService;
@Autowired @Autowired
...@@ -97,6 +101,13 @@ public class AuthServiceImpl implements AuthService { ...@@ -97,6 +101,13 @@ public class AuthServiceImpl implements AuthService {
userAccountService.insertUserAccount(userAccountDO); userAccountService.insertUserAccount(userAccountDO);
userAccountVO = userAccountDO.buildUserAccountVO(); userAccountVO = userAccountDO.buildUserAccountVO();
payClient.createWallet(userAccountDO.getId()); payClient.createWallet(userAccountDO.getId());
// 查询之前有没有实名过
RealNameAuthDO nameAuthByUnionId = realNameAuthDao.getRealNameAuthBakByUnionId(unionId);
if (nameAuthByUnionId != null) {
nameAuthByUnionId.setUserAccountId(userAccountDO.getId());
nameAuthByUnionId.setId(null);
realNameAuthDao.addRealNameAuth(nameAuthByUnionId);
}
} else { } else {
CompanyAuthDO companyAuthDO = companyAuthDao.getCompanyAuth(userAccountVO.getId()); CompanyAuthDO companyAuthDO = companyAuthDao.getCompanyAuth(userAccountVO.getId());
companyAuthStatus = companyAuthDO == null ? 0 : 1; companyAuthStatus = companyAuthDO == null ? 0 : 1;
......
...@@ -44,7 +44,7 @@ public class CompanyAuthServiceImpl implements CompanyAuthService { ...@@ -44,7 +44,7 @@ public class CompanyAuthServiceImpl implements CompanyAuthService {
if (companyInfoDO != null) { if (companyInfoDO != null) {
List<CompanyMemberDO> companyMemberDOS = companyDao.listCompanyMembers(companyInfoDO.getId()); List<CompanyMemberDO> companyMemberDOS = companyDao.listCompanyMembers(companyInfoDO.getId());
if (!CollectionUtils.isEmpty(companyMemberDOS)) { if (!CollectionUtils.isEmpty(companyMemberDOS)) {
return ResultBody.error(ResultEnum.APPLET_LOGIN_ERROR); return ResultBody.error(ResultEnum.COMPANY_EXIST_ERROR);
} }
} else { } else {
companyInfoDO = new CompanyInfoDO(); companyInfoDO = new CompanyInfoDO();
......
...@@ -183,6 +183,7 @@ public class CooperationServiceImpl implements CooperationService { ...@@ -183,6 +183,7 @@ public class CooperationServiceImpl implements CooperationService {
} }
// 审批通过生成后台对应的账号 // 审批通过生成后台对应的账号
BUserAccountVO bUserAccountVO = this.generateBackUserAccountVO(userApplyTag); BUserAccountVO bUserAccountVO = this.generateBackUserAccountVO(userApplyTag);
log.info("check apply cooperation tag, bUserAccountVO:{}", JSONObject.toJSONString(bUserAccountVO));
ResultBody resultBody = backUserAccountService.insertBAccount(bUserAccountVO); ResultBody resultBody = backUserAccountService.insertBAccount(bUserAccountVO);
if (!resultBody.getCode().equals(ResultEnum.SUCCESS.getResultCode())) { if (!resultBody.getCode().equals(ResultEnum.SUCCESS.getResultCode())) {
// 生成账号失败处理 // 生成账号失败处理
...@@ -195,7 +196,6 @@ public class CooperationServiceImpl implements CooperationService { ...@@ -195,7 +196,6 @@ public class CooperationServiceImpl implements CooperationService {
} }
throw new BizException(ResultEnum.COOPERATION_CHECK_NOT_PASS_ERROR); throw new BizException(ResultEnum.COOPERATION_CHECK_NOT_PASS_ERROR);
} }
log.info("check apply cooperation tag, bUserAccountVO:{}", JSONObject.toJSONString(bUserAccountVO));
Map<String, String> param = new HashMap<String, String>(); Map<String, String> param = new HashMap<String, String>();
param.put("accountNo", bUserAccountVO.getAccountNo()); param.put("accountNo", bUserAccountVO.getAccountNo());
param.put("password", bUserAccountVO.getPassWord()); param.put("password", bUserAccountVO.getPassWord());
......
package com.mmc.iuav.user.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.mmc.iuav.page.PageResult;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.response.ResultEnum;
import com.mmc.iuav.user.dao.RealNameAuthDao;
import com.mmc.iuav.user.entity.RealNameAuthDO;
import com.mmc.iuav.user.model.dto.RealNameAuthDTO;
import com.mmc.iuav.user.model.qo.RealNameAuthQO;
import com.mmc.iuav.user.model.vo.RealNameAuthVO;
import com.mmc.iuav.user.service.RealNameAuthService;
import com.mmc.iuav.user.util.RealNameAuthUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author: zj
* @Date: 2023/7/27 10:07
*/
@Service
@Slf4j
public class RealNameAuthServiceImpl implements RealNameAuthService {
@Autowired
private RealNameAuthDao realNameAuthDao;
@Override
public ResultBody add(RealNameAuthVO realNameAuthVO) {
RealNameAuthDO realNameAuthDO0 = realNameAuthDao.getRealNameAuthByUId(realNameAuthVO.getUserAccountId());
if (realNameAuthDO0 != null && realNameAuthDO0.getCheckStatus().equals(1)) {
return ResultBody.error(ResultEnum.REAL_NAME_PASS_ERROR);
}
// 查询是否已认证
int count = realNameAuthDao.existHasBeenAuth(realNameAuthVO.getUnionId(), realNameAuthVO.getIdNumber());
if (count > 0) {
return ResultBody.error(ResultEnum.IDENTITY_HAS_BEEN_AUTHENTICATED);
}
// 校验正面
ResultBody faceResult = RealNameAuthUtil.deal(realNameAuthVO.getFrontIdImg(), "face");
// 校验反面
ResultBody backResult = RealNameAuthUtil.deal(realNameAuthVO.getBackIdImg(), "back");
String faceMsg = JSONObject.parseObject(faceResult.toString()).getString("code");
String backMsg = JSONObject.parseObject(backResult.toString()).getString("code");
// 都解析通过
if (faceMsg.equals("200") && backMsg.equals("200")) {
// 处理正面
JSONObject faceResultJson = JSONObject.parseObject(
JSONObject.parseObject(faceResult.toString()).getString("result"));
JSONObject backResultJson = JSONObject.parseObject(
JSONObject.parseObject(backResult.toString()).getString("result"));
// 正面解析成功的时候,拿用户输入的信息与解析的数据作对比,一致再进行下一步,不一致提醒"用户输入的信息与身份证的不一致,请重新上传"
if (!faceResultJson.getString("name").equals(realNameAuthVO.getUserName())
|| !realNameAuthVO.getIdNumber().equals(faceResultJson.getString("num"))) {
return ResultBody.error(ResultEnum.ID_INFO_AND_ID_card_MISMATCH);
}
RealNameAuthDO realNameAuthDO = new RealNameAuthDO();
realNameAuthDO.setCheckStatus(1);
realNameAuthDO.setUserAccountId(realNameAuthVO.getUserAccountId());
realNameAuthDO.setFrontIdImg(realNameAuthVO.getFrontIdImg());
realNameAuthDO.setBackIdImg(realNameAuthVO.getBackIdImg());
realNameAuthDO.setUserName(faceResultJson.getString("name"));
realNameAuthDO.setIdNumber(faceResultJson.getString("num"));
realNameAuthDO.setAddress(faceResultJson.getString("address"));
realNameAuthDO.setNationality(faceResultJson.getString("nationality"));
realNameAuthDO.setIssue(backResultJson.getString("issue"));
if (faceResultJson.getString("sex").equals("男")) {
realNameAuthDO.setSex(1);
} else if (faceResultJson.getString("sex").equals("女")) {
realNameAuthDO.setSex(2);
} else {
realNameAuthDO.setSex(0);
}
if (faceResultJson.getString("is_fake").equals(false)) {
realNameAuthDO.setFakeFront(1);
} else {
realNameAuthDO.setFakeFront(0);
}
if (backResultJson.getString("is_fake").equals(false)) {
realNameAuthDO.setFakeBack(1);
} else {
realNameAuthDO.setFakeBack(0);
}
realNameAuthDO.setBirthday(this.getDate(faceResultJson.getString("birth"), "yyyyMMdd"));
realNameAuthDO.setStartDate(this.getDate(backResultJson.getString("start_date"), "yyyyMMdd"));
if (backResultJson.getString("end_date").equals("长期")) {
realNameAuthDO.setEndDate(null);
} else {
realNameAuthDO.setEndDate(this.getDate(backResultJson.getString("end_date"), "yyyyMMdd"));
}
// 记录到数据库
// 判断之前有没有认证成功
RealNameAuthDO beforeRealNameAuthDO = realNameAuthDao
.getRealNameAuthByUnionId(realNameAuthVO.getUnionId());
if (beforeRealNameAuthDO == null) {
realNameAuthDao.addRealNameAuth(realNameAuthDO);
} else {
Date date = new Date();
realNameAuthDO.setCreateTime(date);
realNameAuthDO.setId(beforeRealNameAuthDO.getId());
realNameAuthDao.updateRealNameAuth(realNameAuthDO);
}
return ResultBody.success();
} else {
return ResultBody.error(ResultEnum.PHOTO_FORMAT_ERROR);
}
}
@Override
public ResultBody<RealNameAuthDTO> detail(Integer id) {
RealNameAuthDO realNameAuthDO = realNameAuthDao.getRealNameAuthById(id);
if (realNameAuthDO != null) {
return ResultBody.success(realNameAuthDO.buildRealNameAuthDTO());
}
return ResultBody.success();
}
@Override
public ResultBody listPage(RealNameAuthQO realNameAuthQO) {
int count = realNameAuthDao.countListRealNameAuth(realNameAuthQO);
if (count == 0) {
return ResultBody.success(PageResult.buildPage(realNameAuthQO.getPageNo(), realNameAuthQO.getPageSize(), count));
}
int pageNo = realNameAuthQO.getPageNo();
realNameAuthQO.buildCurrentPage();
List<RealNameAuthDO> list = realNameAuthDao.listRealNameAuth(realNameAuthQO);
List<RealNameAuthDTO> pageList = list.stream().map(d -> {
return d.buildRealNameAuthDTO();
}).collect(Collectors.toList());
return ResultBody.success(PageResult.buildPage(pageNo, realNameAuthQO.getPageSize(), count, pageList));
}
@Override
public ResultBody<RealNameAuthDTO> userDetail(Integer userAccountId) {
RealNameAuthDO realNameAuthDO = realNameAuthDao.userDetail(userAccountId);
if (realNameAuthDO != null) {
return ResultBody.success(realNameAuthDO.buildRealNameAuthDTO());
}
return ResultBody.success();
}
public Date getDate(String str, String format) {
Date date = null;
try {
// 设置日期格式
SimpleDateFormat df = new SimpleDateFormat(format);
// String dates=df.format(new Date());// new Date()为获取当前系统时间
date = df.parse(str);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
}
package com.mmc.iuav.user.util;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.response.ResultEnum;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
/**
* @author: zj
* @Date: 2023/7/27 14:54
*/
public class RealNameAuthUtil {
public static ResultBody deal(String idCardUrl, String side) {
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + "524b1864a88f47458c1061bae3811570");
//根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/json; charset=UTF-8");
Map<String, String> querys = new HashMap<String, String>();
//configure配置
JSONObject configObj = new JSONObject();
configObj.put("side", side);
String config_str = configObj.toString();
// 拼装请求body的json字符串
JSONObject requestObj = new JSONObject();
requestObj.put("image", idCardUrl);
if (configObj.size() > 0) {
requestObj.put("configure", config_str);
}
String bodys = requestObj.toString();
return PhotoMessgHandle(idCardUrl, side, querys, headers, bodys);
}
//印刷文字识别
public static String PRINT_HOST = "http://dm-51.data.aliyun.com";
public static String PRINT_PATH = "/rest/160601/ocr/ocr_idcard.json";
//信息处理
public static ResultBody PhotoMessgHandle(String idCardUrl, String side, Map<String, String> querys, Map<String, String> headers, String bodys) {
JSONObject messg = null;
try {
HttpResponse response = RealNameAuthUtil.doPost(PRINT_HOST, PRINT_PATH, "POST", headers, querys, bodys);
int stat = response.getStatusLine().getStatusCode();
if (stat != 200) { //输出异常信息
System.out.println("Http code: " + stat);
System.out.println("http header error msg: " + response.getFirstHeader("X-Ca-Error-Message"));
System.out.println("Http body error msg:" + EntityUtils.toString(response.getEntity()));
return ResultBody.error(ResultEnum.EXPTION_ID_CARD_THOTO_MESSAGE_ERROR.getResultMsg());
}
//这是正常的情况
String res = EntityUtils.toString(response.getEntity());
JSONObject res_obj = JSON.parseObject(res);
res_obj.remove("face_rect");
res_obj.remove("card_region");
res_obj.remove("face_rect_vertices");
messg = res_obj;
return ResultBody.success(res_obj);
} catch (Exception e) {
return ResultBody.error(ResultEnum.ID_CARD_THOTO_MESSAGE_ERROR.getResultMsg());
}
}
/**
* Post String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
private static HttpClient wrapClient(String host) {
HttpClient httpClient = new DefaultHttpClient();
if (host.startsWith("https://")) {
sslClient(httpClient);
}
return httpClient;
}
private static void sslClient(HttpClient httpClient) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] xcs, String str) {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String str) {
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https", 443, ssf));
} catch (KeyManagementException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
StringBuilder sbUrl = new StringBuilder();
sbUrl.append(host);
if (!StringUtils.isBlank(path)) {
sbUrl.append(path);
}
if (null != querys) {
StringBuilder sbQuery = new StringBuilder();
for (Map.Entry<String, String> query : querys.entrySet()) {
if (0 < sbQuery.length()) {
sbQuery.append("&");
}
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
sbQuery.append(query.getValue());
}
if (!StringUtils.isBlank(query.getKey())) {
sbQuery.append(query.getKey());
if (!StringUtils.isBlank(query.getValue())) {
sbQuery.append("=");
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
}
}
}
if (0 < sbQuery.length()) {
sbUrl.append("?").append(sbQuery);
}
}
return sbUrl.toString();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mmc.iuav.user.dao.RealNameAuthDao">
<insert id="addRealNameAuth" parameterType="com.mmc.iuav.user.entity.RealNameAuthDO" useGeneratedKeys="true"
keyProperty="id">
insert into real_name_auth(user_account_id, union_id, front_id_img, back_id_img, id_number, user_name, sex, nationality,
birthday, address, issue,
start_date, end_date, is_fake_front, is_fake_back, check_status, remark, create_time)
values (#{userAccountId}, #{unionId}, #{frontIdImg}, #{backIdImg}, #{idNumber}, #{userName}, #{sex}, #{nationality},
#{birthday}, #{address}, #{issue},
#{startDate}, #{endDate}, #{fakeFront}, #{fakeBack}, #{checkStatus}, #{remark}, NOW())
</insert>
<update id="updateRealNameAuth" parameterType="com.mmc.iuav.user.entity.RealNameAuthDO">
update real_name_auth
<set>
<if test=" frontIdImg != null and frontIdImg != '' ">
front_id_img = #{frontIdImg},
</if>
<if test=" backIdImg != null and backIdImg != '' ">
back_id_img = #{backIdImg},
</if>
<if test=" idNumber != null and idNumber != '' ">
id_number = #{idNumber},
</if>
<if test=" userName != null and userName != '' ">
user_name = #{userName},
</if>
<if test=" sex != null ">
sex = #{sex},
</if>
<if test=" nationality != null and nationality != '' ">
nationality = #{nationality},
</if>
<if test=" birthday != null ">
birthday = #{birthday},
</if>
<if test=" address != null and address != '' ">
address = #{address},
</if>
<if test=" issue != null and issue != '' ">
issue = #{issue},
</if>
<if test=" startDate != null ">
start_date = #{startDate},
</if>
<if test=" fakeFront != null ">
is_fake_front = #{fakeFront},
</if>
<if test=" fakeBack != null ">
is_fake_back = #{fakeBack},
</if>
<if test=" checkStatus != null ">
check_status = #{checkStatus},
</if>
<if test=" endDate != null ">
end_date = #{endDate},
</if>
<if test=" remark != null and remark != '' ">
remark = #{remark},
</if>
<if test="createTime !=null">
create_time = NOW(),
</if>
</set>
where id = #{id}
</update>
<select id="existHasBeenAuth" resultType="java.lang.Integer">
select count(*) from real_name_auth where union_id <![CDATA[<>]]> #{unionId} and id_number = #{idNumber} and check_status = 1
</select>
<select id="getRealNameAuthByUnionId" resultType="com.mmc.iuav.user.entity.RealNameAuthDO">
select rna.id, rna.user_account_id, rna.union_id, rna.front_id_img, rna.back_id_img, rna.id_number, rna.user_name, rna.sex, rna.nationality,
rna.birthday, rna.address, rna.issue, rna.start_date, rna.end_date, rna.is_fake_front, rna.is_fake_back, rna.check_status, rna.remark,
rna.create_time
from real_name_auth rna
where rna.union_id = #{unionId} and rna.is_deleted = 0
</select>
<select id="getRealNameAuthBakByUnionId" resultType="com.mmc.iuav.user.entity.RealNameAuthDO">
select rna.id, rna.user_account_id, rna.union_id, rna.front_id_img, rna.back_id_img, rna.id_number, rna.user_name, rna.sex, rna.nationality,
rna.birthday, rna.address, rna.issue, rna.start_date, rna.end_date, rna.is_fake_front, rna.is_fake_back, rna.check_status, rna.remark,
rna.create_time
from real_name_auth rna
where rna.union_id = #{unionId} and rna.is_deleted = 0 and rna.check_status = 1
</select>
<select id="getRealNameAuthByUId" resultType="com.mmc.iuav.user.entity.RealNameAuthDO">
select rna.id,rna.union_id,rna.user_name,rna.id_number,rna.check_status,rna.sex
from real_name_auth rna
where rna.user_account_id = #{userAccountId} and rna.is_deleted = 0
</select>
<select id="getRealNameAuthById" resultType="com.mmc.iuav.user.entity.RealNameAuthDO">
select rna.id, rna.user_account_id, rna.union_id, rna.front_id_img, rna.back_id_img, rna.id_number, rna.user_name, rna.sex, rna.nationality,
rna.birthday, rna.address, rna.issue, rna.start_date, rna.end_date, rna.is_fake_front, rna.is_fake_back, rna.check_status, rna.remark,
rna.create_time
from real_name_auth rna
where rna.id = #{id} and rna.is_deleted = 0
</select>
<select id="countListRealNameAuth" resultType="java.lang.Integer">
select count(*) from real_name_auth where is_deleted = 0 and check_status = 1
</select>
<select id="listRealNameAuth" resultType="com.mmc.iuav.user.entity.RealNameAuthDO"
parameterType="com.mmc.iuav.user.model.qo.RealNameAuthQO">
select
rna.id,rna.user_account_id,ua.nick_name,rna.user_name,ua.phone_num,rna.check_status,rna.create_time,ua.remark
from user_account ua inner join real_name_auth rna on
ua.id=rna.user_account_id
where ua.`disable` = 0
<if test="keyword != null and keyword != '' ">
and ( ua.id like concat('%',#{keyword},'%')
or
ua.user_name like concat('%',#{keyword},'%')
or ua.phone_num like
concat('%',#{keyword},'%')
)
</if>
<if test="checkStatus != null ">
and rna.check_status = #{checkStatus}
</if>
order by rna.create_time DESC
limit #{pageNo},#{pageSize}
</select>
<select id="userDetail" resultType="com.mmc.iuav.user.entity.RealNameAuthDO">
select rna.id, rna.user_account_id, rna.union_id, rna.front_id_img, rna.back_id_img, rna.id_number, rna.user_name, rna.sex, rna.nationality,
rna.birthday, rna.address, rna.issue, rna.start_date, rna.end_date, rna.is_fake_front, rna.is_fake_back, rna.check_status, rna.remark,
rna.create_time
from real_name_auth rna
where rna.user_account_id = #{userAccountId} and rna.is_deleted = 0
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论