| | |
| | | var xmlHttp = null; |
| | | //根据window.XMLHttpRequest对象是否存在使用不同的创建方式 |
| | | if (window.XMLHttpRequest) { |
| | | xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式 |
| | | } |
| | | else if (window.ActiveXObject) { |
| | | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式 |
| | | xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式 |
| | | } else if (window.ActiveXObject) { |
| | | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE浏览器支持的创建方式 |
| | | } |
| | | xmlHttp.withCredentials = false; |
| | | return xmlHttp; |
| | | } |
| | | |
| | | function getUserIP(onNewIP) { // onNewIp - your listener function for new IPs |
| | | //compatibility for firefox and chrome |
| | | var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; |
| | | var pc = new myPeerConnection({ |
| | | iceServers: [] |
| | | }), |
| | | noop = function() {}, |
| | | localIPs = {}, |
| | | ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g, |
| | | key; |
| | | |
| | | function iterateIP(ip) { |
| | | if (!localIPs[ip]) onNewIP(ip); |
| | | localIPs[ip] = true; |
| | | } |
| | | |
| | | //create a bogus data channel |
| | | pc.createDataChannel(""); |
| | | |
| | | // create offer and set local description |
| | | pc.createOffer().then(function(sdp) { |
| | | sdp.sdp.split('\n').forEach(function(line) { |
| | | if (line.indexOf('candidate') < 0) return; |
| | | line.match(ipRegex).forEach(iterateIP); |
| | | }); |
| | | |
| | | pc.setLocalDescription(sdp, noop, noop); |
| | | }).catch(function(reason) { |
| | | // An error occurred, so handle the failure to connect |
| | | }); |
| | | |
| | | //sten for candidate events |
| | | pc.onicecandidate = function(ice) { |
| | | if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return; |
| | | ice.candidate.candidate.match(ipRegex).forEach(iterateIP); |
| | | }; |
| | | } |
| | | |
| | | //连接方法 |
| | | function CertCtl_connect() { |
| | | var baseURL = ""; |
| | | getUserIP(function(ip) { |
| | | // alert("Got IP! :" + ip); |
| | | baseURL = ip; |
| | | }); |
| | | console.log(baseURL, 666666); |
| | | var result = ""; |
| | | var iParam1 = "1"; |
| | | //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步 |
| | | CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/connect", false); |
| | | CertCtl.xhr.open("POST", "http://" + baseURL + ":18889/api/connect", false); |
| | | // CertCtl.xhr.open("POST", urls, false); |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | //返回值readyState 0: 请求未初始化 |
| | | // 1: 服务器连接已建立 |
| | | // 2:请求已接收 |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //发送请求 |
| | | try { |
| | | CertCtl.xhr.send(); |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) { |
| | | result = CertCtl.xhr.responseText; |
| | | CertCtl.xhr.readyState = 1; |
| | |
| | | //result页面回显 |
| | | document.getElementById("result").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | //断开连接方法 |
| | |
| | | //result页面回显 |
| | | document.getElementById("result").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | //获取状态方法 |
| | |
| | | //result页面回显 |
| | | document.getElementById("result").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | //读卡方法 |
| | |
| | | //result页面回显 |
| | | document.getElementById("result").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | function readIDCardSN() { |
| | |
| | | //result页面回显 |
| | | document.getElementById("result").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | function getSAMID() { |
| | |
| | | //result页面回显 |
| | | document.getElementById("result").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | function readM1Card() { |
| | |
| | | //result页面回显 |
| | | document.getElementById("ACardResult").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | function writeM1Card() { |
| | |
| | | //result页面回显 |
| | | document.getElementById("ACardResult").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | function handleAPDUCMD() { |
| | |
| | | //result页面回显 |
| | | document.getElementById("ACardResult").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | /* |
| | |
| | | //result页面回显 |
| | | document.getElementById("ACardResult").value = result; |
| | | } |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | } |
| | | |
| | | export default CertCtl; |