识别银行卡
index.wxml
<button bindtap="yinhangka">识别银行卡</button>
<text>识别的银行卡号:{{number}}</text>
index.js
Page({
yinhangka(){
let that=this
wx.cloud.callFunction({
name:"tupianshibie",
data:{
imgUUU:"https://6d79-myminiprogram-xdqs5-1302292245.tcb.qcloud.la/ocr/yinghangka1.jpg?sign=8421781fbe63ce33ca36ade3d5f1d936&t=1590994105"
},
success(res){
console.log("识别成功",res);
that.setData({
number:res.result.errMsg
})
},
fail(err){
console.log("识别失败",err);
}
})
}
})
云函数js
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.ocr.bankcard({
type: 'photo',
imgUrl: event.imgUUU
})
console.log(result);
return result
} catch (err) {
return err
}
}
识别身份证
shibie.wxml
<button bindtap="shengfenzhen">识别身份证</button>
shibie.js
- 上传图片到云存储保存,然后使用云数据库存储,之后进行调用
Page({
shengfenzhen() {
let that = this
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
const tempFilePaths = res.tempFilePaths
console.log("临时链接", tempFilePaths);
that.uploadFile(tempFilePaths[0])
}
})
},
uploadFile(tempFile) {
let that = this
wx.cloud.uploadFile({
cloudPath: 'ocr/shengfenzheng03.png',
filePath: tempFile,
success: res => {
console.log("上传图片成功", res.fileID)
that.getImgUrl(res.fileID)
},
fail: err => {
console.log("上传图片失败", err);
}
})
},
getImgUrl(fileid) {
let that=this
wx.cloud.getTempFileURL({
fileList: [fileid],
success: res => {
console.log("获取图片url成功",res.fileList)
let tempUrl=res.fileList[0].tempFileURL
console.log("获取图片url成功",tempUrl)
that.shibie(tempUrl)
},
fail: err => {
console.log("获取图片url失败",err)
}
})
},
shibie(tempurl){
let that=this
wx.cloud.callFunction({
name:"shengfengzheng",
data:{
imgQQ:tempurl
},
success(res){
console.log("识别成功",res)
},
fail(err){
console.log("识别失败",err);
}
})
}
})
云函数js
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.ocr.idcard({
type: 'photo',
imgUrl: event.imgQQ
})
console.log(result);
return result
} catch (err) {
return err
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律