更新记录

1.0.0(2024-01-03)

新版发布


平台兼容性

Android Android CPU类型 iOS
适用版本区间:5.0 - 14.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 适用版本区间:11 - 17

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


特别提醒

  • 购买本插件前,请先试用,请先试用,请先试用,自测确认满足需求之后再行购买。虚拟物品一旦购买之后无法退款。
  • 如有使用上的疑问、bug,可以QQ(381996687)联系作者;
  • 作者可承接各种插件定制,价格美丽有意向可加q详谈;
  • 请在合法范围内使用,若使用本插件做非法开发,本方概不负责;
  • 若是通过HBuilderX导入的示例项目,需前往manifest->基础设置->应用名称,修改项目名称不然会因为名称过长iOS端无法启动。
  • 示例demo打包若提示:云端服务器返回错误:请先完成企业实名认证,证明您是“百度OCR识别插件,支持识别身份证、银行卡、驾驶证、行驶证、票据、车牌、发票等”的开发者,如有疑问,请发邮件到service@dcloud.io咨询。可前往manifest.json修改应用名称重新打包即可。(云打包应用名称若包含身份证等敏感词会有这个提示)

推荐

  1. 结合百度人脸识别,人脸采集插件,可以轻松实现实名认证身份核验,插件地址:https://ext.dcloud.net.cn/plugin?id=16043

准备工作

  • 百度文字识别创建应用,教程:https://ai.baidu.com/ai-doc/OCR/dk3iqnq51 创建应用根据项目需求选择需要识别的类型。 getLicense

  • 配置包名与Bundle ID(Android还需签名MD5) 配置包名

  • 获取AK、SK与License文件(复制AK、SK,下载License后面需要用到)

License

插件使用文档

1.创建文件夹

在项目根目录下创建nativeplugins文件夹购买或试用插件将下载的授权文件License 放入Android:nativeplugins/YT-BDOcr/android/assets/aip.license(Android授权文件下载下来名称是”aip-ocr.license“记得改成”aip.license“再放入文件夹),iOS:nativeplugins/YT-BDOcr/ios/aip.license,文件夹和License名称必须和这里的一致。(没有对应的文件夹自行创建)参照示例demo中nativeplugins/YT-BDOcr将授权文件换成自己的即可

2.选择插件打包(打自定义基座或云打包)

购买或试用该插件然后选中购买该插件项目的manifest.json 文件,选择App原生插件配置,选中云端插件,勾选插件对应的插件,配置相应的权限(见最下面”隐私、权限声明“)

3.引入插件

const bdOcr = uni.requireNativePlugin('YT-BDOcr');

4.身份验证

  • 通过API Key / Secret Key验证,虽然SDK对网络传输的敏感数据进行了二次加密,但由于AK/SK是明文填写在代码中,在移动设备中可能会存在AK/SK被盗取的风险。有安全考虑的开发者可使用第二种授权方案。(使用这个方式验证可省略上面步骤1.创建文件夹导入License)
bdOcr.initAccessTokenWithAkSk({
    AK:"申请的Api Key",
    SK:"申请的Secret Key"
},res=>{
//iOS没有验证结果的回调
    if (res.status == 'success') {
        uni.showToast({
            title: '鉴权成功:'+res.msg,
            icon: 'none',
            duration: 2000
        })
    } else {
        uni.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
        })
    }           
});
  • 通过授权文件(安全模式)验证,使用该种方式验证需严格按照步骤1创建相应文件夹导入License文件
// 通过license文件验证身份(安全模式,推荐使用)
bdOcr.initAccessTokenLicenseFile(res => {
    // iOS没有验证结果回调
    if (res.status == 'success') {
        uni.showToast({
            title: '鉴权成功:'+res.msg,
            icon: 'none',
            duration: 2000
        })
    } else {
        uni.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
        })
    }
});

5.识别

let time = new Date().getTime();
var name = time + ".jpg"
bdOcr.scanningRecognition({
    ocrType:"textBasic",
    language_type:"CHN_ENG",
    resultImage: true,
    imageName: name
}, res => {
    // 图片路径 --- 使用完记得删除路径下图片
    this.photo = res.imagePath;
    // 识别结果
    this.result = res.reslutInfo
});

6.清除指定路径下图片

clearPath() {
    if (this.photo.length == 0 || this.photo == null) {
        return;
    }
    bdOcr.clearPath(this.photo, res => {
        uni.showToast({
            title: res.result ? "删除成功" : "删除失败",
            icon: 'none',
            duration: 1500
        })
    })
},
  • 参数说明
参数 值类型 是否必传 说明
ocrType String true 识别类型,详情见下表
language_type String false 识别语言类型,详情见下表
resultImage bool false 返回识别图片,默认false不返回
imageName String true 图片名称,用于返回图片路径用
  • ocrType识别类型
参数 说明
idCardFront 身份证正面
idCardBack 身份证反面
localIdCardFront 身份证正面扫描(自动识别)
localIdCardBack 身份证反面扫描(自动识别)
textBasic 通用文字识别
bankCard 银行卡
text 通用文字识别含位置信息
textAccurateBasic 通用文字识别 高精度
textAccurate 通用文字识别 高精度 含位置信息
textEnhanced 通用文字识别 含生僻字
webImage 网络图片文字识别
drivingLicense 驾驶证
vehicleLicense 行驶证
plateNumber 车牌
businessLicense 营业执照
receipt 通用票据
valueAddedTax 增值税发票
taxiReceipt 出租车票
vinCode VIN码
trainTicket 火车票
numbers 数字识别
qrCode 二维码
household 户口
passport 护照
writtenText 手写文字
exampleDoc 试卷分析
weightNote 磅单
taxiItinerary 网约车行程单
medicalDetail 医疗费用
vehicleInvoice 机动车销售发票
invoice 通用机打发票
businessCard 名片(仅Android有效)
vehicleCertificate 车辆合格证(仅iOS有效)
  • language_type识别语言类型
