wscp-miping/qian/admin/passdog.html
2024-06-07 16:23:01 +08:00

273 lines
7.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<title>测试</title>
<link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="../plugs/layer/theme/default/layer.css"
rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"
rel="stylesheet">
<style type="text/css">
.xz-ys-top {
width: 100%;
height: 400px;
background: no-repeat center top;
text-align: center;
margin-top: 20px;
}
.xz-sfrz-dl {
width: 390px;
height: 55px;
background: #0389d2;
margin: 280px auto;
color: #fff;
border: none;
font-size: 16px;
font-weight: bold;
cursor: pointer;
}
.xz-sfrz-dl:hover {
background: #1ab394;
}
.xz-ys-bottom {
width: 1421px;
background: no-repeat center top;
margin: 30px auto;
padding-top: 70px;
}
.xz-ys-xf-gn {
width: 1325px;
margin: 20px auto;
background: transparent;
}
.xz-sjstz {
width: 303px;
height: 122px;
border: none;
cursor: pointer;
}
.xz-hqpj {
width: 303px;
height: 122px;
border: none;
cursor: pointer;
}
.xz-hqqm {
width: 303px;
height: 122px;
border: none;
cursor: pointer;
}
.xz-cwdm {
width: 303px;
height: 122px;
border: none;
cursor: pointer;
}
</style>
</head>
<body class="gray-bg">
<object id="test" classid="clsid:C966EBD9-49E9-4E9C-B854-270861C58382"
width="0" height="0"></object>
<div>
<div>websocket版</div>
<div class="xz-ys-bottom">
<div class="xz-ys-xf-gn">
<table cellspacing="20" style="background:transparent;">
<tr>
<td style="background:transparent;">
<button class="xz-sjstz"
onclick="getBase64String()"></button>
</td>
<td width="20px"></td>
<td style="background:transparent;">
<button class="xz-hqpj"
onclick="Auth()"></button>
</td>
<td width="20px"></td>
<td style="background:transparent;">
<button class="xz-hqqm"
onclick="getChangle()"></button>
</td>
<td width="20px"></td>
</tr>
</table>
</div>
</div>
</div>
<!-- Mainly scripts -->
<script src="../plugs/jquery/jquery-1.12.3.min.js"></script>
<!--<script src="${base}static/js/jquery-2.1.1.min.js"></script>-->
<script src="./bootstrap.min.js"></script>
<!--<script src="${base}static/js/bootstrap.min.js"></script>-->
<script src="${base}static/js/layer/layer.js"></script>
<script>
var obj = document.getElementById("test");
var base64String = "";
// 获取随机数
function getBase64String() {
$.ajax("http://localhost:8092/test/test_one.json", {
type: 'post',
success: function(data){
if (data == null) {
alert("获取随机数失败");
return false;
} else {
base64String = data;
alert(data);
}
}
});
// $.ajax({
// async: false, //表示请求是否异步处理
// type: "post", //请求类型
// url: "http://localhost:8092/test/test_one.json",//请求的 URL地址
// dataType: "json",//返回的数据类型
// success: function (data) {
// console.log(1111);
// console.log(data);
// }
// })
// $.post("http://localhost:8092/test/test_one.json", null, function (data) {
// console.log(data);
// if (data == null) {
// alert("获取随机数失败");
// return false;
// } else {
// base64String = data;
// alert(data);
// }
// });
}
var challenge;
// 根据票据获取账号
function getChangle() {
console.log(challenge);
$.post("http://localhost:8092/test/test_two.json", {
"identityTicket": challenge,
"challenge": base64String
}, function (data) {
alert("结果:" + data);
});
}
function USB() {
var oTempObj = new Object;
oTempObj.callbackAuth = new Function();
var wsUri = "ws://127.0.0.1:31018";
var websocket = new WebSocket(wsUri);
websocket.onopen = function (evt) {
console.log(evt);
};
websocket.onclose = function (evt) {
console.log(evt);
};
websocket.onmessage = function (evt) {
if (typeof oTempObj.callbackAuth === "function")
oTempObj.callbackAuth(evt.data);
};
websocket.onerror = function (evt) {
};
function sendMessage(msg) {
console.log("dy");
console.log(msg);
console.log("dy");
waitForSocketConnection(websocket, function () {
websocket.send(msg);
});
};
function waitForSocketConnection(socket, callback) {
setTimeout(
function () {
if (socket.readyState === 1) {
if (callback !== undefined) {
callback();
}
return;
} else {
waitForSocketConnection(socket, callback);
}
}, 2);
};
oTempObj.Auth = function (cspName, callback) {
console.log(cspName);
//var msg = "{\"FuncName\":\"GetSignAndToken\",\"Parames\":{\"IP\":\"192.168.1.165\",\"PORT\":9021,\"svrRandom\":\"" + cspName + "\"},\"sessionID\":\"1111111\"}";
var msg="{\"FuncName\":\"GetSignAndToken\",\"Parames\":{\"IP\":\"192.168.1.10\",\"PORT\":9021,\"svrRandom\":\"" + cspName + "\"},\"sessionID\":\"1111111\"}";
sendMessage(msg);
oTempObj.callbackAuth = callback;
}
oTempObj.CheckKey = function (callback) {
var msg = "{\"FuncName\":\"CheckKey\"}";
sendMessage(msg);
oTempObj.callbackAuth = callback;
}
return oTempObj;
}
var websocket;
// 获取票据
function Auth() {
websocket = new USB();
websocket.CheckKey(function (data) {
var json = $.parseJSON(data);
console.log(data);
if (json.IsKeyIn == 1) {
websocket.Auth(base64String, function (res) {
var obj = $.parseJSON(res);
console.log(res);
if (obj.result == "success") {
challenge = obj.Taken;
alert("成功");
return;
} else {
alert(obj.ErrorCode);
return;
}
});
} else {
alert("无Key")
}
})
}
</script>
</body>
</html>