微信小程序 插件服務·OCR支持

2022-05-12 17:52 更新

OCR 支持

查看本文檔前,建議先閱讀《小程序插件文檔》 體驗工具小程序 —— 該插件完全使用此插件實現(xiàn)。該插件支持身份證識別,行駛證識別和銀行卡識別。 小程序碼 

申請權限

  • 請在小程序后臺搜索本插件(AppID=wx4418e3e031e551be) 設置-第三方服務-添加插件

調(diào)用限制

  • 來開放社區(qū)購買,appid內(nèi)的額度在插件、API、服務市場是通用的

調(diào)用方式

app.json中增加聲明引入插件 version選擇最新的

  "pages": [],
  "plugins": {
    "ocr-plugin": {
      "version": "3.0.2",
      "provider": "wx4418e3e031e551be"
    }
  }
}

頁面的json也要增加聲明

{
  "usingComponents": {
    "ocr-navigator": "plugin://ocr-plugin/ocr-navigator"
  }
}

組件

對外暴露自定義組件,UI載體為button(可樣式自定義) 封裝了

參數(shù)

屬性名類型默認值是否必填說明
onSuccessHandleEvent接口調(diào)用成功的回調(diào)函數(shù)
certificateTypeStringidCard證書類型包含四種 身份證:idCard、駕駛證:drivingLicense、銀行卡:bankCard、營業(yè)執(zhí)照:businessLicense

返回結果中image_path 是用戶證件照片的臨時地址,開發(fā)者可以通過image_path拿到用戶的證件照片

以下具體說明四種證件類型的使用方法

1、身份證

certificateType='idCard' 或 無certificateType這個參數(shù)

屬性名類型默認值是否必填說明
onSuccessHandleEvent接口調(diào)用成功的回調(diào)函數(shù)
certificateTypeStringidCard證書類型包含四種 身份證:idCard、駕駛證:drivingLicense、銀行卡:bankCard、營業(yè)執(zhí)照:businessLicense
oppositeBooleantrue是否顯示身份證的反面,默認為 true顯示反面

onSuccess

參數(shù) e.detail

參考身份證返回結果實例

示例代碼1

    <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>
/** wxss **/
/*自定義按鈕樣式*/
.ocr-wrapper {
  margin: 40rpx auto;
  width: 375rpx;
}
.intro {
  margin: 40rpx;
}

身份證返回結果實例

{"type":0,"name":{"text":"張三","pos":{"left_top":{"x":98.7780914307,"y":40.9823074341},"right_top":{"x":172.311325073,"y":41.2864379883},"right_bottom":{"x":172.190856934,"y":64.9047088623},"left_bottom":{"x":98.6072158813,"y":64.5630187988}},"label":[]},"gender":{"text":"男","pos":{"left_top":{"x":101.035919189,"y":80.7537384033},"right_top":{"x":121.421043396,"y":80.7818603516},"right_bottom":{"x":121.264938354,"y":101.272567749},"left_bottom":{"x":100.882026672,"y":101.244766235}},"label":[]},"nationality":{"text":"漢","pos":{"left_top":{"x":201.881393433,"y":81.7225189209},"right_top":{"x":222.004470825,"y":81.6959762573},"right_bottom":{"x":221.899169922,"y":101.255821228},"left_bottom":{"x":201.765304565,"y":101.291915894}},"label":[]},"address":{"text":"廣州市天河區(qū)五山路483號xxxxxxxxx","pos":{"left_top":{"x":95.5787811279,"y":150.794250488},"right_top":{"x":310.358947754,"y":151.617507935},"right_bottom":{"x":310.004699707,"y":220.222885132},"left_bottom":{"x":95.1295013428,"y":219.552230835}},"label":[]},"id":{"text":"4452xxxxxxxxxxxx","pos":{"left_top":{"x":176.158676147,"y":244.072860718},"right_top":{"x":453.888336182,"y":244.978515625},"right_bottom":{"x":453.874603271,"y":266.313659668},"left_bottom":{"x":176.066543579,"y":265.342407227}},"label":[]},"card_position":{"pos":{"left_top":{"x":1085.625,"y":621.75},"right_top":{"x":338.125,"y":594.75},"right_bottom":{"x":303.625,"y":99.75},"left_bottom":{"x":1189.125,"y":126.75}},"label":[]},"image_width":1280,"image_height":960,"image_path":"http://tmp/wx4418e3e031e551be.o6zAJs-yC5ByIjnyyy09jKDZquXk.dlrc7P7WlhnGb4aca86b078fc2acb5b08e7a0f438943.jpg"}

