1、申请权限
在小程序后台搜索本插件(AppID=wx4418e3e031e551be) 设置-第三方服务-添加插件
2、购买调用额度(可免费购买,免费的额度100次/天)必须购买不然调用识别不了
购买网址:https://fuwu.weixin.qq.com/buy/000ce4cec24ca026d37900ed551415
3、调用方式
(1)小程序app.json中添加代码申明
"plugins": {
"ocr-plugin": {
"version": "3.0.6",
"provider": "wx4418e3e031e551be"
}
},
(2)在具体调用的页面的json文件中引用
"usingComponents": {
"ocr-navigator": "plugin://ocr-plugin/ocr-navigator"
}
(3)页面示例代码
<!-- 身份证正面 -->
<ocr-navigator bind:onSuccess="success" certificateType="idCard" opposite="{{false}}">
<button type="primary">身份证正面识别</button>
</ocr-navigator>
<view>姓名:{{name}} </view>
<view>地址:{{address}} </view>
<view>身份证号:{{id}} </view>
<image wx:if="{{sfz_before}}" src="{{sfz_before}}" style="width: 65vw;height: 40vw;"></image>
<!-- 身份证反面 -->
<ocr-navigator bind:onSuccess="successFan" certificateType="idCard" opposite="{{true}}">
<button type="primary">身份证反面识别</button>
</ocr-navigator>
<view>签发机关:{{authority}} </view>
<view>有效期:{{valid_date}} </view>
<image wx:if="{{sfz_after}}" src="{{sfz_after}}" style="width: 65vw;height: 40vw;"></image>
(4)在js中回调函数
successFan:function(e) {
success:function(e) {
this.setData({name: e.detail.name.text , address: e.detail.address.text, id: e.detail.id.text , sfz_before: e.detail.image_path});
// let sfzjson = JSON.stringify(e);
// this.setData({sfz: sfzjson });
},
successFan:function(e) {
this.setData({valid_date: e.detail.valid_date.text , authority: e.detail.authority.text, sfz_after: e.detail.image_path});
let sfzjson = JSON.stringify(e);
this.setData({sfzFan: sfzjson });
},
官方文档查看:https://developers.weixin.qq.com/miniprogram/dev/extended/service/ocr.html