New file |
| | |
| | | package com.panzhihua.service_community.api; |
| | | |
| | | import static com.panzhihua.common.enums.IdentityAuthMethodEnum.FACE_AUTH; |
| | | import static com.panzhihua.common.enums.IdentityAuthTypeEnum.ELDER_AUTH; |
| | | import static com.panzhihua.common.enums.IdentityAuthTypeEnum.PENSION_AUTH; |
| | | import static java.util.Objects.nonNull; |
| | | import static org.apache.commons.lang3.StringUtils.isBlank; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.panzhihua.common.model.dtos.community.AddIdentityAuthDTO; |
| | | import com.panzhihua.common.model.dtos.community.GetIdentityEidTokenDTO; |
| | | import com.panzhihua.common.model.dtos.community.PageIdentityAuthRecordDTO; |
| | | import com.panzhihua.common.model.helper.AESUtil; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.SysConfVO; |
| | | import com.panzhihua.common.utlis.TencentUtils; |
| | | import com.panzhihua.service_community.dao.ComElderAuthElderliesDAO; |
| | | import com.panzhihua.service_community.dao.ComPensionAuthPensionerDAO; |
| | | import com.panzhihua.service_community.dao.SysConfMapper; |
| | | import com.panzhihua.service_community.model.dos.ComElderAuthElderliesDO; |
| | | import com.panzhihua.service_community.model.dos.ComPensionAuthPensionerDO; |
| | | import com.panzhihua.service_community.model.dos.SysConfDO; |
| | | import com.panzhihua.service_community.service.ComElderAuthRecordsService; |
| | | import com.panzhihua.service_community.service.ComPensionAuthRecordService; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @title: IdentityAuthApi |
| | | * @projectName: 成都呐喊信息技术有限公司-智慧社区项目 |
| | | * @description: 身份认证相关api |
| | | * @author: hans |
| | | * @date: 2021/09/01 18:06 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/identity-auth") |
| | | public class IdentityAuthApi { |
| | | |
| | | private static final String ELDER_AUTH_TYPE_PREFIX = "ELDER_AUTH_TYPE_"; |
| | | private static final String PENSION_AUTH_TYPE_PREFIX = "PENSION_AUTH_TYPE_"; |
| | | |
| | | @Resource |
| | | private ComElderAuthRecordsService comElderAuthRecordsService; |
| | | @Resource |
| | | private ComPensionAuthRecordService comPensionAuthRecordService; |
| | | @Resource |
| | | private SysConfMapper sysConfDao; |
| | | @Resource |
| | | private ComElderAuthElderliesDAO comElderAuthElderliesDAO; |
| | | @Resource |
| | | private ComPensionAuthPensionerDAO comPensionAuthPensionerDAO; |
| | | |
| | | @Value("${domain.aesKey:}") |
| | | private String aesKey; |
| | | |
| | | /** |
| | | * 新增身份认证 |
| | | * @param addIdentityAuthDTO 新增身份认证请求参数 |
| | | * @return 新增结果 |
| | | */ |
| | | @PostMapping("/add") |
| | | public R addIdentityAuth(@RequestBody AddIdentityAuthDTO addIdentityAuthDTO) { |
| | | String eidToken = addIdentityAuthDTO.getEidToken(); |
| | | boolean isEidTokenBlank = isBlank(eidToken); |
| | | if (!Boolean.logicalXor(isEidTokenBlank, isBlank(addIdentityAuthDTO.getAuthVideo()))) { |
| | | return R.fail("缺少认证参数"); |
| | | } |
| | | if (!isEidTokenBlank) { |
| | | String result = TencentUtils.getEidResult(eidToken); |
| | | JSONObject object = JSON.parseObject(result); |
| | | if (object == null) { |
| | | return R.fail("人脸信息与所填信息不符,请检查所填写信息"); |
| | | } |
| | | JSONObject textObject = object.getJSONObject("Text"); |
| | | String code = textObject.getString("ErrCode"); |
| | | if (!code.equals("0")) { |
| | | log.error("人脸核验失败,错误原因:" + textObject.toJSONString()); |
| | | return R.fail("人脸信息与所填信息不符,请检查所填写信息"); |
| | | } |
| | | addIdentityAuthDTO.setAuthMethod(FACE_AUTH.getMethod()); |
| | | addIdentityAuthDTO.setVerificationResult(object.toJSONString()); |
| | | } |
| | | int authType = addIdentityAuthDTO.getAuthType().intValue(); |
| | | if (authType == ELDER_AUTH.getType()) { |
| | | return comElderAuthRecordsService.addElderAuth(addIdentityAuthDTO); |
| | | } else if (authType == PENSION_AUTH.getType()) { |
| | | return comPensionAuthRecordService.addPensionAuth(addIdentityAuthDTO); |
| | | } else { |
| | | return R.fail("请核对需要认证的类型"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 分页查询身份认证记录 |
| | | * @param pageIdentityAuthRecordDTO 分页查询身份认证记录参数 |
| | | * @return 身份认证记录列表 |
| | | */ |
| | | @PostMapping("/record/page") |
| | | public R queryRecordWithPage(@RequestBody PageIdentityAuthRecordDTO pageIdentityAuthRecordDTO) { |
| | | int authType = pageIdentityAuthRecordDTO.getAuthType().intValue(); |
| | | if (authType == ELDER_AUTH.getType()) { |
| | | return comElderAuthRecordsService.queryRecordWithPage(pageIdentityAuthRecordDTO); |
| | | } else if (authType == PENSION_AUTH.getType()) { |
| | | return comPensionAuthRecordService.queryRecordWithPage(pageIdentityAuthRecordDTO); |
| | | } else { |
| | | return R.fail("请核对需要查询的身份认证类型"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取身份认证详情 |
| | | * @param authType 认证类型 |
| | | * @param identityAuthId 认证id |
| | | * @return 认证记录详情 |
| | | */ |
| | | @GetMapping("/detail") |
| | | public R retrieveIdentityAuthDetail(@RequestParam("authType") Integer authType, |
| | | @RequestParam("identityAuthId") Long identityAuthId) { |
| | | if (authType.intValue() == ELDER_AUTH.getType()) { |
| | | return comElderAuthRecordsService.retrieveElderAuthDetail(identityAuthId); |
| | | } else if (authType.intValue() == PENSION_AUTH.getType()) { |
| | | return comPensionAuthRecordService.retrievePensionAuthDetail(identityAuthId); |
| | | } else { |
| | | return R.fail("请核对认证类型"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取身份认证方式 |
| | | * @param communityId |
| | | * @param identityAuthType |
| | | * @return 认证方式 |
| | | */ |
| | | @GetMapping("/mode") |
| | | public R getIdentityAuthMode(@RequestParam(value = "communityId") Long communityId, |
| | | @RequestParam(value = "identityAuthType") Integer identityAuthType) { |
| | | String identityCode; |
| | | if (identityAuthType.intValue() == ELDER_AUTH.getType()) { |
| | | //高龄认证 |
| | | identityCode = ELDER_AUTH_TYPE_PREFIX + communityId; |
| | | } else if (identityAuthType.intValue() == PENSION_AUTH.getType()) { |
| | | //养老认证 |
| | | identityCode = PENSION_AUTH_TYPE_PREFIX + communityId; |
| | | } else { |
| | | return R.fail("身份认证类型错误"); |
| | | } |
| | | SysConfDO sysConfDO = sysConfDao.selectOne(new QueryWrapper<SysConfDO>() |
| | | .lambda().eq(SysConfDO::getCode, identityCode).eq(SysConfDO::getCommunityId, communityId)); |
| | | if (nonNull(sysConfDO)) { |
| | | SysConfVO sysConfVO = new SysConfVO(); |
| | | BeanUtils.copyProperties(sysConfDO, sysConfVO); |
| | | return R.ok(sysConfVO.getValue()); |
| | | } |
| | | return R.fail("获取失败!"); |
| | | } |
| | | |
| | | /** |
| | | * 获取身份认证人脸核验token |
| | | * @param getIdentityEidTokenDTO |
| | | * @return token |
| | | */ |
| | | @PostMapping("/getEidToken") |
| | | public R getEidToken(@RequestBody GetIdentityEidTokenDTO getIdentityEidTokenDTO) { |
| | | int isExist; |
| | | String idCard; |
| | | try { |
| | | idCard = AESUtil.encrypt128(getIdentityEidTokenDTO.getIdCard(), aesKey); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("加密失败【{}】", e.getMessage()); |
| | | return R.fail("认证失败,请重新尝试"); |
| | | } |
| | | if (getIdentityEidTokenDTO.getAuthType().intValue() == ELDER_AUTH.getType()) { |
| | | //高龄认证 |
| | | isExist = comElderAuthElderliesDAO.selectCount(new QueryWrapper<ComElderAuthElderliesDO>() |
| | | .lambda().eq(ComElderAuthElderliesDO::getName, getIdentityEidTokenDTO.getName()) |
| | | .eq(ComElderAuthElderliesDO::getIdCard, idCard)); |
| | | } else if (getIdentityEidTokenDTO.getAuthType().intValue() == PENSION_AUTH.getType()) { |
| | | //养老认证 |
| | | isExist = comPensionAuthPensionerDAO.selectCount(new QueryWrapper<ComPensionAuthPensionerDO>() |
| | | .lambda().eq(ComPensionAuthPensionerDO::getName, getIdentityEidTokenDTO.getName()) |
| | | .eq(ComPensionAuthPensionerDO::getIdCard, idCard)); |
| | | } else { |
| | | return R.fail("请核对身份认证类型"); |
| | | } |
| | | if (isExist <= 0) { |
| | | return R.fail("该人员未在社区报道无法认证"); |
| | | } |
| | | // 获取EidToken |
| | | return R.ok(TencentUtils.getEidToken(getIdentityEidTokenDTO.getName(), getIdentityEidTokenDTO.getIdCard())); |
| | | } |
| | | } |