|
|
@@ -136,50 +136,207 @@ class FaceMatchingFragment : RcBaseFragment<FragmentFaceMatchingBinding>(),
|
|
|
callback.invoke(true)
|
|
|
|
|
|
// 调用人脸比对方法
|
|
|
- callFaceMatchingApi(faceFeature.featureData, callback)
|
|
|
+ //callFaceMatchingApi(faceFeature.featureData, callback)
|
|
|
+ callFaceLoginApi(faceFeature.featureData, callback)
|
|
|
}
|
|
|
|
|
|
- private fun callFaceMatchingApi(
|
|
|
+// private fun callFaceMatchingApi(
|
|
|
+// featureData: ByteArray,
|
|
|
+// callback: (comparing: Boolean) -> Unit
|
|
|
+// ) {
|
|
|
+// showLoading("比对中....")
|
|
|
+//// val param = FaceCompareReq().apply {
|
|
|
+//// data = featureData
|
|
|
+////// userId = ExamApp.sLearnLoginVo!!.user_id
|
|
|
+//// userId = ExamApp.sLearnLoginVo!!.userId
|
|
|
+//// }
|
|
|
+//// RcLog.info("=====登录id ${param.userId}")
|
|
|
+////// val disposable = ApiRepository.faceCompare(param)
|
|
|
+//// val disposable = ApiRepository.compare(param)
|
|
|
+//// .subscribe({ success ->
|
|
|
+//// dismissLoading()
|
|
|
+//// RcLog.info("======SHIBAI $mType")
|
|
|
+////// callback.invoke(false)
|
|
|
+//// if (success) {
|
|
|
+//// dispatchMatchingSuccess()
|
|
|
+//// }
|
|
|
+////// var userInfo= LearnLoginVo()
|
|
|
+////// userInfo.user_id=success.userId
|
|
|
+////// userInfo.type=success.userType
|
|
|
+////// userInfo.username=success.cardNum
|
|
|
+////// userInfo.nickName=success.userName
|
|
|
+////// userInfo.user_id=success.userId
|
|
|
+////// ExamApp.sLearnLoginVo=userInfo
|
|
|
+////// ExamApp.sLearnLoginVo!!.nickName=success.userName
|
|
|
+////
|
|
|
+////
|
|
|
+//// }, { throwable ->
|
|
|
+//// RcLog.info("======SHIBATWO")
|
|
|
+//// dismissLoading()
|
|
|
+//// callback.invoke(false)
|
|
|
+//// showNetError(throwable)
|
|
|
+////
|
|
|
+////// if (!pretreatmentError(throwable)) {
|
|
|
+////// faceEngineHelper?.stopPreview(false)
|
|
|
+////// throwable.printStackTrace()
|
|
|
+////// showNetError(throwable)
|
|
|
+////// }
|
|
|
+//// })
|
|
|
+//// addDisposable(disposable)
|
|
|
+//
|
|
|
+// // 如果还没有登录信息,需要先通过人脸识别获取用户信息
|
|
|
+// var userId = ExamApp.sLearnLoginVo?.userId
|
|
|
+//
|
|
|
+// if (userId.isNullOrEmpty()) {
|
|
|
+// // 未登录状态,先调用识别接口获取用户信息
|
|
|
+// callFaceRecognizeApi(featureData, callback)
|
|
|
+// } else {
|
|
|
+// // 已登录状态,直接比对
|
|
|
+// val param = FaceCompareReq().apply {
|
|
|
+// data = featureData
|
|
|
+// userId = ExamApp.sLearnLoginVo!!.userId
|
|
|
+// }
|
|
|
+// RcLog.info("=====登录id ${param.userId}")
|
|
|
+// val disposable = ApiRepository.compare(param)
|
|
|
+// .subscribe({ success ->
|
|
|
+// dismissLoading()
|
|
|
+// RcLog.info("======SHIBAI $mType")
|
|
|
+// if (success) {
|
|
|
+// dispatchMatchingSuccess()
|
|
|
+// }
|
|
|
+// }, { throwable ->
|
|
|
+// RcLog.info("======SHIBATWO")
|
|
|
+// dismissLoading()
|
|
|
+// callback.invoke(false)
|
|
|
+// showNetError(throwable)
|
|
|
+// })
|
|
|
+// addDisposable(disposable)
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ private fun callFaceLoginApi(
|
|
|
+ featureData: ByteArray,
|
|
|
+ callback: (comparing: Boolean) -> Unit
|
|
|
+ ) {
|
|
|
+ showLoading("识别中...")
|
|
|
+
|
|
|
+ // 构建请求参数(和 compare 接口参数一样)
|
|
|
+ val param = FaceCompareReq().apply {
|
|
|
+ data = featureData
|
|
|
+ userId = "" // 空表示识别模式
|
|
|
+ }
|
|
|
+
|
|
|
+ RcLog.info("=====调用人脸识别登录接口")
|
|
|
+
|
|
|
+ // 调用 faceByPic 接口,直接完成登录
|
|
|
+ val disposable = ApiRepository.faceByPic(param)
|
|
|
+ .subscribe({ data ->
|
|
|
+ dismissLoading()
|
|
|
+ RcLog.info("======人脸识别登录成功")
|
|
|
+
|
|
|
+ // ✅ 保存用户信息(和刷卡登录一样)
|
|
|
+ ExamApp.sLearnLoginVo = data
|
|
|
+
|
|
|
+ // ✅ Token 已经在 ExamRetrofit.faceByPic 中设置了
|
|
|
+ RcLog.info("=====Token: ${HttpClient.token}")
|
|
|
+ RcLog.info("=====用户ID: ${data.userId}")
|
|
|
+ RcLog.info("=====用户名: ${data.userName}")
|
|
|
+
|
|
|
+ // 登录成功,根据类型处理
|
|
|
+ dispatchMatchingSuccess()
|
|
|
+
|
|
|
+ }, { throwable ->
|
|
|
+ dismissLoading()
|
|
|
+ RcLog.info("======人脸识别登录失败")
|
|
|
+ callback.invoke(false)
|
|
|
+
|
|
|
+ // 错误处理
|
|
|
+ if (throwable is NetException) {
|
|
|
+ when (throwable.code) {
|
|
|
+ "500" -> {
|
|
|
+ // 人脸不匹配
|
|
|
+ AlertDialog.Builder(requireContext())
|
|
|
+ .setCancelable(false)
|
|
|
+ .setTitle("提示")
|
|
|
+ .setMessage(throwable.message ?: "人脸识别失败")
|
|
|
+ .setPositiveButton("确定") { _, _ ->
|
|
|
+ faceEngineHelper?.stopPreview(false)
|
|
|
+ }.show()
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ showNetError(throwable)
|
|
|
+ faceEngineHelper?.stopPreview(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throwable.printStackTrace()
|
|
|
+ showNetError(throwable)
|
|
|
+ faceEngineHelper?.stopPreview(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ addDisposable(disposable)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private fun callFaceRecognizeApi(
|
|
|
featureData: ByteArray,
|
|
|
callback: (comparing: Boolean) -> Unit
|
|
|
) {
|
|
|
- showLoading("比对中....")
|
|
|
+ // 调用后端人脸识别接口,返回用户信息
|
|
|
+ // 注意:这里需要根据你后端的实际接口来调整
|
|
|
val param = FaceCompareReq().apply {
|
|
|
data = featureData
|
|
|
-// userId = ExamApp.sLearnLoginVo!!.user_id
|
|
|
- userId = ExamApp.sLearnLoginVo!!.userId
|
|
|
+ userId = "" // 空userId表示识别模式
|
|
|
}
|
|
|
- RcLog.info("=====登录id ${param.userId}")
|
|
|
-// val disposable = ApiRepository.faceCompare(param)
|
|
|
+
|
|
|
val disposable = ApiRepository.compare(param)
|
|
|
.subscribe({ success ->
|
|
|
dismissLoading()
|
|
|
- RcLog.info("======SHIBAI $mType")
|
|
|
-// callback.invoke(false)
|
|
|
if (success) {
|
|
|
- dispatchMatchingSuccess()
|
|
|
+ // 识别成功,获取用户信息后登录
|
|
|
+ // 这里假设后端会在success中返回用户信息
|
|
|
+ // 如果后端接口不同,需要相应调整
|
|
|
+ requireArguments().getString("username")?.let { username ->
|
|
|
+ callLearnLoginApi(username, true) {
|
|
|
+ dispatchMatchingSuccess()
|
|
|
+ }
|
|
|
+ } ?: run {
|
|
|
+ // 如果没有username参数,需要从响应中获取
|
|
|
+ showNetError(Exception("无法获取用户信息"))
|
|
|
+ }
|
|
|
}
|
|
|
-// var userInfo= LearnLoginVo()
|
|
|
-// userInfo.user_id=success.userId
|
|
|
-// userInfo.type=success.userType
|
|
|
-// userInfo.username=success.cardNum
|
|
|
-// userInfo.nickName=success.userName
|
|
|
-// userInfo.user_id=success.userId
|
|
|
-// ExamApp.sLearnLoginVo=userInfo
|
|
|
-// ExamApp.sLearnLoginVo!!.nickName=success.userName
|
|
|
-
|
|
|
-
|
|
|
}, { throwable ->
|
|
|
- RcLog.info("======SHIBATWO")
|
|
|
dismissLoading()
|
|
|
callback.invoke(false)
|
|
|
showNetError(throwable)
|
|
|
+ })
|
|
|
+ addDisposable(disposable)
|
|
|
+ }
|
|
|
|
|
|
-// if (!pretreatmentError(throwable)) {
|
|
|
-// faceEngineHelper?.stopPreview(false)
|
|
|
-// throwable.printStackTrace()
|
|
|
-// showNetError(throwable)
|
|
|
-// }
|
|
|
+ private fun callLearnLoginApi(username: String, realLogin: Boolean = false, callback: () -> Unit) {
|
|
|
+ if (username.isNullOrEmpty()) {
|
|
|
+ ExamApp.sLearnLoginVo = null
|
|
|
+ HttpClient.token = null
|
|
|
+
|
|
|
+ CommonUtils.restartApp(requireActivity())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ showLoading("查询中...")
|
|
|
+ val disposable = ApiRepository.learnLogin(
|
|
|
+ username,
|
|
|
+ CommonUtils.getAndroidId(requireContext()),
|
|
|
+ realLogin,
|
|
|
+ "1"
|
|
|
+ )
|
|
|
+ .subscribe({ data ->
|
|
|
+ dismissLoading()
|
|
|
+ ExamApp.sLearnLoginVo = data
|
|
|
+ callback.invoke()
|
|
|
+ }, { throwable ->
|
|
|
+ dismissLoading()
|
|
|
+ throwable.printStackTrace()
|
|
|
+ showNetError(throwable)
|
|
|
})
|
|
|
addDisposable(disposable)
|
|
|
}
|