0.2.0 • Published 7 years ago

react-native-huashi-100u v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

react-native-huashi-100u

npm.io API for Huashi 100U ID card scanner

NOTICE: THIS COMPONENT IS ONLY FOR ANDROID

Installation

npm install react-native-huashi-100u --save

react-native link

put below service tag into application tag in AndroidManifest.xml

<service
    android:name="com.huashi.otg.sdk.HsOtgService"
    android:enabled="true"
    android:exported="true"></service>

Usage

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, {Component} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
} from 'react-native';
import HsOtg from 'react-native-huashi-100u';


export default class test extends Component {

  async init() {
    try {
      const result = await HsOtg.init();
      // success
      // {
      //   code: 1,
      //   sam: "4321442432432423423432414324324" // 模块代码
      // }
      alert(JSON.stringify(result));
    } catch ({code, message}) {
      // error
      // code:-1, msg:"init failed"
      // code:0, msg:"connect failed"
      alert(`code: ${code}, message: ${message}`);
    }
  };
  async auth() {
    try {
      const result = await HsOtg.auth();
      // success
      // {
      //   code: 1,
      //   msg: "success"
      // }
      // {
      //   code: 2,
      //   msg: "auth failed"
      // }
      alert(JSON.stringify(result));
    } catch ({code, message}) {
      // error
      // code:-1, msg:"init failed"
      // code:0, msg:"connect failed"
      alert(`code: ${code}, message: ${message}`);
    }
  };
  async read() {
    try {
      const result = await HsOtg.read();
      // success
      // {
      //   code: 1,
      //   firstFP: "左手拇指,87",
      //   secondFP: "右手拇指,87",
      //   name: "张三",
      //   sex: "男",
      //   people: "汉",
      //   birthday: "Tue Aug 08 2017 14:29:44 GMT+0800 (CST)",
      //   address: "北京海淀区xxx路",
      //   id: "1104343242342343242",
      //   department: "xxx公安局xxx分局",
      //   startDate: "2017.08.10",
      //   endDate: "2037.08.10",
      // }
      alert(JSON.stringify(result));
    } catch ({code, message}) {
      // error
      // code:-1, msg:"init failed"
      // code:0, msg:"read failed"
      alert(`code: ${code}, message: ${message}`);
    }
  };

  render() {
    return (
      <View style={styles.container}>
        <TouchableHighlight onPress={this.init}>
          <Text style={styles.welcome}>
            init
          </Text>
        </TouchableHighlight>
        <TouchableHighlight onPress={this.auth}>
          <Text style={styles.welcome}>
            auth
          </Text>
        </TouchableHighlight>
        <TouchableHighlight onPress={this.read}>
          <Text style={styles.welcome}>
            read
          </Text>
        </TouchableHighlight>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('test', () => test);