提交 d7d5df6b 编写于 作者: 雪洛's avatar 雪洛

feat: 增加实人认证示例页面

上级 5137b89d
......@@ -27,5 +27,10 @@
"uniStatistics" : {
"enable" : false
},
"app": {
"duts": [
"uni-facialRecognitionVerify"
]
},
"vueVersion" : "3"
}
......@@ -269,12 +269,12 @@
"navigationBarTitleText": "页面级下拉刷新",
"enablePullDownRefresh": true
}
},
{
"path": "pages/API/get-element-by-id/get-element-by-id",
"style": {
"navigationBarTitleText": "获取节点"
}
},
{
"path": "pages/API/get-element-by-id/get-element-by-id",
"style": {
"navigationBarTitleText": "获取节点"
}
},
{
"path": "pages/API/nodes-info/nodes-info",
......@@ -939,6 +939,13 @@
"style": {
"navigationBarTitleText": "自定义TabBar"
}
}, {
"path": "pages/API/facial-recognition-verify/facial-recognition-verify",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
......@@ -990,4 +997,4 @@
"query": "" //启动参数,在页面的onLoad函数里面得到
}]
}
}
}
\ No newline at end of file
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<input class="uni-input uni-input-default" type="text" v-model="realName" name="real-name" id="real-name" placeholder="姓名" />
</view>
<view class="uni-btn-v uni-common-mt">
<input class="uni-input uni-input-default" type="text" v-model="idCard" name="id-card" id="id-card" placeholder="身份证号" />
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="facialRecognition">开始人脸识别</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: '实人认证',
realName: '',
idCard: ''
}
},
onReady() {
uni.showModal({
title: '提示',
content: '注意:目前uni-app x内使用实人认证功能需要打包自定义基座。',
showCancel: false
})
},
methods: {
facialRecognition() {
const realName = this.realName.trim()
const idCard = this.idCard.trim()
if (realName == '' || idCard == '') {
uni.showModal({
title: '错误',
content: '姓名和身份证号不可为空',
showCancel: false
})
return
}
const testFacialCo = uniCloud.importObject('facial-recognition-co')
const metaInfo = uni.getFacialRecognitionMetaInfo();
testFacialCo.getCertifyId({
realName,
idCard,
metaInfo
})
.then<string>((res : UTSJSONObject) : Promise<string> => {
const certifyId = res['certifyId'] as string
return new Promise((
resolve : (res : string) => void,
reject : (err : Error) => void
) => {
uni.startFacialRecognitionVerify({
certifyId,
success() {
resolve(certifyId)
},
fail(err) {
reject(new Error(err.errMsg))
}
})
})
})
.then<UTSJSONObject>((certifyId : string) : Promise<UTSJSONObject> => {
return testFacialCo.getAuthResult(certifyId)
})
.then<void>((res : UTSJSONObject) => {
console.log('res', res)
})
.catch<void>((err : any | null) => {
console.error('error', err)
})
}
}
}
</script>
<style>
</style>
// 注意本文件为实人认证API示例代码,如需在业务中使用需补充业务逻辑,比如用户需要登录才能使用实人认证、限制每个用户每天能实人认证的次数等
module.exports = {
_before() {
this.frvManager = uniCloud.getFacialRecognitionVerifyManager({
requestId: this.getUniCloudRequestId()
})
},
async getCertifyId({
realName,
idCard,
metaInfo
} = {}) {
const result = await this.frvManager.getCertifyId({
realName,
idCard,
metaInfo
})
return result
},
async getAuthResult(certifyId) {
const result = await this.frvManager.getAuthResult({
certifyId
})
return result
}
}
\ No newline at end of file
{
"name": "facial-recognition-co",
"dependencies": {},
"extensions": {
"uni-cloud-verify": {}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册