facial-recognition-meta-info.uvue 2.5 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
<template>
  <!-- #ifdef APP -->
  <scroll-view class="page-scroll-view">
  <!-- #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" type="text" v-model="realName" name="real-name" placeholder="姓名" maxlength="-1" />
        </view>
        <view class="uni-btn-v uni-common-mt">
          <input class="uni-input" type="text" v-model="idCard" name="id-card" placeholder="身份证号" maxlength="-1" />
        </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')
        let metaInfo = uni.getFacialRecognitionMetaInfo();
        testFacialCo.getCertifyId({
          realName,
          idCard,
          metaInfo
        })
          .then((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((certifyId : string) : Promise<UTSJSONObject> => {
            return testFacialCo.getAuthResult(certifyId)
          })
          .then((res : UTSJSONObject) => {
            console.log('res', res)
          })
          .catch((err : any | null) => {
            console.error('error', err)
          })
      }
    }
  }
</script>

<style>
雪洛's avatar
雪洛 已提交
86
</style>