Administrator
2022-04-11 79d9fc857559982b00b68b2d709807bdc4cd286f
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://localhost: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;
}
@@ -83,12 +128,11 @@
function CertCtl_disconnect() {
    var result = "";
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/disconnect", false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/disconnect", false);
    //发送请求
    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;
@@ -99,12 +143,11 @@
function CertCtl_getStatus() {
    var result = "";
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/getStatus", false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/getStatus", false);
    //发送请求
    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;
@@ -117,8 +160,8 @@
    var result = "";
    try {
        //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
        CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readCard", false); //readCard读卡,不生成正反面仿复印件
        //CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readCert", false);     //readCert读卡,生成正反面仿复印件
        CertCtl.xhr.open("POST", "http://localhost:18889/api/readCard", false); //readCard读卡,不生成正反面仿复印件
        //CertCtl.xhr.open("POST", "http://localhost:18889/api/readCert", false);     //readCert读卡,生成正反面仿复印件
        //发送请求
        CertCtl.xhr.send();
        if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
@@ -135,12 +178,11 @@
function CertCtl_readICCardSN() {
    var result = "";
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readICCardSN", false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/readICCardSN", false);
    //发送请求
    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;
@@ -152,12 +194,11 @@
function CertCtl_readIDCardSN() {
    var result = "";
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readIDCardSN", false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/readIDCardSN", false);
    //发送请求
    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;
@@ -171,12 +212,11 @@
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    //getSAMID 获取的SAMID,格式为:05032013102800015247360103645891
    //getSAMIDStr 获取SAMID,格式为:05.03-20131028-0001524736-0103645891
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/getSAMIDStr", false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/getSAMIDStr", false);
    //发送请求
    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;
@@ -209,13 +249,12 @@
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readM1Card?" + "SID=" + sid + "&BID=" + bid + "&KEYTYPE=" + keyType + "&KEY=" + key, false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/readM1Card?" + "SID=" + sid + "&BID=" + bid + "&KEYTYPE=" + keyType + "&KEY=" + key, false);
    //发送请求
    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;
@@ -251,13 +290,12 @@
        data = document.getElementById("cmd").value;
    }
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/writeM1Card?" + "SID=" + sid + "&BID=" + bid + "&KEYTYPE=" + keyType + "&KEY=" + key + "&DATA=" + data, false);
    //CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/writeM1Card?"+"SID="+sid+"&BID="+bid+"&KEYTYPE="+keyType+"&KEY="+key+"&DATA="+data, false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/writeM1Card?" + "SID=" + sid + "&BID=" + bid + "&KEYTYPE=" + keyType + "&KEY=" + key + "&DATA=" + data, false);
    //CertCtl.xhr.open("POST", "http://localhost:18889/api/writeM1Card?"+"SID="+sid+"&BID="+bid+"&KEYTYPE="+keyType+"&KEY="+key+"&DATA="+data, false);
    //发送请求
    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;
@@ -273,12 +311,11 @@
        cmd = document.getElementById("cmd").value;
    }
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/handleAPDUCMD?" + "APDUCMD=" + cmd, false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/handleAPDUCMD?" + "APDUCMD=" + cmd, false);
    //发送请求
    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;
@@ -297,7 +334,7 @@
    }
    
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/setProgramCode?"+"PROGRAMCODE="+programData, false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/setProgramCode?"+"PROGRAMCODE="+programData, false);
    //发送请求
    try {
        CertCtl.xhr.send();
@@ -317,12 +354,11 @@
        programData = document.getElementById("programData").value;
    }
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/checkProgramCode?" + "PROGRAMCODE=" + programData, false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/checkProgramCode?" + "PROGRAMCODE=" + programData, false);
    //发送请求
    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;
@@ -335,12 +371,11 @@
    var result = "";
    var IsMute = false; //false - 开声音(默认开), true - 关声音
    //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
    CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/Routon_Mute?" + "ISMUTE=" + IsMute, false);
    CertCtl.xhr.open("POST", "http://localhost:18889/api/Routon_Mute?" + "ISMUTE=" + IsMute, false);
    //发送请求
    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;