package me.zhengjie.application.bank.controller; import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.arcsoft.face.*; import com.arcsoft.face.enums.ErrorInfo; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.rest.AnonymousPostMapping; import me.zhengjie.application.admin.service.SmsTemplateService; import me.zhengjie.application.bank.BaseController; import me.zhengjie.application.bank.controller.vo.CompareImageVo; import me.zhengjie.application.bank.service.BankNotarizeService; import me.zhengjie.application.bank.service.UserAXQInfoService; import me.zhengjie.application.bank.service.dao.CompareImageDto; import me.zhengjie.base.ResponseDTO; import me.zhengjie.base.ResultCode; import me.zhengjie.base.config.TencentHumanFaceVerify; import me.zhengjie.base.mq.RedisCacheConfig; import me.zhengjie.base.util.BeanCopyUtils; import me.zhengjie.base.util.FileUploadUtil; import me.zhengjie.base.util.UUIDGenerator; import me.zhengjie.base.util.tencent.h5face.SdkTest; import me.zhengjie.dao.mybatis.OrderFileRepository; import me.zhengjie.dao.mybatis.FaceCompareRepository; import me.zhengjie.dao.mybatis.entity.OrderFileEntity; import me.zhengjie.dao.mybatis.entity.FaceCompareEntity; import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @Validated @RestController @RequestMapping("${fqgz.bank.app.url-prefix}") @Slf4j @RequiredArgsConstructor @Api(tags = "客户经理APP: 公证流程") public class BankNotarizeController extends BaseController { private final OrderFileRepository orderFileRepository; private final UserAXQInfoService userAXQInfoService; private final BankNotarizeService bankNotarizeService; private final TencentHumanFaceVerify faceVerify; private final SmsTemplateService smsTemplateService; private final FaceCompareRepository thirdPartyInterfaceRepository; private final RedisTemplate redisTemplate; /** * 获取签名公证书URL * * @param json * @return * @throws Exception */ @RequestMapping("/getNotarization") public ResponseDTO getNotarization(@RequestBody String json) throws Exception { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); if (StringUtils.isEmpty(businessNo)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } OrderFileEntity orderFile = orderFileRepository.getOrderNotarization(businessNo); // 下载到指定的目录 String filePath = "tmp/" + UUIDGenerator.uuid() + ".pdf"; return ResponseDTO.success(FileUploadUtil.getCustomUrl(orderFile.getSignedPdfUrl(), filePath)); } @RequestMapping("/axqRegister") public ResponseDTO axqRegister(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); String phone = jsonObj.getString("phone"); String name = jsonObj.getString("name"); if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(phone) || StringUtils.isEmpty(name)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.registAXQUser(idCard, phone, name); } // 人脸核身,当事人 @RequestMapping("/order/getFaceId") public ResponseDTO getFaceId(@RequestBody String json) throws Exception { // 这里需要先判断公证员是否在线 JSONObject jsonObj = JSONObject.parseObject(json); String userName = jsonObj.getString("userName"); String idCard = jsonObj.getString("idCard"); String businessNo = jsonObj.getString("businessNo"); if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(idCard)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } ResponseDTO result = bankNotarizeService.onlineNotary(businessNo); if (!result.isSuccess()) { return result; } JSONObject str = SdkTest.getFaceId(faceVerify.getBankWebankAppId(), faceVerify.getBankSecret(), faceVerify.getBankKeyLicence(), userName, idCard, businessNo); return ResponseDTO.success(str); } /** * 视频通话 * * @param json * @return ResponseDTO */ @AnonymousPostMapping("/video/call") public ResponseDTO videoCall(@RequestBody String json) { JSONObject jsonObject = JSONObject.parseObject(json); String businessNo = jsonObject.getString("businessNo"); ResponseDTO result = bankNotarizeService.onlineNotary(businessNo); if (!result.isSuccess()) { return result; } // 这里保存推送的数据 redisTemplate.convertAndSend(RedisCacheConfig.CHANNEL_WEB_SOCKET, json); return bankNotarizeService.videoCall(json); } @RequestMapping("/order/pdf") public ResponseDTO getOrderPDF(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); if (StringUtils.isEmpty(businessNo)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } ResponseDTO order = bankNotarizeService.getOrderPDF(businessNo); return order; } @RequestMapping("/order/note") public ResponseDTO note(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); if (StringUtils.isEmpty(businessNo)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } // OrderFileEntity orderFile = orderFileRepository.getOrderNote(businessNo); // 判断如果面谈笔录没有,给提示 if (orderFile == null) { return ResponseDTO.error(ResultCode.INTERVIEW_NOTE_UNSUBMIT); } // pdf的地址预览 String noteUrl = FileUploadUtil.getPreviewUrl(orderFile.getHtmlUrl()); return ResponseDTO.success(noteUrl); } @RequestMapping("/sendAuthMessage") public ResponseDTO sendAuthMessage(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); if (StringUtils.isEmpty(idCard)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.sendAuthMessage(idCard); } @RequestMapping("/verifyAuthMessage") public ResponseDTO verifyAuthMessage(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); String checkCode = jsonObj.getString("checkCode"); if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(checkCode)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.verifyAuthMessage(idCard, checkCode); } @RequestMapping("/getAuthStatus") public ResponseDTO getAuthStatus(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); if (StringUtils.isEmpty(idCard)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.getAuthStatus(idCard); } /** * 当事人签名 * * @param json * @return */ @RequestMapping("/uploadSeal") @ApiOperation("当事人签名") public ResponseDTO uploadSeal(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); JSONArray jsonArray = jsonObj.getJSONArray("signInfo"); if (StringUtils.isEmpty(businessNo) || jsonArray == null) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.uploadSeal(businessNo, jsonArray); } @RequestMapping("/active-arcsoft") public ResponseDTO activeArcsoft() { // 从官网获取 String appId = "6F5JVsCCeSEbBSLSXWVwPki71yK5Y4Jf7oUjA4Y3mLtu"; String sdkKey = "5qKM4a9oNSXNhXdwd7Ycrvnxdw2JXjcyeccYmb4zND7S"; FaceEngine faceEngine = new FaceEngine("/home/tom/nt/lib/so"); // 激活引擎 int errorCode = faceEngine.activeOnline(appId, sdkKey); if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) { System.out.println("引擎激活失败"); } else { System.out.println("引擎激活成功"); } // 引擎卸载 errorCode = faceEngine.unInit(); return ResponseDTO.success(); } @RequestMapping("/isFaceCompare") public ResponseDTO isFaceCompare(@RequestBody String json){ // 这里需要先判断公证员是否在线 JSONObject jsonObj = JSONObject.parseObject(json); String userName = jsonObj.getString("userName"); String idCard = jsonObj.getString("idCard"); String businessNo = jsonObj.getString("businessNo"); if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(idCard)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } ResponseDTO result = bankNotarizeService.onlineNotary(businessNo); if (!result.isSuccess()) { return result; } //判断传入的当事人 是否做过人脸核身 QueryWrapper thirdPartyInterfaceEntityQueryWrapper = new QueryWrapper<>(); thirdPartyInterfaceEntityQueryWrapper.eq("name",userName).eq("id_card",idCard); List list = thirdPartyInterfaceRepository.getList(thirdPartyInterfaceEntityQueryWrapper); if (CollectionUtil.isEmpty(list)){ return ResponseDTO.error(ResultCode.RESULT_DATA_NONE); } return ResponseDTO.success(); } /** * 银行客户经理的人脸照片比对 * @param compareImageVo * @return */ //@RequestMapping("/face-compare") @AnonymousPostMapping("/face-compare") public ResponseDTO faceCompare(@RequestBody CompareImageVo compareImageVo){ ResponseDTO result = bankNotarizeService.appFaceCompare(BeanCopyUtils.convertObj(compareImageVo, CompareImageDto.class)); if(result.isSuccess()) { // 4---开始公证(待公证) -- 2个公证员,发送短信 smsTemplateService.startNotarize(compareImageVo.getBusinessNo()); } return result; } }