微信刷脸模块
This commit is contained in:
parent
ab05bf79ce
commit
9c09e8f004
|
@ -76,45 +76,57 @@ public class WxFacePayController {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/doFacePay", method = RequestMethod.POST)
|
@RequestMapping(value = "/doFacePay", method = RequestMethod.POST)
|
||||||
public Result<WxFacePayAuthinfoResp> doFacePay(@RequestBody WxFaceOrderVo wxFaceOrderVo) throws Exception {
|
public Result<String> doFacePay(@RequestBody WxFaceOrderVo wxFaceOrderVo) throws Exception {
|
||||||
//1 初始化
|
Result<String> result = new Result<>();
|
||||||
this.initWxpayface();
|
try {
|
||||||
|
//1 初始化
|
||||||
|
this.initWxpayface();
|
||||||
|
|
||||||
//2 获取数据getWxpayfaceRawdata
|
//2 获取数据getWxpayfaceRawdata
|
||||||
WxFacePayResp wxFacePayResp = this.getWxpayfaceRawdata();
|
WxFacePayResp wxFacePayResp = this.getWxpayfaceRawdata();
|
||||||
//String rawdata = wxFacePayResp.getRawdata();
|
//String rawdata = wxFacePayResp.getRawdata();
|
||||||
|
|
||||||
//3、获取调用凭证get_wxpayface_authinfo(rawdata)(获取调用凭证)
|
//3、获取调用凭证get_wxpayface_authinfo(rawdata)(获取调用凭证)
|
||||||
WxFacePayAuthinfoResp wxFacePayResp0 = this.getWxpayfaceAuthinfo(wxFacePayResp.getRawdata());
|
WxFacePayAuthinfoResp wxFacePayResp0 = this.getWxpayfaceAuthinfo(wxFacePayResp.getRawdata());
|
||||||
|
|
||||||
//4、进行人脸识别getWxpayfaceCode(获取支付凭证)
|
//4、进行人脸识别getWxpayfaceCode(获取支付凭证)
|
||||||
WxFacePayAuthinfoResp authinfoResp = this.getWxpayfaceCode(wxFaceOrderVo, wxFacePayResp0);
|
WxFacePayAuthinfoResp authinfoResp = this.getWxpayfaceCode(wxFaceOrderVo, wxFacePayResp0);
|
||||||
|
|
||||||
WxPayMicropayResult micropayResult = new WxPayMicropayResult();
|
WxPayMicropayResult micropayResult = new WxPayMicropayResult();
|
||||||
if (StringUtil.isNotBlank(authinfoResp.getFace_code())) {
|
if (StringUtil.isNotBlank(authinfoResp.getFace_code())) {
|
||||||
//5、调用后台人脸支付API发起支付
|
//5、调用后台人脸支付API发起支付
|
||||||
wxFaceOrderVo.setOutTradeNo(getOutTradeNo());
|
wxFaceOrderVo.setOutTradeNo(getOutTradeNo());
|
||||||
micropayResult = this.toCreateWxOrder(authinfoResp, wxFaceOrderVo, wxFacePayResp0);
|
micropayResult = this.toCreateWxOrder(authinfoResp, wxFaceOrderVo, wxFacePayResp0);
|
||||||
|
|
||||||
//6、向后端查询订单状态 WxPayOrderQueryResult queryResult = queryOrderByNo(micropayResult);
|
//6、向后端查询订单状态 WxPayOrderQueryResult queryResult = queryOrderByNo(micropayResult);
|
||||||
boolean isSuccess = pollOrderStatus(micropayResult);
|
boolean isSuccess = pollOrderStatus(micropayResult);
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
//8、更新支付结果updateWxpayfacePayResult
|
//8、更新支付结果updateWxpayfacePayResult
|
||||||
WxFacePayResp updFacePayResp = this.updateWxpayfacePayResult(wxFacePayResp0);
|
WxFacePayResp updFacePayResp = this.updateWxpayfacePayResult(wxFacePayResp0);
|
||||||
|
|
||||||
if (ObjUtil.isNotEmpty(updFacePayResp) && WxConstant.STATE_SUCCESS.equals(updFacePayResp.getReturn_code())) {
|
if (ObjUtil.isNotEmpty(updFacePayResp) && WxConstant.STATE_SUCCESS.equals(updFacePayResp.getReturn_code())) {
|
||||||
//向后端发起更新订单,进行相应的操作、
|
//11、向后端发起更新订单,进行相应的操作、
|
||||||
this.updatePayResult(micropayResult);
|
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 { //查询失败或者长时间未有结果
|
} else {
|
||||||
//7、撤销交易reverse
|
result = Result.error("获取人脸识别支付凭证为空值");
|
||||||
WxPayOrderReverseRequest reverseRequest = new WxPayOrderReverseRequest();
|
|
||||||
reverseRequest.setTransactionId(micropayResult.getTransactionId());
|
|
||||||
reverseRequest.setOutTradeNo(micropayResult.getOutTradeNo());
|
|
||||||
WxPayOrderReverseResult reverseResult = this.toReverseOrder(reverseRequest);
|
|
||||||
}
|
}
|
||||||
|
} 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秒
|
* 30秒
|
||||||
* 调用步骤6
|
* 调用步骤6
|
||||||
|
*
|
||||||
* @param micropayResult
|
* @param micropayResult
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue