1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 要求上传身份证等信息 – java – 前端

要求上传身份证等信息 – java – 前端

时间:2018-09-29 00:15:09

相关推荐

要求上传身份证等信息 – java – 前端

一、前言

一般不会泄露,但可能会存在三无APP,所以要擦亮自己的眼睛,不要乱注册一些无用的APP,一般APP的身份证上传,对于企业它是怎么使用的昵?下面基于程序员的角度来帮助分析一下这个问题,希望能解开你的疑惑。

二、用途

对于企业来说,拿到你的身份证,无非就是身份证OCR(文字识别)一下,就是识别出你的身份证正反面的信息,然后校验以下几种情况:

注册身份的真实性;身份证是否过期;年龄是否满足注册条件;性别校验;…

以上信息是否都校验是基于这款产品的目的用途。一般APP基本都是拿到姓名、身份证号校验注册身份的真实性即可。

除上以外,会保存你的身份证照片,这个虽然保存在企业服务器上了,但是一般都是授权访问的,如有疑问,问题排查所用。企业员工都是基于法律签订合同的,如果真有企业或者员工做非法的事情,那就是违犯,等待相关机关处理。

三、技术实现

一般身份证OCR实现,都是借助第三方接口实现,目前大部分都是采用百度实现。实现方式如下:

1.获取百度身份证文字识别密钥,登录https://console./ai/?fromai=1#/ai/ocr/overview/index,拿到APP_ID、API_KEY、SECRET_KEY即可。

2.maven配置

<dependencies><!– 百度文字识别SDK –> <dependency><groupId>com.baidu.aip</groupId><artifactId>java-sdk</artifactId><version>4.6.1</version></dependency></dependencies>

3.controller实现

package com.midou.idcardocr.controller;import com.baidu.aip.ocr.AipOcr;import com.midou.idcardocr.util.ImageUtil;import org.json.JSONObject;import java.util.HashMap;/** * @author 米兜 * @description * @date /6/28 8:17 * @modified by */public class HelloWorld {//申请的[https://console./ai/?fromai=1#/ai/ocr/overview/index] public static final String APP_ID = “20621426”;public static final String API_KEY = “01IBzVivzwkwdQMS9B4ScdDt”;public static final String SECRET_KEY = “RvIYakSHRgZrNnOIDXObitl2FOEQdtUo”;public static void main(String[] args) {AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);// 传入可选参数调用接口 HashMap<String, String> options = new HashMap<String, String>();options.put(“detect_direction”, “true”);options.put(“detect_risk”, “false”);//身份证背面照 //String idCardSide = “back”; //身份证正面照 String idCardSide = “front”;// 参数为本地图片路径 //String image = “D:\\back.jpg”; String image = “D:\\front.jpg”;JSONObject res = client.idcard(image, idCardSide, options);System.out.println(res.toString(2));// 参数为本地图片转二进制 byte[] file = ImageUtil.readImageFile(image);res = client.idcard(file, idCardSide, options);System.out.println(res.toString(2));}}

4.上面涉及一个本地图片转二进制package com.midou.idcardocr.util;import javax.imageio.stream.FileImageInputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;/** * @author 米兜 * @description * @date /6/28 8:24 * @modified by */public class ImageUtil {/** * 将图像转为二进制数组 * * @param path * @return */ public static byte[] readImageFile(String path) {byte[] data = null;FileImageInputStream input = null;try {input = new FileImageInputStream(new File(path));ByteArrayOutputStream output = new ByteArrayOutputStream();byte[] buf = new byte[1024];int numBytesRead = 0;while ((numBytesRead = input.read(buf)) != -1) {output.write(buf, 0, numBytesRead);}data = output.toByteArray();output.close();input.close();} catch (FileNotFoundException ex1) {ex1.printStackTrace();} catch (IOException ex1) {ex1.printStackTrace();}return data;}}

四、运行结果

[图片来源网络,如有争议,联系删除即可]

0 [main] INFO com.baidu.aip.client.BaseClient – get access_token success. current state: STATE_AIP_AUTH_OK

2 [main] DEBUG com.baidu.aip.client.BaseClient – current state after check priviledge: STATE_TRUE_AIP_USER

{

“log_id”: 3010258785723740188,

“words_result”: {

“姓名”: {

“words”: “栾韶东”,

“location”: {

“top”: 40,

“left”: 89,

“width”: 51,

“height”: 19

}

},

“民族”: {

“words”: “回”,

“location”: {

“top”: 76,

“left”: 168,

“width”: 12,

“height”: 14

}

},

“住址”: {

“words”: “广东省深圳市福田区笋岗西路3002号”,

“location”: {

“top”: 140,

“left”: 85,

“width”: 166,

“height”: 37

}

},

“公民身份号码”: {

“words”: “”,

“location”: {

“top”: 0,

“left”: 0,

“width”: 0,

“height”: 0

}

},

“出生”: {

“words”: “19680909”,

“location”: {

“top”: 107,

“left”: 86,

“width”: 131,

“height”: 14

}

},

“性别”: {

“words”: “男”,

“location”: {

“top”: 76,

“left”: 89,

“width”: 10,

“height”: 15

}

}

},

“words_result_num”: 6,

“idcard_number_type”: 0,

“image_status”: “unknown”,

“direction”: 0

}

{

“log_id”: 2919714179777122876,

“words_result”: {

“姓名”: {

“words”: “栾韶东”,

“location”: {

“top”: 40,

“left”: 89,

“width”: 51,

“height”: 19

}

},

“民族”: {

“words”: “回”,

“location”: {

“top”: 76,

“left”: 168,

“width”: 12,

“height”: 14

}

},

“住址”: {

“words”: “广东省深圳市福田区笋岗西路3002号”,

“location”: {

“top”: 140,

“left”: 85,

“width”: 166,

“height”: 37

}

},

“公民身份号码”: {

“words”: “”,

“location”: {

“top”: 0,

“left”: 0,

“width”: 0,

“height”: 0

}

},

“出生”: {

“words”: “19680909”,

“location”: {

“top”: 107,

“left”: 86,

“width”: 131,

“height”: 14

}

},

“性别”: {

“words”: “男”,

“location”: {

“top”: 76,

“left”: 89,

“width”: 10,

“height”: 15

}

}

},

“words_result_num”: 6,

“idcard_number_type”: 0,

“image_status”: “unknown”,

“direction”: 0

}

Process finished with exit code 0

五、总结

上面是基于程序员角度分析身份证信息问题,如有不对,请多多包涵。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。