react-native使用Face++识别身份证,读取信息展示

react

文档中心地址/OCR ID Card API:
https://console.faceplusplus.com.cn/documents/5671702

下面是实现的效果图:


按照官方文档的调用实例:

curl -X POST “https://api-cn.faceplusplus.com/cardpp/v1/ocridcard”

-F “api_key=<api_key>”

-F “api_secret=<api_secret>”

-F “[email protected]_file.jpg”

api_key、 api_secret

官网的 应用管理里面创建API Key 生成

根据需要,选择类型,这边文档里楼主用的是试用的

创建成功,下面圈出来的就是上面对应两个参数的值

image_file.jpg

是传入的身份证照片

楼主用的是formData方式上传的

代码块:

引入react-native-image-picker获取图片

 import ImagePicker from 'react-native-image-picker';

getImage() {

const options = {

quality: 0.4,

maxWidth: 500,

maxHeight: 500,

noData: true,

storageOptions: {//是否做为临时图片存储

skipBackup: true//在手机相册存储图片

}

};

ImagePicker.launchImageLibrary(options, (response) => {

console.log('Response = ', response);

if (response.didCancel) {

console.log('User cancelled photo picker');

}

else if (response.error) {

console.log('ImagePicker Error: ', response.error);

}

else if (response.customButton) {

console.log('User tapped custom button: ', response.customButton);

}

else {

console.log('response==== ', response);

let formData = new FormData();

let file = {uri: response.uri, type: 'multipart/form-data', name: Date.parse(new Date()) + ".jpg"};

this.setState({

CardImage: file,

});

formData.append('image_file', file);

let url = 'https://api-cn.faceplusplus.com/cardpp/v1/ocridcard' + '?api_key=' + '**********' + '&api_secret=' + '*********';

console.log('formData--', formData);

RTRequest.uploadPhoto(url, formData).then((responseText) => {

if (responseText) {

console.log('图片识别成功,返回数据:====', responseText);

if (responseText) {

this.setState({

cardsData: responseText.cards[0],

});

}

}

})

console.log('url==== ', this.state.url);

console.log('cardsData==== ', this.state.cardsData);

}

});

}

返回值示例

正面示例

{

"cards": [{

"gender": "女",

"name": "牛XX",

"id_card_number": "XXXXXX19841013XXXX",

"birthday": "1984-10-13",

"race": "汉",

"address": "广东省深圳市XXXXXXXX",

"legality": {

"Edited": 0.001,

"Photocopy": 0.0,

"ID Photo": 0.502,

"Screen": 0.496,

"Temporary ID Photo": 0.0

},

"type": 1,

"side": "front"

}],

"time_used": 2151,

"request_id": "1473759244,40dfde25-6d1a-4c90-a994-813556c81e30"

}

背面示例

{

"cards": [{

"issued_by": "北京市公安局海淀分局",

"side": "back",

"valid_date": "2010.11.13-2020.11.13"

}],

"time_used": 2151,

"request_id": "1473759244,40dfde25-6d1a-4c90-a994-813556c81e30"

}

请求失败返回示例

{

"time_used": 3,

"error_message": "MISSING_ARGUMENTS: image_url, image_file, image_base64",

"request_id": "1470378968,c6f50ec6-49bd-4838-9923-11db04c40f8d"

}

以上是 react-native使用Face++识别身份证,读取信息展示 的全部内容, 来源链接: utcz.com/z/384047.html

回到顶部