Page({ shibie2(){ //识别银行卡 var that=this wx.chooseImage({ //选择图片 count: 1, //上传数量 sizeType: [‘original‘, ‘compressed‘], sourceType: [‘album‘, ‘camera‘], success (res) { console.log(res) // tempFilePath可以作为img标签的src属性显示图片 const tempFilePaths = res.tempFilePaths that.upload(tempFilePaths[0]) } }) }, upload(tmpFile){ var that=this wx.cloud.uploadFile({ //上传图片 cloudPath: ‘example66688.png‘, filePath: tmpFile, // 文件路径 success: res => { console.log("上传成功",res.fileID) that.getUrl(res.fileID) }, fail: err => { console.log("上传失败",err) } }) }, getUrl(fileid){ var that=this wx.cloud.getTempFileURL({ fileList: [{ fileID: fileid, }] }).then(res => { console.log("获取URL成功",res.fileList[0].tempFileURL) var httpUrl=res.fileList[0].tempFileURL that.getID(httpUrl) }).catch(error => { console.log("获取url失败") }) }, getID(tmp){ var that=this wx.cloud.callFunction({ name:"card", data:{ imgCard:tmp }, success(res){ console.log("识别成功",res.result) //name id gender that.setData({ number:res.result.number, }) }, fail(res){ console.log("识别失败",res) }, }) }, shibie(){ //识别身份证 var that=this wx.chooseImage({ //选择图片 count: 1, //上传数量 sizeType: [‘original‘, ‘compressed‘], sourceType: [‘album‘, ‘camera‘], success (res) { console.log(res) // tempFilePath可以作为img标签的src属性显示图片 const tempFilePaths = res.tempFilePaths that.upload1(tempFilePaths[0]) } }) }, upload1(tmpFile){ var that=this wx.cloud.uploadFile({ //上传图片 cloudPath: ‘example.png‘, filePath: tmpFile, // 文件路径 success: res => { console.log("上传成功",res.fileID) that.getUr2(res.fileID) }, fail: err => { console.log("上传失败",err) } }) }, getUr2(fileid){ var that=this wx.cloud.getTempFileURL({ fileList: [{ fileID: fileid, }] }).then(res => { console.log("获取URL成功",res.fileList[0].tempFileURL) var httpUrl=res.fileList[0].tempFileURL that.getID(httpUrl) }).catch(error => { console.log("获取url失败") }) }, getID(tmp){ var that=this wx.cloud.callFunction({ name:"card1", data:{ imgCard:tmp }, success(res){ console.log("识别成功",res.result) //name id gender that.setData({ name:res.result.name, id:res.result.id, gender:res.result.gender }) }, fail(res){ console.log("识别失败",res) }, }) } })