支付宝刷脸完善

This commit is contained in:
张雪 2025-06-27 18:40:46 +08:00
parent 37ba56bacc
commit 6317f78628
1 changed files with 80 additions and 37 deletions

View File

@ -57,10 +57,14 @@ public class AliScanFaceServiceImpl implements IAliScanFaceService {
@Override @Override
public Result<JSONObject> aliFacePay(AliOrderVo aliOrderVo) { public Result<JSONObject> aliFacePay(AliOrderVo aliOrderVo) {
try { try {
/**
* 0执行ABCP初始化
*/
Result<Object> result = this.iniAbcpAbsolute();
if (result.isSuccess()) {
/** /**
* 1获取刷脸"刷脸去初始化服务"的ftoken返回值 * 1获取刷脸"刷脸去初始化服务"的ftoken返回值
*/ */
this.iniAbcpAbsolute();
//参数 //参数
JSONObject zolozConfig = new JSONObject().fluentPut("installAngle", 90); JSONObject zolozConfig = new JSONObject().fluentPut("installAngle", 90);
JSONObject params = new JSONObject() JSONObject params = new JSONObject()
@ -98,6 +102,9 @@ public class AliScanFaceServiceImpl implements IAliScanFaceService {
log.error("[AliScanFaceServiceImpl][aliFacePay][299]调用ABCP 刷脸初始化服务失败 {}", startServiceIniResult.getMessage()); log.error("[AliScanFaceServiceImpl][aliFacePay][299]调用ABCP 刷脸初始化服务失败 {}", startServiceIniResult.getMessage());
return Result.error(startServiceIniResult.getMessage()); return Result.error(startServiceIniResult.getMessage());
} }
}else {
return Result.error("执行iniAbcpAbsolute初始化失败");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("[AliScanFaceServiceImpl][aliFacePay][302][整个支付宝刷脸模块出现失败:] {}", e.getMessage()); log.error("[AliScanFaceServiceImpl][aliFacePay][302][整个支付宝刷脸模块出现失败:] {}", e.getMessage());
@ -132,23 +139,59 @@ public class AliScanFaceServiceImpl implements IAliScanFaceService {
//指定支付宝LOT SDK的本地库路径 //指定支付宝LOT SDK的本地库路径
AbcpInvoke.SetAPIPathFile(aliFaceConfig.getDllPath()); AbcpInvoke.SetAPIPathFile(aliFaceConfig.getDllPath());
// 使用 CountDownLatch 实现线程同步
CountDownLatch latch = new CountDownLatch(1);
CountDownLatch latchFinish = new CountDownLatch(1);
//获取返回数据
AtomicReference<Integer> processCode = new AtomicReference<>();
AtomicReference<String> processResult = new AtomicReference<>();
AtomicReference<Integer> finishCode = new AtomicReference<>();
AtomicReference<String> finishResult = new AtomicReference<>();
//创建回调实例 //创建回调实例
AbcpInvoke.CallbackRsp callbackRsp = new AbcpInvoke.CallbackRsp() { AbcpInvoke.CallbackRsp callbackRsp = new AbcpInvoke.CallbackRsp() {
@Override @Override
public void OnProcess(int code, String subCode, String subMsg, String result) { public void OnProcess(int code, String subCode, String subMsg, String result) {
log.info("[AliScanFaceServiceImpl][OnProcess][123][ABCP调用iniAbcpAbsolute][code:{}][subCode:{}][subMsg:{}][result:{}]", code, subCode, subMsg, result); log.info("[AliScanFaceServiceImpl][OnProcess][155][0、ABCP调用iniAbcpAbsolute-OnProcess][code:{}][subCode:{}][subMsg:{}][result:{}] ", code, subCode, subMsg, result);
try {
processCode.set(code);
processResult.set(result);
} finally {
latch.countDown(); // 确保无论如何都释放锁
}
} }
@Override @Override
public void OnFinish(int code, String subCode, String subMsg, String result) { public void OnFinish(int code, String subCode, String subMsg, String result) {
log.info("[AliScanFaceServiceImpl][OnFinish][128][ABCP调用iniAbcpAbsolute][code:{}][subCode:{}][subMsg:{}][result:{}]", code, subCode, subMsg, result); log.info("[AliScanFaceServiceImpl][OnFinish][167][0、ABCP调用iniAbcpAbsolute-OnFinish][code:{}][subCode:{}][subMsg:{}][result:{}]", code, subCode, subMsg, result);
try {
finishCode.set(code);
finishResult.set(result);
} finally {
latchFinish.countDown(); // 确保无论如何都释放锁
}
} }
}; };
//初始化 //初始化
log.info("[AliScanFaceServiceImpl][iniAbcpAbsolute][175][0、ABCP调用iniAbcpAbsolute初始化参数][appId:{}][appVersion:{}][json:{}] ", aliFaceConfig.getAppId(), aliFaceConfig.getAppVersion(), json);
AbcpInvoke.AbcpInit(aliFaceConfig.getAppId(), aliFaceConfig.getAppVersion(), json, callbackRsp); AbcpInvoke.AbcpInit(aliFaceConfig.getAppId(), aliFaceConfig.getAppVersion(), json, callbackRsp);
return Result.ok("支付宝ABCP初始化成功"); // 等待finish回调完成设置超时避免死锁
boolean awaitFinishSuccess = latchFinish.await(120, TimeUnit.SECONDS);
if (!awaitFinishSuccess) {
log.info("[AliScanFaceServiceImpl][iniAbcpAbsolute][181] [0、ABCP调用iniAbcpAbsolute初始化-120秒-等待finish回调超时]");
return Result.error("初始化等待finish回调超时");
} else {
JSONObject jsonObject = JSONObject.parseObject(finishResult.get());
log.info("[AliScanFaceServiceImpl][iniAbcpAbsolute][184][0、ABCP调用iniAbcpAbsolute初始化-finish回调结果-finishCode {}] [返回结果:{}]", finishCode, jsonObject.toString());
if (finishCode.get() == 1000) {
return Result.ok("ABCP调用iniAbcpAbsolute初始化成功");
} else {
return Result.error("ABCP调用刷脸初始化服务finish失败");
}
}
} else { } else {
log.info("[AliScanFaceServiceImpl][iniAbcpAbsolute][55][{} :文件不存在]", aliFaceConfig.getDllPath()); log.info("[AliScanFaceServiceImpl][iniAbcpAbsolute][55][{} :文件不存在]", aliFaceConfig.getDllPath());
return Result.error("支付宝ABCP初始化失败" + aliFaceConfig.getDllPath() + "不存在"); return Result.error("支付宝ABCP初始化失败" + aliFaceConfig.getDllPath() + "不存在");