2、銀行卡

certificateType='bankCard'

屬性名類型默認值是否必填說明
onSuccessHandleEvent接口調(diào)用成功的回調(diào)函數(shù)
certificateTypeStringbankCard證書類型包含四種 身份證:idCard、駕駛證:drivingLicense、銀行卡:bankCard、營業(yè)執(zhí)照:businessLicense

onSuccess

參數(shù) e.detail

參考銀行卡返回結果實例

示例代碼1

<ocr-navigator bind:onSuccess="blankSuccess"  certificateType="bankCard">
  <button type="primary">銀行卡識別</button>
</ocr-navigator>
/** wxss **/
/*自定義按鈕樣式*/
.ocr-wrapper {
  margin: 40rpx auto;
  width: 375rpx;
}
.intro {
  margin: 40rpx;
}

銀行卡返回結果實例

{"number":{"text":"6225xxxxxxxxxxxx","label":[]},"card_position":{"pos":{"left_top":{"x":2.19140625,"y":227.6171875},"right_top":{"x":729.50390625,"y":206.0546875},"right_bottom":{"x":769.91015625,"y":658.8671875},"left_bottom":{"x":-11.27734375,"y":680.4296875}},"label":[]},"image_width":762,"image_height":1280,"image_path":"http://tmp/wx4418e3e031e551be.o6zAJs-yC5ByIjnyyy09jKDZquXk.dlrc7P7WlhnGb4aca86b078fc2acb5b08e7a0f438943.jpg"}

銀行卡返回結果

銀行卡只支持橫版儲蓄卡,信用卡,并且只能識別出銀行卡號,如果需要銀行卡名稱、過期時間需要用戶手動輸入

3、行駛證

certificateType='drivingLicense'

屬性名類型默認值是否必填說明
onSuccessHandleEvent接口調(diào)用成功的回調(diào)函數(shù)
certificateTypeStringdrivingLicense證書類型包含四種 身份證:idCard、駕駛證:drivingLicense、銀行卡:bankCard、營業(yè)執(zhí)照:businessLicense

onSuccess

參數(shù) e.detail

參考行駛證返回結果實例

示例代碼1

<ocr-navigator bind:onSuccess="driverSuccess" certificateType="drivingLicense" selectedOptions="{{['plateNum','vehicleType','owner']}}">
  <button type="primary">行駛證識別</button>
</ocr-navigator>
/** wxss **/
/*自定義按鈕樣式*/
.ocr-wrapper {
  margin: 40rpx auto;
  width: 375rpx;
}
.intro {
  margin: 40rpx;
}

行駛證返回結果實例

