facial-recognition-verify.uvue 2.5 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2
<template>
  <!-- #ifdef APP -->
H
hdx 已提交
3
  <scroll-view class="page-scroll-view">
雪洛's avatar
雪洛 已提交
4 5 6 7 8
  <!-- #endif -->
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-padding-wrap uni-common-mt">
        <view class="uni-btn-v uni-common-mt">
A
Anne_LXM 已提交
9
          <input class="uni-input" type="text" v-model="realName" name="real-name"
10
            placeholder="姓名" maxlength="-1"/>
雪洛's avatar
雪洛 已提交
11 12
        </view>
        <view class="uni-btn-v uni-common-mt">
A
Anne_LXM 已提交
13
          <input class="uni-input" type="text" v-model="idCard" name="id-card"
14
            placeholder="身份证号" maxlength="-1"/>
雪洛's avatar
雪洛 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
        </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() {
    },
    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')
50
        let metaInfo = uni.getFacialRecognitionMetaInfo();
雪洛's avatar
雪洛 已提交
51 52 53 54 55
        testFacialCo.getCertifyId({
          realName,
          idCard,
          metaInfo
        })
56
          .then((res : UTSJSONObject) : Promise<string> => {
雪洛's avatar
雪洛 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
            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))
                }
              })
            })
          })
73
          .then((certifyId : string) : Promise<UTSJSONObject> => {
雪洛's avatar
雪洛 已提交
74 75
            return testFacialCo.getAuthResult(certifyId)
          })
76
          .then((res : UTSJSONObject) => {
雪洛's avatar
雪洛 已提交
77 78
            console.log('res', res)
          })
79
          .catch((err : any | null) => {
雪洛's avatar
雪洛 已提交
80 81 82 83 84 85 86 87 88
            console.error('error', err)
          })
      }
    }
  }
</script>

<style>
</style>