UNPKG

para-bridge-demo

Version:

a bridge api for js-ios/andriod rest

64 lines (56 loc) 1.98 kB
import { BridgePlugin } from '../bridge'; import { get, extend } from 'para-utils'; export interface ICardInfo { // 身份证信息 idCardJson: string; // 身份证图片,H5自动记录正反面. idCardImgBase64: string; } export interface IScanIdentityCardParam { // 是否是正面:"true":正面 | "false":反面 默认true isPositive: 'true' | 'false'; // 是否需要相册 "true":需要 | "false":不需要, 默认false isNeedAlbum?: 'true' | 'false'; } // 原生NTV返回的报文协议定义 interface INtvScanIdentityCardResult { result: { status: '0' | '1' | '2' | '3'; // 0:识别成功 1:识别失败 2:授权失败 3:取消 // 识别结果描述 message: string; }; // 身份证信息 cardInfo: ICardInfo; } // 返回客户端的报文协议定义 export interface IScanIdentityCardResult { status: '0' | '1' | '2' | '3'; // 0:识别成功 1:识别失败 2:授权失败 3:取消 // 识别结果描述 message: string; // 身份证信息 cardInfo: ICardInfo; } export class ScanIdentityCard<K> extends BridgePlugin<IScanIdentityCardParam, K>{ protected get ntvPluginName() { return "_ntv_util_scan_identity_card"; } protected get availableMinVersion() { return "1.0.0"; } protected bridgeExecChrome(pluginName: string | undefined): void { // 可针对不同运行环境实现特定的调用逻辑来MOCK,弥补平台差异性. throw new Error('ScanIdentityCard() 未针对当前环境实现'); } } /** * 扫描用户身份证 * @returns Promise<IScanIdentityCardResult> */ export const scanIdentityCard = (param: IScanIdentityCardParam) => { return new ScanIdentityCard<INtvScanIdentityCardResult>(param).invokeOnce().then(ntvResult => { const cbData = ntvResult.cbData; const result = get(cbData, 'result', { status: '1', message: '' }); const cardInfo = get(cbData, 'cardInfo', {}); return extend({}, result, { cardInfo }) as IScanIdentityCardResult; }); }