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

下面是实现的效果图:
react-native使用Face++识别身份证,读取信息展示
react-native使用Face++识别身份证,读取信息展示
按照官方文档的调用实例:

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”

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

api_key、 api_secret
官网的 应用管理里面创建API Key 生成
根据需要,选择类型,这边文档里楼主用的是试用的
react-native使用Face++识别身份证,读取信息展示
创建成功,下面圈出来的就是上面对应两个参数的值react-native使用Face++识别身份证,读取信息展示

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"
}

相关文章:

  • 2021-07-02
  • 2021-10-29
  • 2021-12-30
  • 2021-07-29
  • 2022-02-06
  • 2021-05-14
  • 2021-08-05
猜你喜欢
  • 2021-11-29
  • 2021-09-29
  • 2021-12-05
  • 2021-08-23
  • 2021-11-21
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案