facial-recognition-meta-info.uvue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view class="page-scroll-view">
  4. <!-- #endif -->
  5. <view>
  6. <page-head :title="title"></page-head>
  7. <view class="uni-padding-wrap uni-common-mt">
  8. <view class="uni-btn-v uni-common-mt">
  9. <input class="uni-input" type="text" v-model="realName" name="real-name" placeholder="姓名" maxlength="-1" />
  10. </view>
  11. <view class="uni-btn-v uni-common-mt">
  12. <input class="uni-input" type="text" v-model="idCard" name="id-card" placeholder="身份证号" maxlength="-1" />
  13. </view>
  14. <view class="uni-btn-v uni-common-mt">
  15. <button type="primary" @click="facialRecognition">开始人脸识别</button>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- #ifdef APP -->
  20. </scroll-view>
  21. <!-- #endif -->
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. title: '实人认证',
  28. realName: '',
  29. idCard: ''
  30. }
  31. },
  32. onReady() {
  33. },
  34. methods: {
  35. facialRecognition() {
  36. const realName = this.realName.trim()
  37. const idCard = this.idCard.trim()
  38. if (realName == '' || idCard == '') {
  39. uni.showModal({
  40. title: '错误',
  41. content: '姓名和身份证号不可为空',
  42. showCancel: false
  43. })
  44. return
  45. }
  46. if('production' === process.env.NODE_ENV && '__UNI__HelloUniAppX'===uni.getAppBaseInfo().appId){
  47. uni.showModal({
  48. title: '提示',
  49. content: '实人认证为收费功能,当前环境暂不支持。请在HBuilderX中新建Hello uni-app x项目真机运行体验!',
  50. showCancel: false
  51. })
  52. return
  53. }
  54. const testFacialCo = uniCloud.importObject('facial-recognition-co')
  55. let metaInfo = uni.getFacialRecognitionMetaInfo();
  56. testFacialCo.getCertifyId({
  57. realName,
  58. idCard,
  59. metaInfo
  60. })
  61. .then((res : UTSJSONObject) : Promise<string> => {
  62. const certifyId = res['certifyId'] as string
  63. return new Promise((
  64. resolve : (res : string) => void,
  65. reject : (err : Error) => void
  66. ) => {
  67. uni.startFacialRecognitionVerify({
  68. certifyId,
  69. success() {
  70. resolve(certifyId)
  71. },
  72. fail(err) {
  73. reject(new Error(err.errMsg))
  74. }
  75. })
  76. })
  77. })
  78. .then((certifyId : string) : Promise<UTSJSONObject> => {
  79. return testFacialCo.getAuthResult(certifyId)
  80. })
  81. .then((res : UTSJSONObject) => {
  82. console.log('res', res)
  83. })
  84. .catch((err : any | null) => {
  85. console.error('error', err)
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style>
  92. </style>