微信刷脸模块
This commit is contained in:
parent
7fc9839038
commit
ab05bf79ce
|
@ -129,7 +129,7 @@ public class WxFacePayController {
|
||||||
// 构建请求参数的JSON字符串
|
// 构建请求参数的JSON字符串
|
||||||
WxFacePayReq wxFacePayReq = new WxFacePayReq("initWxpayface", "1", System.currentTimeMillis() / 1000, 1);
|
WxFacePayReq wxFacePayReq = new WxFacePayReq("initWxpayface", "1", System.currentTimeMillis() / 1000, 1);
|
||||||
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
||||||
System.out.println("**************1、程序启动时初始化:" + wxFacePayResp.toString());
|
log.info("[WxFacePayController][initWxpayface][132] [1、程序启动时初始化:]:{}", wxFacePayResp.toString());
|
||||||
return wxFacePayResp;
|
return wxFacePayResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ public class WxFacePayController {
|
||||||
// 构建请求参数的JSON字符串
|
// 构建请求参数的JSON字符串
|
||||||
WxFacePayReq wxFacePayReq = new WxFacePayReq("getWxpayfaceRawdata", "1", System.currentTimeMillis() / 1000);
|
WxFacePayReq wxFacePayReq = new WxFacePayReq("getWxpayfaceRawdata", "1", System.currentTimeMillis() / 1000);
|
||||||
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
||||||
System.out.println("**************2、获取数据:" + wxFacePayResp.toString());
|
log.info("[WxFacePayController][getWxpayfaceRawdata][146][2、获取数据getWxpayfaceRawdata:] :{}", wxFacePayResp.toString());
|
||||||
return wxFacePayResp;
|
return wxFacePayResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,8 +156,7 @@ public class WxFacePayController {
|
||||||
public WxFacePayAuthinfoResp getWxpayfaceAuthinfo(String rawdata) throws Exception {
|
public WxFacePayAuthinfoResp getWxpayfaceAuthinfo(String rawdata) throws Exception {
|
||||||
// 构建请求参数的JSON字符串
|
// 构建请求参数的JSON字符串
|
||||||
WxFacePayAuthinfoResp wxFacePayResp = weChatPayFaceService.getWxFaceAuthInfoReqMap(rawdata);
|
WxFacePayAuthinfoResp wxFacePayResp = weChatPayFaceService.getWxFaceAuthInfoReqMap(rawdata);
|
||||||
System.out.println("**************3、获取调用凭证get_wxpayface_authinfo:" + wxFacePayResp.toString());
|
log.info("[WxFacePayController][getWxpayfaceAuthinfo][159][3、获取调用凭证get_wxpayface_authinfo:] :{}", wxFacePayResp.toString());
|
||||||
|
|
||||||
return wxFacePayResp;
|
return wxFacePayResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +184,8 @@ public class WxFacePayController {
|
||||||
.setFace_code_type("1");
|
.setFace_code_type("1");
|
||||||
|
|
||||||
WxFacePayAuthinfoResp authinfoResp = weChatPayFaceService.getWxpayfaceCode(wxFacePayReq);
|
WxFacePayAuthinfoResp authinfoResp = weChatPayFaceService.getWxpayfaceCode(wxFacePayReq);
|
||||||
System.out.println("**************4、进行人脸识别结果:" + authinfoResp.toString());
|
log.info("[WxFacePayController][getWxpayfaceCode][189][4、进行人脸识别结果:] :{}", authinfoResp.toString());
|
||||||
|
|
||||||
return authinfoResp;
|
return authinfoResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ public class WxFacePayController {
|
||||||
.body();
|
.body();
|
||||||
JSONObject tradeNoResult = JSONObject.parseObject(req0);
|
JSONObject tradeNoResult = JSONObject.parseObject(req0);
|
||||||
String outTradeNo = tradeNoResult.getString("result");
|
String outTradeNo = tradeNoResult.getString("result");
|
||||||
System.out.println("获取流水号" + outTradeNo);
|
log.info("[WxFacePayController][getOutTradeNo][208][获取流水号] :{}", outTradeNo);
|
||||||
return outTradeNo;
|
return outTradeNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,13 +232,13 @@ public class WxFacePayController {
|
||||||
.body(serverParams.toString())
|
.body(serverParams.toString())
|
||||||
.execute()
|
.execute()
|
||||||
.body();
|
.body();
|
||||||
System.out.println("5、向后台发起进行发起订单支付 结果:" + req);
|
log.info("[WxFacePayController][toCreateWxOrder][237][5、向后台发起进行发起订单支付 结果] :{}", req);
|
||||||
JSONObject serverResult = JSONObject.parseObject(req);
|
JSONObject serverResult = JSONObject.parseObject(req);
|
||||||
Map<String, Object> result = (Map<String, Object>) serverResult.get("result");
|
Map<String, Object> result = (Map<String, Object>) serverResult.get("result");
|
||||||
log.info("[WxFacePayController][toCreateWxOrder][140][5、向后端进行发起订单支付请求结果] :{}", result.toString());
|
log.info("[WxFacePayController][toCreateWxOrder][140][5、向后端进行发起订单支付请求结果] :{}", result.toString());
|
||||||
|
|
||||||
WxPayMicropayResult micropayResult = new WxPayMicropayResult();
|
WxPayMicropayResult micropayResult = new WxPayMicropayResult();
|
||||||
System.out.println("5、调用后台人脸支付API发起支付结果:"+result.toString());
|
log.info("[WxFacePayController][toCreateWxOrder][243][5、调用后台人脸支付API发起支付结果:] :{}", result.toString());
|
||||||
if (ObjUtil.isNotEmpty(result)) {
|
if (ObjUtil.isNotEmpty(result)) {
|
||||||
micropayResult.setOutTradeNo(result.get("outTradeNo").toString());
|
micropayResult.setOutTradeNo(result.get("outTradeNo").toString());
|
||||||
micropayResult.setTransactionId(result.get("transactionId").toString());
|
micropayResult.setTransactionId(result.get("transactionId").toString());
|
||||||
|
@ -253,13 +253,13 @@ public class WxFacePayController {
|
||||||
/**
|
/**
|
||||||
* 轮询逻辑封装方法
|
* 轮询逻辑封装方法
|
||||||
* 查询微信刷脸订单状态
|
* 查询微信刷脸订单状态
|
||||||
|
* 30秒
|
||||||
* 调用步骤6
|
* 调用步骤6
|
||||||
*
|
|
||||||
* @param micropayResult
|
* @param micropayResult
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean pollOrderStatus(WxPayMicropayResult micropayResult) {
|
public boolean pollOrderStatus(WxPayMicropayResult micropayResult) {
|
||||||
final long timeoutMillis = 60_000; // 60秒超时(毫秒)
|
final long timeoutMillis = 30_000; // 30秒超时(毫秒)
|
||||||
final long pollInterval = 2_000; // 轮询间隔2秒
|
final long pollInterval = 2_000; // 轮询间隔2秒
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
@ -267,17 +267,18 @@ public class WxFacePayController {
|
||||||
while (true) {
|
while (true) {
|
||||||
// 1. 查询订单状态
|
// 1. 查询订单状态
|
||||||
WxPayOrderQueryResult queryResult = this.queryOrderByNo(micropayResult);
|
WxPayOrderQueryResult queryResult = this.queryOrderByNo(micropayResult);
|
||||||
|
log.info("[WxFacePayController][pollOrderStatus][272][1. 查询订单状态:] :{}", queryResult);
|
||||||
|
|
||||||
// 2. 检查成功状态
|
// 2. 检查成功状态
|
||||||
if (WxConstant.STATE_SUCCESS.equals(queryResult.getReturnCode())) {
|
if (WxConstant.STATE_SUCCESS.equals(queryResult.getReturnCode())) {
|
||||||
System.out.println("订单支付成功!");
|
log.info("[WxFacePayController][pollOrderStatus][275][订单支付成功!]");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 检查超时
|
// 3. 检查超时
|
||||||
long elapsed = System.currentTimeMillis() - startTime;
|
long elapsed = System.currentTimeMillis() - startTime;
|
||||||
if (elapsed >= timeoutMillis) {
|
if (elapsed >= timeoutMillis) {
|
||||||
System.out.println("支付超时,未获取成功状态");
|
log.info("[WxFacePayController][pollOrderStatus][284][支付超时,未获取成功状态]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +288,7 @@ public class WxFacePayController {
|
||||||
TimeUnit.MILLISECONDS.sleep(nextPoll);
|
TimeUnit.MILLISECONDS.sleep(nextPoll);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
System.out.println("轮询被中断");
|
log.info("[WxFacePayController][pollOrderStatus][293] [轮询被中断]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,13 +313,12 @@ public class WxFacePayController {
|
||||||
.body(serverParams.toString())
|
.body(serverParams.toString())
|
||||||
.execute()
|
.execute()
|
||||||
.body();
|
.body();
|
||||||
System.out.println("6、后台发起查询订单 结果:" + req);
|
log.info("[WxFacePayController][queryOrderByNo][318][6、后台发起查询订单 结果:] :{}", req);
|
||||||
|
|
||||||
JSONObject serverResult = JSONObject.parseObject(req);
|
JSONObject serverResult = JSONObject.parseObject(req);
|
||||||
Map<String, Object> result = (Map<String, Object>) serverResult.get("result");
|
Map<String, Object> result = (Map<String, Object>) serverResult.get("result");
|
||||||
log.info("[WxFacePayController][toCreateWxOrder][140][6、后台发起查询订单 请求结果] :{}", result.toString());
|
log.info("[WxFacePayController][toCreateWxOrder][140][6、后台发起查询订单 请求结果] :{}", result.toString());
|
||||||
|
|
||||||
System.out.println("5、调用后台人脸支付API发起支付结果:"+result.toString());
|
|
||||||
if (ObjUtil.isNotEmpty(result)) {
|
if (ObjUtil.isNotEmpty(result)) {
|
||||||
queryResult.setReturnCode(result.get("returnCode").toString());
|
queryResult.setReturnCode(result.get("returnCode").toString());
|
||||||
queryResult.setOutTradeNo(result.get("outTradeNo").toString());
|
queryResult.setOutTradeNo(result.get("outTradeNo").toString());
|
||||||
|
@ -337,6 +337,7 @@ public class WxFacePayController {
|
||||||
* 支付交易返回失败或支付系统超时,调用该接口撤销交易。
|
* 支付交易返回失败或支付系统超时,调用该接口撤销交易。
|
||||||
* 如果此订单用户支付失败,微信支付系统会将此订单关闭;
|
* 如果此订单用户支付失败,微信支付系统会将此订单关闭;
|
||||||
* 如果用户支付成功,微信支付系统会将此订单资金退还给用户。
|
* 如果用户支付成功,微信支付系统会将此订单资金退还给用户。
|
||||||
|
*
|
||||||
* @param reverseRequest
|
* @param reverseRequest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -353,7 +354,7 @@ public class WxFacePayController {
|
||||||
.body(serverParams.toString())
|
.body(serverParams.toString())
|
||||||
.execute()
|
.execute()
|
||||||
.body();
|
.body();
|
||||||
System.out.println("向后台发起撤销交易 结果:" + req);
|
log.info("[WxFacePayController][toReverseOrder][359][向后台发起撤销交易 结果:] :{}", req);
|
||||||
JSONObject serverResult = JSONObject.parseObject(req);
|
JSONObject serverResult = JSONObject.parseObject(req);
|
||||||
reverseResult = (WxPayOrderReverseResult) serverResult.get("result");
|
reverseResult = (WxPayOrderReverseResult) serverResult.get("result");
|
||||||
log.info("[WxFacePayController][toReverseOrder][314][7、向后台发起撤销交易请求结果] :{}", reverseResult.toString());
|
log.info("[WxFacePayController][toReverseOrder][314][7、向后台发起撤销交易请求结果] :{}", reverseResult.toString());
|
||||||
|
@ -362,8 +363,6 @@ public class WxFacePayController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 8、更新支付结果updateWxpayfacePayResult
|
* 8、更新支付结果updateWxpayfacePayResult
|
||||||
*
|
*
|
||||||
|
@ -381,7 +380,47 @@ public class WxFacePayController {
|
||||||
.setAuthinfo(wxFacePayResp0.getAuthinfo());
|
.setAuthinfo(wxFacePayResp0.getAuthinfo());
|
||||||
|
|
||||||
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
||||||
System.out.println("**************8、更新支付结果updateWxpayfacePayResult:" + wxFacePayResp.toString());
|
log.info("[WxFacePayController][updateWxpayfacePayResult][385][8、更新支付结果updateWxpayfacePayResult] :{}", wxFacePayResp.toString());
|
||||||
|
return wxFacePayResp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 9、停止刷脸支付stopWxpayface
|
||||||
|
* 仅在人脸凭证/付款码face_code【第4步骤】未返回前可用,face_code返回后不可停止
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/stopWxpayface", method = RequestMethod.POST)
|
||||||
|
public WxFacePayResp stopWxpayface(WxFacePayAuthinfoResp wxFacePayResp0) throws JsonProcessingException, UnsupportedEncodingException, WxpayFaceSDKDll.DllRegistrationException {
|
||||||
|
// 构建请求参数的JSON字符串
|
||||||
|
WxFacePayReq wxFacePayReq = new WxFacePayReq("stopWxpayface", "1", System.currentTimeMillis() / 1000);
|
||||||
|
wxFacePayReq.setAppid(wxMpProperties.getMchConfig().getAppId())
|
||||||
|
.setMch_id(wxMpProperties.getMchConfig().getMchId())
|
||||||
|
.setStore_id(WxConstant.STORE_ID)
|
||||||
|
.setAuthinfo(wxFacePayResp0.getAuthinfo());
|
||||||
|
|
||||||
|
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
||||||
|
log.info("[WxFacePayController][stopWxpayface][407][9、停止刷脸支付stopWxpayface的结果:] :{}", wxFacePayResp.toString());
|
||||||
|
return wxFacePayResp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 10、释放资源releaseWxpayface
|
||||||
|
* 首次刷脸需要initWxpayface,刷脸结束后不需要调用releaseWxpayface,否则下次刷脸需要重新initWxpayface,影响启动耗时;
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/releaseWxpayface", method = RequestMethod.POST)
|
||||||
|
public WxFacePayResp releaseWxpayface(WxFacePayAuthinfoResp wxFacePayResp0) throws JsonProcessingException, UnsupportedEncodingException, WxpayFaceSDKDll.DllRegistrationException {
|
||||||
|
// 构建请求参数的JSON字符串
|
||||||
|
WxFacePayReq wxFacePayReq = new WxFacePayReq("releaseWxpayface", "1", System.currentTimeMillis() / 1000);
|
||||||
|
|
||||||
|
WxFacePayResp wxFacePayResp = weChatPayFaceService.doWxPayIniMethod(wxFacePayReq);
|
||||||
|
log.info("[WxFacePayController][releaseWxpayface][425][10、释放资源releaseWxpayface的结果:] :{}", wxFacePayResp.toString());
|
||||||
return wxFacePayResp;
|
return wxFacePayResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,8 +442,7 @@ public class WxFacePayController {
|
||||||
.body(serverParams.toString())
|
.body(serverParams.toString())
|
||||||
.execute()
|
.execute()
|
||||||
.body();
|
.body();
|
||||||
System.out.println("11、向后端发起更新状态为成功 结果:" + req);
|
log.info("[WxFacePayController][updatePayResult][447][11、向后端发起更新状态为成功 结果:] :{}", req.toString());
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(req);
|
JSONObject jsonObject = JSONObject.parseObject(req);
|
||||||
Map<String, Object> result = (Map<String, Object>) jsonObject.get("result");
|
Map<String, Object> result = (Map<String, Object>) jsonObject.get("result");
|
||||||
log.info("[WxFacePayController][updatePayResult][140][11、向后端发起更新状态为成功 请求结果] :{}", result.toString());
|
log.info("[WxFacePayController][updatePayResult][140][11、向后端发起更新状态为成功 请求结果] :{}", result.toString());
|
||||||
|
@ -413,10 +451,8 @@ public class WxFacePayController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 4、进行人脸识别getWxpayfaceCode(获取支付凭证)
|
* 4、进行人脸识别getWxpayfaceCode(获取支付凭证)
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,6 +20,7 @@ public interface WeChatPayFaceService {
|
||||||
* 调用方法
|
* 调用方法
|
||||||
* 1、程序启动时初始化initWxpayface;2、获取数据getWxpayfaceRawdata;
|
* 1、程序启动时初始化initWxpayface;2、获取数据getWxpayfaceRawdata;
|
||||||
* 8、更新支付结果updateWxpayfacePayResult
|
* 8、更新支付结果updateWxpayfacePayResult
|
||||||
|
* 9、停止刷脸支付stopWxpayface
|
||||||
* @param wxFacePayReq
|
* @param wxFacePayReq
|
||||||
* @return
|
* @return
|
||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class WxFacePayAuthinfoResp {
|
||||||
* 3、获取调用凭证
|
* 3、获取调用凭证
|
||||||
* 必填:否
|
* 必填:否
|
||||||
* authinfo的有效时间, 单位秒。
|
* authinfo的有效时间, 单位秒。
|
||||||
|
* 在有效时间内, 对于同一台终端设备,相同的参数的前提下(如:相同的公众号、商户号、 门店编号等),可以用同一个authinfo,多次调用SDK的getWxpayfaceCode接口。
|
||||||
*/
|
*/
|
||||||
private int expires_in;
|
private int expires_in;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue