QrCode.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>扫码身份验证</title>
  6. </head>
  7. <style>
  8. #code img{
  9. margin: 0 auto;
  10. padding-top: 10px;
  11. }
  12. </style>
  13. <body>
  14. <div id="code" clas s="code"></div>
  15. </body>
  16. <script src="res/jquery/jquery-3.3.1.min.js"></script>
  17. <script src="qrcode.min.js"></script>
  18. <script>
  19. var uuid;
  20. const URL = document.location.protocol+"//"+window.location.host;
  21. function createUniqueString() {
  22. const timestamp = +new Date() + ''
  23. const randomNum = parseInt((1 + Math.random()) * 65536) + ''
  24. return (+(randomNum + timestamp)).toString(32)
  25. }
  26. function newCode(str){
  27. var qrcode = new QRCode(document.getElementById("code"), {
  28. id: 'er_image',
  29. width : 200,
  30. height : 200
  31. });
  32. qrcode.makeCode(str);
  33. }
  34. // function qr_login(){
  35. // uuid = createUniqueString();
  36. // // uuid=res.value;
  37. // document.getElementById("code").innerHTML = "";
  38. // newCode(uuid+'ypzhxfytkjusky');
  39. // document.getElementById("code").title = '';
  40. // };
  41. var wsUri = "wss://qhome.usky.cn/wss/";
  42. var websocket = null;
  43. var initWebSocket = function() {
  44. try{
  45. websocket = new WebSocket(wsUri);
  46. websocket.onopen = function()
  47. {
  48. var json = {};
  49. json.actfrom = "loginpage";
  50. json.action = "query_ercode";
  51. websocket.send(JSON.stringify(json));
  52. setInterval(function(){
  53. if(websocket != null)
  54. websocket.send(JSON.stringify(json));
  55. },30000)
  56. };
  57. websocket.onmessage = function (evt)
  58. {
  59. console.log("Received:",evt.data);
  60. var jData = eval('(' + evt.data + ')');
  61. if (jData.action=="query_ercode"){
  62. document.getElementById("code").innerHTML = "";
  63. var evm_loing = jData.value;
  64. newCode(""+evm_loing);
  65. document.getElementById("code").title = '';
  66. }else if (jData.action=="loginphone"){
  67. var action = jData.action;
  68. var phonenumber = jData.phonenumber;
  69. // document.getElementById("action").value='';
  70. // document.getElementById("phonenumber").value='';
  71. // document.getElementById("action").value=action;
  72. // document.getElementById("phonenumber").value=phonenumber;
  73. location.href = URL + "/YtIoT/view/mainframe.jsp"
  74. // alert("ceshi");
  75. websocket = null;
  76. }
  77. };
  78. websocket.onclose = function()
  79. {
  80. // 关闭 websocket
  81. console.log('连接已关闭...');
  82. // alert("连接已关闭...");
  83. };
  84. }catch(exception){
  85. console.log("Exception:",exception);
  86. (function(){})()
  87. }
  88. }
  89. $(document).ready(function(){
  90. // $("#login_ok").hide();
  91. initWebSocket();
  92. });
  93. // qr_login()
  94. </script>
  95. </html>