参数 说明
CHN_ENG 中英文混合(默认)
ENG 英文
POR 葡萄牙
FRE 法语
GER 德语
ITA 意大利语
SPA 西班牙语
RUS 俄语
JAP 日语

示例代码

<template>
    <!-- iOS打包时前往manifest->基础设置->应用名称。修改名称不然会因为名称过长无法运行 -->
    <scroll-view scroll-y style="width: 750rpx;">
        <view class="content">
            <button class="btn" @click="touchAction('textBasic')">通用文字识别(基础版、不含位置信息)</button>
            <button class="btn" @click="touchAction('text')">通用文字识别(含位置信息)</button>
            <button class="btn" @click="touchAction('textAccurateBasic')">通用文字识别(高精度、不含位置信息)</button>
            <button class="btn" @click="touchAction('textAccurate')">通用文字识别(高精度、含位置信息)</button>
            <button class="btn" @click="touchAction('textEnhanced')">通用文字识别 (含生僻字)</button>

            <button class="btn" @click="touchAction('webImage')">网图识别</button>
            <button class="btn" @click="touchAction('idCardFront')">身份证正面识别</button>
            <button class="btn" @click="touchAction('localIdCardFront')">身份证正面扫描,自动识别</button>
            <button class="btn" @click="touchAction('idCardBack')">身份证背面识别</button>
            <button class="btn" @click="touchAction('localIdCardBack')">身份证背面,自动识别</button>
            <button class="btn" @click="touchAction('bankCard')">银行卡</button>

            <button class="btn" @click="touchAction('drivingLicense')">驾驶证</button>
            <button class="btn" @click="touchAction('vehicleLicense')">行驶证</button>
            <button class="btn" @click="touchAction('plateNumber')">车牌识别</button>
            <button class="btn" @click="touchAction('businessLicense')">营业执照</button>

            <button class="btn" @click="touchAction('receipt')">通用票据</button>
            <button class="btn" @click="touchAction('valueAddedTax')">增值税</button>
            <button class="btn" @click="touchAction('taxiReceipt')">出租车票</button>
            <button class="btn" @click="touchAction('vinCode')">VIN码识别</button>
            <button class="btn" @click="touchAction('trainTicket')">火车票识别</button>
            <button class="btn" @click="touchAction('numbers')">数字识别</button>
            <button class="btn" @click="touchAction('qrCode')">二维码识别</button>

            <button class="btn" @click="touchAction('household')">户口本</button>
            <button class="btn" @click="touchAction('passport')">护照</button>
            <button class="btn" @click="touchAction('writtenText')">手写文字</button>
            <button class="btn" @click="touchAction('exampleDoc')">试卷分析</button>
            <button class="btn" @click="touchAction('weightNote')">/磅单识别</button>

            <button class="btn" @click="touchAction('taxiItinerary')">网约车行程单识别</button>
            <button class="btn" @click="touchAction('medicalDetail')">医疗费用明细</button>
            <button class="btn" @click="touchAction('vehicleInvoice')">机动车销售发票</button>
            <button class="btn" @click="touchAction('invoice')">机打发票</button>
            <button class="btn" @click="touchAction('vehicleCertificate')">车辆合格证</button>

        </view>
    </scroll-view>

</template>

<script>
    const bdOcr = uni.requireNativePlugin('YT-BDOcr');
    export default {
        data() {
            return {
                photo: "",
                result: ''
            }
        },
        onLoad() {
            // 通过AK,SK验证身份 initAccessTokenWithAkSk方法仅供测试使用,上线请使用initAccessToken方法
            // bdOcr.initAccessTokenWithAkSk({
            //  AK:"***",
            //  SK:"***"
            // },res=>{

            // });
            // 通过license文件验证身份(安全模式,推荐使用)
            bdOcr.initAccessTokenLicenseFile(res => {
                // iOS没有验证结果回调
                if (res.status == 'success') {
                    uni.showToast({
                        title: '鉴权成功:' + res.msg,
                        icon: 'none',
                        duration: 2000
                    })
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: 'none',
                        duration: 2000
                    })
                }
            });
        },
        methods: {
            touchAction(type) {
                console.log(type)
                let time = new Date().getTime();
                var name = time + ".jpg"
                bdOcr.scanningRecognition({
                    ocrType: type,
                    imageName:name,
                    resultImage: true
                }, res => {
                    // 识别图片 resultImage=true有效
                    this.photo = res.imagePath;
                    // 识别结果
                    this.result = res.reslutInfo
                    uni.navigateTo({
                        url:`./showBdOcrResult?path=${this.photo}&result=${this.result}`
                    })
                });
            }
        }
    }
</script>

<style>
    .content {
        align-items: center;
        width: 750rpx;
        display: flex;
        flex-direction: column;
        display: flex;
    }

    .btn {
        margin-top: 10rpx;
        background-color: coral;
        width: 690rpx;
        height: 88rpx;
    }
</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

Android: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> iOS: iOS:NSCameraUsageDescription NSPhotoLibraryUsageDescription

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件自身不采集任何数据,插件使用的百度文字识别SDK采集数据,请参考其官方说明:https://ai.baidu.com/ai-doc/OCR/ck3h7xws3

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问