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) }, }) } })