123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>扫码身份验证</title>
- </head>
- <style>
- #code img{
- margin: 0 auto;
- padding-top: 10px;
- }
- </style>
- <body>
- <div id="code" clas s="code"></div>
- </body>
- <script src="res/jquery/jquery-3.3.1.min.js"></script>
- <script src="qrcode.min.js"></script>
- <script>
- var uuid;
- const URL = document.location.protocol+"//"+window.location.host;
- function createUniqueString() {
- const timestamp = +new Date() + ''
- const randomNum = parseInt((1 + Math.random()) * 65536) + ''
- return (+(randomNum + timestamp)).toString(32)
- }
- function newCode(str){
- var qrcode = new QRCode(document.getElementById("code"), {
- id: 'er_image',
- width : 200,
- height : 200
- });
- qrcode.makeCode(str);
- }
- // function qr_login(){
- // uuid = createUniqueString();
- // // uuid=res.value;
- // document.getElementById("code").innerHTML = "";
- // newCode(uuid+'ypzhxfytkjusky');
- // document.getElementById("code").title = '';
- // };
- var wsUri = "wss://qhome.usky.cn/wss/";
- var websocket = null;
- var initWebSocket = function() {
- try{
- websocket = new WebSocket(wsUri);
- websocket.onopen = function()
- {
- var json = {};
- json.actfrom = "loginpage";
- json.action = "query_ercode";
- websocket.send(JSON.stringify(json));
- setInterval(function(){
- if(websocket != null)
- websocket.send(JSON.stringify(json));
- },30000)
- };
- websocket.onmessage = function (evt)
- {
- console.log("Received:",evt.data);
- var jData = eval('(' + evt.data + ')');
- if (jData.action=="query_ercode"){
- document.getElementById("code").innerHTML = "";
- var evm_loing = jData.value;
- newCode(""+evm_loing);
- document.getElementById("code").title = '';
- }else if (jData.action=="loginphone"){
- var action = jData.action;
- var phonenumber = jData.phonenumber;
- // document.getElementById("action").value='';
- // document.getElementById("phonenumber").value='';
- // document.getElementById("action").value=action;
- // document.getElementById("phonenumber").value=phonenumber;
- location.href = URL + "/YtIoT/view/mainframe.jsp"
- // alert("ceshi");
- websocket = null;
- }
- };
- websocket.onclose = function()
- {
- // 关闭 websocket
- console.log('连接已关闭...');
- // alert("连接已关闭...");
- };
- }catch(exception){
- console.log("Exception:",exception);
- (function(){})()
- }
- }
- $(document).ready(function(){
- // $("#login_ok").hide();
- initWebSocket();
- });
- // qr_login()
- </script>
- </html>
|