{"plate_num":{"text":"粵KDxxxx","label":[]},"vehicle_type":{"text":"小型轎車","label":[]},"owner":{"text":"周xx","label":[]},"addr":{"text":"廣東省xxxxxxxx","label":[]},"use_character":{"text":"非營運","label":[]},"model":{"text":"東風日產(chǎn)牌xxxxxx","label":[]},"vin":{"text":"LGBH52Exxxxxx","label":[]},"engine_num":{"text":"873073Y","label":[]},"register_date":{"text":"2017-11-13","label":[]},"issue_date":{"text":"2017-11-13","label":[]},"plate_num_b":{"text":"粵R82xxxx","label":[]},"record":{"text":"4418005xxxx","label":[]},"passengers_num":{"text":"26人","label":[]},"total_quality":{"text":"6900kg","label":[]},"prepare_quality":{"text":"4480kg","label":[]},"load_quality":{"text":"","label":[]},"lead_quality":{"text":"","label":[]},"overall_size":{"text":"7725x205xxxx","label":[]},"type":2,"card_position":[{"pos":{"left_top":{"x":454.0625,"y":17.34375},"right_top":{"x":987.8125,"y":11.71875},"right_bottom":{"x":987.8125,"y":562.96875},"left_bottom":{"x":471.5625,"y":546.09375}},"label":[]},{"pos":{"left_top":{"x":-0.9375,"y":28.59375},"right_top":{"x":445.3125,"y":22.96875},"right_bottom":{"x":445.3125,"y":551.71875},"left_bottom":{"x":-0.9375,"y":546.09375}},"label":[]}],"card_position_front":{"pos":{"left_top":{"x":454.0625,"y":17.34375},"right_top":{"x":987.8125,"y":11.71875},"right_bottom":{"x":987.8125,"y":562.96875},"left_bottom":{"x":471.5625,"y":546.09375}},"label":[]},"card_position_back":{"pos":{"left_top":{"x":-0.9375,"y":28.59375},"right_top":{"x":445.3125,"y":22.96875},"right_bottom":{"x":445.3125,"y":551.71875},"left_bottom":{"x":-0.9375,"y":546.09375}},"label":[]},"image_width":1000,"image_height":600,"img_size":{"w":1000,"h":600},"image_path":"http://tmp/wx4418e3e031e551be.o6zAJs-yC5ByIjnyyy09jKDZquXk.dlrc7P7WlhnGb4aca86b078fc2acb5b08e7a0f438943.jpg"}

行駛證返回結果

行駛證支持正副頁面在一張圖片中

4、營業(yè)執(zhí)照

certificateType='businessLicense'

屬性名類型默認值是否必填說明
onSuccessHandleEvent接口調(diào)用成功的回調(diào)函數(shù)
certificateTypeStringbusinessLicense證書類型包含四種 身份證:idCard、駕駛證:drivingLicense、銀行卡:bankCard、營業(yè)執(zhí)照:businessLicense

onSuccess

參數(shù) e.detail

參考營業(yè)執(zhí)照返回結果實例

示例代碼1

<ocr-navigator bind:onSuccess="businessSuccess"   certificateType="businessLicense">
  <button type="primary">營業(yè)執(zhí)照識別</button>
</ocr-navigator>
/** wxss **/
/*自定義按鈕樣式*/
.ocr-wrapper {
  margin: 40rpx auto;
  width: 375rpx;
}
.intro {
  margin: 40rpx;
}

營業(yè)執(zhí)照返回結果實例

{"reg_num":{"text":"371400228016303","label":[]},"legal_representative":{"text":"xxxx","label":[]},"enterprise_name":{"text":"xxxxx有限公司","label":[]},"address":{"text":"xxx省xxx市xxx","label":[]},"type_of_enterprise":{"text":"有限責任公司(自然人投資或控股)","label":[]},"business_scope":{"text":"xxxxxxxxxxxx","label":[]},"registered_capital":{"text":"叁佰萬元整","label":[]},"valid_period":{"text":"2008年04月12日至年月日","label":[]},"registered_date":{"text":"2008年04月12日","label":[]},"cert_position":{"pos":{"left_top":{"x":65.4609375,"y":115.640625},"right_top":{"x":567.4921875,"y":123.828125},"right_bottom":{"x":567.4921875,"y":811.578125},"left_bottom":{"x":65.4609375,"y":819.765625}},"label":[]},"img_size":{"w":630,"h":874},"image_path":"http://tmp/wx4418e3e031e551be.o6zAJs-yC5ByIjnyyy09jKDZquXk.dlrc7P7WlhnGb4aca86b078fc2acb5b08e7a0f438943.jpg"}

說明

本文檔配合3.0.2以及以上的插件使用,并且調(diào)試基礎庫在2.4.0以及以上才能使用


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號