'use strict' ; 
module.exports =  { // __before调用其他方法前会先调用这个方法_before( context)  { // 创建实人认证实例this.frvManager =  uniCloud.getFacialRecognitionVerifyManager( { requestId: this.getUniCloudRequestId( ) } ) } ,async getCertifyId( {  realName, idCard, metaInfo } )  { // 会先调用_beforetry { const result =  await this.frvManager.getCertifyId( {  realName, idCard, metaInfo } ) ; return  result}  catch ( e)  { throw {  errCode: 500 , message: '获取认证失败,请检查信息的正确性'  } ; } } ,// 获取认证的结果async getAuthResult( certifyId)  { try { const result =  await this.frvManager.getAuthResult( {  certifyId } ) ; return  result}  catch ( e)  { throw {  errCode: 500 , message: '认证失败'  } ; } } 
} 
// 注册实人认证
// veify为云函数文件名const uniCloudVerify =  uniCloud.importObject( 'veify' ) ; 
//点击认证
submit ( ) { let  data =  { realName:this.params.realName,idCard:this.params.idNumber} this.uniCloudVerifyFunction( data) .then( res = >  { console.log( '实名认证yes' ,res) ; if( res.authState ==  'SUCCESS' ) { //成功} // 提示成功} ) .catch( err = >  { console.log( '实名认证no' ,err) ; // 提示失败} ) 
} ,
//封装
async uniCloudVerifyFunction( {  realName, idCard } )  { // 获取设备信息const metaInfo =  uni.getFacialRecognitionMetaInfo( ) ; // 获取CertifyIdconst certifyidResult =  await uniCloudVerify.getCertifyId( {  realName, idCard, metaInfo } )  if  ( certifyidResult.errCode !=  0 )  return  Promise.reject( {  code: 500 , msg: '获取certifyid失败,请联系管理员处理!'  } ) const certifyId =  certifyidResult.certifyId; // 开始认证return  new Promise(( resolve, reject)  = >  { uni.startFacialRecognitionVerify( { certifyId: certifyId,success: async res = >  { console.log( res) ; const result =  await uniCloudVerify.getAuthResult( certifyId) ; resolve( result) ; } ,fail: err = >  { reject( {  code: err.errCode, msg: err.errMsg } ) } } ) ; } ) 
} 
< template> < view> < view class = "navBbutPart"  > < button class = "butsty font30"  hover-class= "butstyHover"  @click= "$u .throttle(submit, 1000)" >  人脸验证 < /button> < /view> < /view> 
< /template> < script> import  {  accountAuthenticationedit,accountAuthenticationadd }  from "@/api/all.js" // 注册实人认证const uniCloudVerify =  uniCloud.importObject( 'getFaceRecognition' ) ; export  default { name:"getBack" ,props:{ params:{ } ,//是否修改edit:{ default:false} } ,data ( )  { return  { } ; } ,onLoad ( )  { // console.log( uni.getFacialRecognitionMetaInfo( )) ; } ,methods:{ async uniCloudVerifyFunction( {  realName, idCard } )  { // 获取设备信息const metaInfo =  uni.getFacialRecognitionMetaInfo( ) ; // 获取CertifyIdconst certifyidResult =  await uniCloudVerify.getCertifyId( {  realName, idCard, metaInfo } )  if  ( certifyidResult.errCode !=  0 )  return  Promise.reject( {  code: 500 , msg: '获取certifyid失败,请联系管理员处理!'  } ) const certifyId =  certifyidResult.certifyId; // 开始认证return  new Promise(( resolve, reject)  = >  { uni.startFacialRecognitionVerify( { certifyId: certifyId,success: async res = >  { console.log( res) ; const result =  await uniCloudVerify.getAuthResult( certifyId) ; resolve( result) ; } ,fail: err = >  { reject( {  code: err.errCode, msg: err.errMsg } ) } } ) ; } ) } ,submit ( ) { let  data =  { realName:this.params.realName,idCard:this.params.idNumber} this.uniCloudVerifyFunction( data) .then( res = >  { console.log( '实名认证yes' ,res) ; if( res.authState ==  'SUCCESS' ) { if( ! this.edit) { accountAuthenticationadd( this.params) .then( resapi= > { console.log( '实名认证接口' ,resapi) ; this.com.back( ) //返回} ) } else{ accountAuthenticationedit( this.params) .then( resapi= > { this.com.back( ) } ) } } // 提示成功} ) .catch( err = >  { console.log( '实名认证no' ,err) ; // 提示失败} ) } } } 
< /script> < style scoped lang = "scss" > 
.navBbutPart{ width: 90 %; position: fixed; bottom: 200rpx; padding: 0  5 %; button{ border-radius: 50rpx; } } 
< /style>