Commit 20b26012 authored by 宋永孟's avatar 宋永孟

add 完成活体检测的业务逻辑

parent 9815d536
......@@ -24,7 +24,9 @@ import com.yidian.xarc.xevent.XBaseEvent
import com.yidian.xpage.XPageManager
import com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import org.json.JSONObject
import java.io.*
import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.util.*
......@@ -53,9 +55,9 @@ object ToolsUtil {
//单位转换
fun dp2px(context: Context, dpVal: Float): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dpVal,
context.resources.displayMetrics
TypedValue.COMPLEX_UNIT_DIP,
dpVal,
context.resources.displayMetrics
).toInt()
}
......@@ -205,4 +207,10 @@ object ToolsUtil {
return false
}
fun randomName(): String {
val randomNum = (Math.random() * 1000).toInt()
return "lifeCircle$randomNum"
}
}
\ No newline at end of file
package com.yidian.shenghuoquan.newscontent.http.httpbean
class IdentifyIdOcrVerifyBean(var request: Request, val response: Response) {
data class Request(var biz_token: String, var meglive_data: String)
data class Request(var biz_token: String, var meglive_objectid: String)
data class Response(val biz_token: String)
......
......@@ -9,12 +9,14 @@ import com.megvii.meglive_sdk.manager.MegLiveManager
import com.yidian.common.AppConfig
import com.yidian.common.base.BaseActivity
import com.yidian.common.http.HttpResult
import com.yidian.common.utils.ToolsUtil
import com.yidian.shenghuoquan.newscontent.databinding.ActivityAliveLayoutBinding
import com.yidian.shenghuoquan.newscontent.http.ApiService
import com.yidian.shenghuoquan.newscontent.http.httpbean.AuthPersonalGetTokenBean
import com.yidian.shenghuoquan.newscontent.http.httpbean.AuthPersonalGetTokenCallback
import com.yidian.shenghuoquan.newscontent.http.httpbean.IdentifyIdOcrVerifyBean
import com.yidian.shenghuoquan.newscontent.http.httpbean.IdentifyIdOcrVerifyCallback
import com.yidian.shenghuoquan.newscontent.utils.KS3Core
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
......@@ -29,6 +31,7 @@ class AliveTestActivity : BaseActivity<ActivityAliveLayoutBinding>(), PreCallbac
private var bizToken = ""
private var megLiveManager: MegLiveManager? = null
private var modelPath = "" // 模型本地存放路径
private var dataPath = "" // 模型本地存放路径
private var mProgressDialog: ProgressDialog? = null
private val VERIFY_URL = "https://api.megvii.com/faceid/v3/sdk/verify"
......@@ -136,19 +139,60 @@ class AliveTestActivity : BaseActivity<ActivityAliveLayoutBinding>(), PreCallbac
override fun onDetectFinish(token: String?, errorCode: Int, errorMessage: String?, data: String?) {
if (errorCode == 1000) {
token?.let { verify(it, data!!.toByteArray()) }
val requestParams: IdentifyIdOcrVerifyBean.Request = IdentifyIdOcrVerifyBean.Request(bizToken, data!!)
ApiService.identifyIdOcrVerify(identifyIdOcrVerifyCallback, requestParams)
}
}
private fun verify(token: String, data: ByteArray) {
showDialogDismiss()
saveFile(ToolsUtil.randomName(), data)
}
private val identifyIdOcrVerifyCallback = object : IdentifyIdOcrVerifyCallback {
override fun identifyIdOcrVerifySuccess(t: HttpResult<Any?>?) {
//人脸验证成功
progressDialogDismiss()
}
}
// 将字节流转换成文件
@Throws(Exception::class)
fun saveFile(filename: String, data: ByteArray?) {
if (data != null) {
val sdcardPath = System.getenv("EXTERNAL_STORAGE")
dataPath = "$sdcardPath/life_circle_business/meglive"
val file = File(dataPath)
if (file.exists()) {
file.delete()
}
val fos = FileOutputStream(file)
fos.write(data, 0, data.size)
fos.flush()
fos.close()
KS3Core.INSTANCE.uploadObject(file, object : KS3Core.OnKS3TaskListener {
override fun onTaskStart() {
}
override fun onTaskProgress(progress: Double) {
}
override fun onTaskFinish() {
}
override fun onTaskCancel() {
}
override fun onTaskSuccess(bucket: String?, objectKey: String?) {
val requestParams: IdentifyIdOcrVerifyBean.Request = IdentifyIdOcrVerifyBean.Request(bizToken, objectKey!!)
ApiService.identifyIdOcrVerify(identifyIdOcrVerifyCallback, requestParams)
}
override fun onTaskFailure(statesCode: Int, message: String?) {
}
})
}
}
......
......@@ -37,12 +37,8 @@ class IDCardResultActivity:BaseActivity<ActivityIdcardResultBinding>() {
if (iDCardImg != null) {
val bmpIDCardImg = BitmapFactory.decodeByteArray(iDCardImg, 0, iDCardImg.size)
viewBind.resultIdcardImage.setImageBitmap(bmpIDCardImg)
ToolsUtil.saveImage(bmpIDCardImg, randomName() + ".jpg", this)
ToolsUtil.saveImage(bmpIDCardImg, ToolsUtil.randomName() + ".jpg", this)
}
}
private fun randomName(): String {
val randomNum = (Math.random() * 1000).toInt()
return "lifeCircle$randomNum"
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment