第一步 需要先添加插件
购买页面
https://developers.weixin.qq.com/community/servicemarket/detail/000ce4cec24ca026d37900ed551415
可以选择免费的 收费的自己选择吧
然后需要在自己的小程序上面设置
1打开设置
2第三方设置
3添加插件 搜索ocr 或者 wx4418e3e031e551be
这个步骤完成之后 就是在页面写代码了
首先在app.json 中添加 这个就是插件的意思 版本可以选择最新版本的 但是我没找到版本号
"plugins": {
"ocr-plugin": {
"version": "3.0.2",
"provider": "wx4418e3e031e551be"
}
},
然后在当前页面的json文件中添加下边的 代码
"usingComponents": {
"ocr-navigator": "plugin://ocr-plugin/ocr-navigator"
},
wxml 页面代码 调用识别的函数 载体为button
<ocr-navigator bind:onSuccess="success" certificateType="idCard" opposite="{{false}}">
<button type="primary">身份证正面识别</button>
</ocr-navigator>
<ocr-navigator bind:onSuccess="success" certificateType="idCard" opposite="{{true}}">
<button type="primary">身份证反面识别</button>
</ocr-navigator>
js 页面的代码
success: function (e) {
console.log(e)
}
直接就可以输出身份证 识别后的信息