中控身份证打卡器ID100接口调用中遇到的一些坑
1、大家好,这篇文章主要是分享一下身份证读卡器接口调用中遇到的一些坑。
2、需求比较简单,打卡之后把身份证照片和身份证信息保存到服务器和数据库。
<tr>
<td id="readIDDiv" colspan="4" style="text-align:center;">
<!-- <button id="button_readID" onclick="new Device().startFun()"><img src="images/base_readCard.png" id="button_readID">读取身份证信息</button>-->
<button onclick="atart()">开始读取身份证信息</button>
<button onclick="window.clearInterval(init)">停止读取身份证信息</button>
</td>
</tr>
//通过定时任务实现持续打卡
<script type="text/javascript">
var init;
function atart()
{
window.clearInterval(init);
init=self.setInterval("clock()",1000);
};
function clock()
{
new Device().startFun();
// console.log('111111111')
};
</script>
1、本次开发是在中控读卡器官方提供的前端代码上进行开发的, new Device().startFun();为官方提供的方法,我这里只是调用了一下。
2、在用前端代码调用接口时,一定要关闭客户端,要不然会显示接口连接成功,可是无法获取身份证信息的情况.
3、ajax 代码如下
var map =JSON.stringify(result.Certificate);
// console.log(map);
//
if(map !== null && map !==undefined && map !== ''){
$.ajax({
url: "http://192.168.3.177:8080/test/idnumber",
type: "post",
dataType: "json",
data: {map:map},
async: true,
success: function(obj) {
console.log(obj)
//debugger
//result=obj;
if(obj=="1"){
obr="跳转成功";
}
// window.alert(obj);
},
error: function(obj) {
// result="请求服务错误";
window.alert(obj);
//debugger
// alert("请求服务错误");
}
});
@RestController
@RequestMapping("test")
public class Idnumber {
// @Qualifier("idserivce")
@Autowired
private ServiceT serviceT;
@RequestMapping("/idnumber")
@ResponseBody
public Object getString (String map, HttpServletResponse response){
response.setCharacterEncoding("UTF-8");
response.setHeader("Access-Control-Allow-Origin", "*");
/* 星号表示所有的域都可以接受, */
response.setHeader("Access-Control-Allow-Methods", "GET,POST");
// System.out.println(map);
// Idservice idserivce;
serviceT.insetinto(map);
return map;
}
}
2、应为涉及到跨域问题加上下面3行代码,要不然请求不通
response.setCharacterEncoding(“UTF-8”);
response.setHeader(“Access-Control-Allow-Origin”, "");
/ 星号表示所有的域都可以接受, */
response.setHeader(“Access-Control-Allow-Methods”, “GET,POST”);
3、下面正常写业务逻辑就行了,处理图片,保持数据就ok了