Administrator
2021-12-09 d1b058faa19088838b668d6c03dd71c2bcc7d5d3
src/views/securityGuard/sfzJS.js
@@ -43,27 +43,70 @@
    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() {
function CertCtl_connect(fn) {
    // var baseURL = "";
    // getUserIP(function (ip) {
    //     // alert("Got IP! :" + ip);
    //     baseURL = ip;
    // });
    // console.log(baseURL, 666666);
    var result = "";
    var iParam1 = "1";
    // var iParam1 = "1";
    var urls = "http://127.0.0.1:18889/api/connect";
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/connect", false);
    // CertCtl.xhr.open("POST", urls, 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:请求已接收
@@ -72,10 +115,12 @@
    //返回值status      200: "OK"
    //               404: 未找到页面
    //当返回值readyState为4且status为200时,为查询成功
    // console.log(CertCtl.xhr);
    if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
        result = CertCtl.xhr.responseText;
        CertCtl.xhr.readyState = 1;
        // CertCtl.xhr.readyState = 1;
    }
    fn(CertCtl.xhr.responseText)
    return result;
}
@@ -87,8 +132,7 @@
    //发送请求
    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;
@@ -103,8 +147,7 @@
    //发送请求
    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;
@@ -139,8 +182,7 @@
    //发送请求
    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;
@@ -156,8 +198,7 @@
    //发送请求
    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;
@@ -175,8 +216,7 @@
    //发送请求
    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;
@@ -214,8 +254,7 @@
    //发送请求
    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;
@@ -256,8 +295,7 @@
    //发送请求
    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;
@@ -277,8 +315,7 @@
    //发送请求
    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;
@@ -321,8 +358,7 @@
    //发送请求
    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;
@@ -339,8 +375,7 @@
    //发送请求
    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;
@@ -401,8 +436,7 @@
            //result页面回显
            document.getElementById("result").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
//断开连接方法
@@ -420,8 +454,7 @@
            //result页面回显
            document.getElementById("result").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
//获取状态方法
@@ -439,8 +472,7 @@
            //result页面回显
            document.getElementById("result").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
//读卡方法
@@ -509,8 +541,7 @@
            //result页面回显
            document.getElementById("result").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
function readIDCardSN() {
@@ -527,8 +558,7 @@
            //result页面回显
            document.getElementById("result").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
function getSAMID() {
@@ -545,8 +575,7 @@
            //result页面回显
            document.getElementById("result").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
function readM1Card() {
@@ -563,8 +592,7 @@
            //result页面回显
            document.getElementById("ACardResult").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
function writeM1Card() {
@@ -581,8 +609,7 @@
            //result页面回显
            document.getElementById("ACardResult").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
function handleAPDUCMD() {
@@ -599,8 +626,7 @@
            //result页面回显
            document.getElementById("ACardResult").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
/*
@@ -669,8 +695,7 @@
            //result页面回显
            document.getElementById("ACardResult").value = result;
        }
    } catch (e) {
    }
    } catch (e) { }
}
export default CertCtl;