From 9c09e8f0046110fda3b4b17f9b80ae7591cf55d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=AA?= <1044122544@qq.com> Date: Mon, 9 Jun 2025 17:36:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=88=B7=E8=84=B8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/controller/WxFacePayController.java | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/dpkj/modules/scanface/wx/controller/WxFacePayController.java b/src/main/java/com/dpkj/modules/scanface/wx/controller/WxFacePayController.java index 63d4c1c..4226bc1 100644 --- a/src/main/java/com/dpkj/modules/scanface/wx/controller/WxFacePayController.java +++ b/src/main/java/com/dpkj/modules/scanface/wx/controller/WxFacePayController.java @@ -76,45 +76,57 @@ public class WxFacePayController { * @throws Exception */ @RequestMapping(value = "/doFacePay", method = RequestMethod.POST) - public Result doFacePay(@RequestBody WxFaceOrderVo wxFaceOrderVo) throws Exception { - //1 初始化 - this.initWxpayface(); + public Result doFacePay(@RequestBody WxFaceOrderVo wxFaceOrderVo) throws Exception { + Result result = new Result<>(); + try { + //1 初始化 + this.initWxpayface(); - //2 获取数据getWxpayfaceRawdata - WxFacePayResp wxFacePayResp = this.getWxpayfaceRawdata(); - //String rawdata = wxFacePayResp.getRawdata(); + //2 获取数据getWxpayfaceRawdata + WxFacePayResp wxFacePayResp = this.getWxpayfaceRawdata(); + //String rawdata = wxFacePayResp.getRawdata(); - //3、获取调用凭证get_wxpayface_authinfo(rawdata)(获取调用凭证) - WxFacePayAuthinfoResp wxFacePayResp0 = this.getWxpayfaceAuthinfo(wxFacePayResp.getRawdata()); + //3、获取调用凭证get_wxpayface_authinfo(rawdata)(获取调用凭证) + WxFacePayAuthinfoResp wxFacePayResp0 = this.getWxpayfaceAuthinfo(wxFacePayResp.getRawdata()); - //4、进行人脸识别getWxpayfaceCode(获取支付凭证) - WxFacePayAuthinfoResp authinfoResp = this.getWxpayfaceCode(wxFaceOrderVo, wxFacePayResp0); + //4、进行人脸识别getWxpayfaceCode(获取支付凭证) + WxFacePayAuthinfoResp authinfoResp = this.getWxpayfaceCode(wxFaceOrderVo, wxFacePayResp0); - WxPayMicropayResult micropayResult = new WxPayMicropayResult(); - if (StringUtil.isNotBlank(authinfoResp.getFace_code())) { - //5、调用后台人脸支付API发起支付 - wxFaceOrderVo.setOutTradeNo(getOutTradeNo()); - micropayResult = this.toCreateWxOrder(authinfoResp, wxFaceOrderVo, wxFacePayResp0); + WxPayMicropayResult micropayResult = new WxPayMicropayResult(); + if (StringUtil.isNotBlank(authinfoResp.getFace_code())) { + //5、调用后台人脸支付API发起支付 + wxFaceOrderVo.setOutTradeNo(getOutTradeNo()); + micropayResult = this.toCreateWxOrder(authinfoResp, wxFaceOrderVo, wxFacePayResp0); - //6、向后端查询订单状态 WxPayOrderQueryResult queryResult = queryOrderByNo(micropayResult); - boolean isSuccess = pollOrderStatus(micropayResult); - if (isSuccess) { - //8、更新支付结果updateWxpayfacePayResult - WxFacePayResp updFacePayResp = this.updateWxpayfacePayResult(wxFacePayResp0); + //6、向后端查询订单状态 WxPayOrderQueryResult queryResult = queryOrderByNo(micropayResult); + boolean isSuccess = pollOrderStatus(micropayResult); + if (isSuccess) { + //8、更新支付结果updateWxpayfacePayResult + WxFacePayResp updFacePayResp = this.updateWxpayfacePayResult(wxFacePayResp0); - if (ObjUtil.isNotEmpty(updFacePayResp) && WxConstant.STATE_SUCCESS.equals(updFacePayResp.getReturn_code())) { - //向后端发起更新订单,进行相应的操作、 - this.updatePayResult(micropayResult); + if (ObjUtil.isNotEmpty(updFacePayResp) && WxConstant.STATE_SUCCESS.equals(updFacePayResp.getReturn_code())) { + //11、向后端发起更新订单,进行相应的操作、 + this.updatePayResult(micropayResult); + + result = Result.ok("微信刷脸成功!", micropayResult.getOutTradeNo()); + } + } else { //查询失败或者长时间未有结果 + //7、撤销交易reverse + WxPayOrderReverseRequest reverseRequest = new WxPayOrderReverseRequest(); + reverseRequest.setTransactionId(micropayResult.getTransactionId()); + reverseRequest.setOutTradeNo(micropayResult.getOutTradeNo()); + WxPayOrderReverseResult reverseResult = this.toReverseOrder(reverseRequest); + result = Result.error("微信刷脸失败后已经撤销订单!"); } - } else { //查询失败或者长时间未有结果 - //7、撤销交易reverse - WxPayOrderReverseRequest reverseRequest = new WxPayOrderReverseRequest(); - reverseRequest.setTransactionId(micropayResult.getTransactionId()); - reverseRequest.setOutTradeNo(micropayResult.getOutTradeNo()); - WxPayOrderReverseResult reverseResult = this.toReverseOrder(reverseRequest); + } else { + result = Result.error("获取人脸识别支付凭证为空值"); } + } catch (Exception e) { + e.printStackTrace(); + log.info("[WxFacePayController][doFacePay][84][微信刷脸完成流程出错] :{}", e.getMessage()); + result = Result.error("微信刷脸完成流程出错:" + e.getMessage()); } - return Result.ok(authinfoResp); + return result; } @@ -255,6 +267,7 @@ public class WxFacePayController { * 查询微信刷脸订单状态 * 30秒 * 调用步骤6 + * * @param micropayResult * @return */