| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619 |
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <meta name="description" content="">
- <meta name="author" content="">
-
- <script src="js/mqttws31.min.js" type="text/javascript"></script>
- <script src="js/jquery-3.5.1.min.js"></script>
- <script type="text/javascript">
-
- window.addEventListener( "pageshow",function ( event ) {
- var historyTraversal = event.persisted ||
- ( typeof window.performance != "undefined" &&
- window.performance.navigation.type === 2 );
- if ( historyTraversal ) {
- // Handle page restore.
- window.location.reload();
- }
- });
- </script>
- <script type="text/javascript">
-
-
- var CID = '';
- var ID = '';
- var PW = '';
- var TYPE = '';
- var client;
- var isconn=false;
- var vmqtt='';
- var SN='';
- var SubID='';
- var myclientid='';
- var callist = '';
- var isget = false;
- var webSocket;
- var isget2=false;
- var vsn='';
- //var vii=1;
- function init()
- {
- try
- {
- //alert('test version 2023-5-17 001 ');
- //updateOutput('init');
-
- CID = getUrlParameter('CID');
- ID = getUrlParameter('ID');
- PW= getUrlParameter('PW');
- TYPE= getUrlParameter('TYPE');
- SN = getUrlParameter('SN');
- vmqtt = getUrlParameter('MQTT');
- SubID = getUrlParameter('SubID');
- //alert(SubID);
- /*
- CID = '886999000230';
- ID = '00000000';
- PW= 'CMM87krWqj8Ltt00';
- TYPE='IOS';
- SN='2501100080027';
- MQTT='aws.gigatech.tw';
- */
- // updateOutput('CID='+CID);
- // updateOutput('ID='+ID);
- // updateOutput('PW='+PW);
- //updateOutput('TYPE='+TYPE);
- if (TYPE=='ANDROID')
- {
-
- connect();
- }
-
- if (TYPE=='IOS')
- {
-
-
-
- var vivi = 0;
- var intervalID = setInterval(() => {
-
- if (isget)
- {
- // break;
- }
- else
- {
-
- if (vivi>5)
- {
- clearInterval(intervalID);
- alert('連線異常');
- }
- else
- {
- vivi++;
- getdoorlist() ;
- }
- // vii++;
- }
- }, 400);
-
-
- }
-
-
-
- //myclientid="Giga8869990002301";
- //myclientid="Giga"+CID+"1";
- //myclientid="Giga"+CID+"1-"+ parseInt(Math.random() * 100000000, 10);
- myclientid="Giga"+CID+"1-"+ SubID;
- client = new Paho.MQTT.Client(vmqtt, Number(8083), myclientid);
- //client = new Paho.MQTT.Client("aws.gigatech.tw", Number(8083), myclientid);
- client.onMessageArrived = onMessageArrived;
- client.onConnectionLost = onConnectionLost;
- client.connect( {onSuccess: onConnect, onFailure : onFailedConnect,timeout: 6,keepAliveInterval: 30});
-
- }catch(e)
- {
- alert(e);
- }
- }
- function onConnectionLost(message)
- {
- updateOutput('onConnectionLost');
- client.connect( {onSuccess: onConnect, onFailure : onFailedConnect,timeout: 6,keepAliveInterval: 30});
- //client.connect( {onSuccess: onConnect, onFailure : onFailedConnect});
- }
- function onMessageArrived(message)
- {
- //alert(message.payloadString);
- var errda = message.payloadString;
- //isget=true;
- isget2=true;
- var vobj = JSON.parse( errda);
- var jsonString = "{\"action\":\"decode\", \"serial\":\"002\",\"data\":\""+vobj.data+"\"}";
- // updateOutput('onMessageArrived');
- // updateOutput('----------------------------------------------');
- // updateOutput(jsonString);
- vsn='002';
- /// "WebToApp". 為我們和前端開發人員的約定
- if (TYPE=='IOS')
- {
- window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
- }
- if (TYPE=='ANDROID')
- {
- webSocket.send(jsonString);
- }
-
- }
- function onFailedConnect()
- {
- //alert('連線異常');
- updateOutput('onFailedConnect');
- }
- function onConnect()
- {
- //client.subscribe('Reserve8869990002301');
- client.subscribe('Reserve'+CID+'1-'+SubID);
- updateOutput('onConnect');
- isconn=true;
- //alert('c');
- }
-
-
-
- </script>
- <title>預約 QR Code</title>
- <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
- </head>
-
- <body class="text-center" onload="init()">
- <div id="cardadmin" class="card" style="box-shadow: 0px 0px 1px 1px rgba(0,0,0,0.1);margin: 21px 20px 0;">
- <div style="margin: 0 0 0 0;background-color:#dcdcdc;" ><div style="margin: 10px 35px 10px 10px;" ><img src="image/qttitle.png" width="40" height="40" ><button id="btn100" style="outline:none;line-height:40px;vertical-align: middle; text-align: left;width:80%;border:0px white none;background-color:#dcdcdc;font-family:Roboto_Light;font-size:24px;color:#646464;height:42px;">預約 QR Code</button></div></div>
- <div style="width: 100%;">
- <button id="addneworder" style="border-color: #dcdcdc;border-width: 1px;width: 95%;
- height: 56px;
- margin: 10px 0px 10px 0px ;
- padding: 11px 0 22px;
- border-radius: 3px;
- font-family:Roboto_Light;font-size:24px;color:#646464;
- background-color: #e6e6e6;" onclick="Addpay99()" >
- 電腦密碼設定 <img src="image/TwoPerson.png" width="40" height="40" style=" margin: -8px 0px 0px 10px ;" alt=""/></button></div>
-
-
- <div id="doorlist" >
-
- </div>
-
- </div>
-
-
- <div>
-
- </div>
- <div>
-
- <div>
- V.231222-1
- </div>
-
- <div id="output" style="display:none">
- <h2>Output</h2>
- </div>
-
- <script type="text/javascript">
- function Addpay99()
- {
-
- document.location = "index5.html?CID="+CID+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID;
-
- }
- function getdoorlist()
- {
-
- var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
-
-
- //var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord=CMM87krWqj8Ltt00\",\"SerialNo\":\"Reserve8869990002301\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
-
- // var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord=CMM87krWqj8Ltt00\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
-
- var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord="+PW+"\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
-
- var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+edata+"}";
- vsn='001';
- // updateOutput(jsonString);
-
- if (TYPE=='IOS')
- {
- window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
- }
-
- if (TYPE=='ANDROID')
- {
- webSocket.send(jsonString);
- /*
- isget=false;
- setTimeout(() => {
- if (isget)
- {
- }else
- {
- }
- }, 500);
- */
-
-
- }
- }
-
- </script>
- <script type="text/javascript">
-
- var input = document.getElementById("input")
- var output = document.getElementById("output");
- var vdata="";
- var isok=true;
-
-
- //var wsUrl = "ws://localhost:2980/";
-
- // var wsUrl = "ws://192.168.0.25:2980/";
- var wsUrl = "ws://127.0.0.1:2980/";
-
- function connect() {
-
- // open the connection if one does not exist
- if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) {
- updateOutput('webSocket fail');
- return;
-
- }
-
- // updateOutput("Trying to establish a WebSocket connection to <code>" + wsUrl + "</code>");
-
- // Create a websocket
- webSocket = new WebSocket(wsUrl);
- webSocket.onopen = function(event) {
-
- // updateOutput("Connected!");
-
-
- // getdoorlist() ;
- //isget=false;
- var vivi = 0;
-
- var intervalID = setInterval(() => {
- if (isget)
- {
- // break;
- }
- else
- {
-
-
- if (vivi>15)
- {
- updateOutput('vivi 6');
- clearInterval(intervalID);
- alert('連線異常');
-
- }
- else
- {
- vivi++;
- updateOutput('call webSocket send msg');
- if (isconn)
- {
- getdoorlist() ;
- }
-
- }
- // vii++;
- }
- }, 400);
-
-
- };
-
- webSocket.onmessage = function(event)
- {
- updateOutput('webSocket return msg');
- // alert(event.data);
- if (vsn=='002')
- {
- var ress = event.data;
- //alert('ress='+ress);
- // ress=ress.replace(/[^a-z0-9\s]/gi, 'a').replace(/[_\s]/g, '-');
- // ress=ress+"}";
- // alert('webSocket finish');
- // alert('retry'+vii);
- // ress= ress.substring(1300,ress.length);
- //alert( ress.substring(1300,ress.length));
- // alert( event.data.trim().substring(1300,event.data.length) );
- callist.innerHTML ='';
- try
- {
- var vobj = JSON.parse(ress);
- callist = vobj.data.data.calllist;
- //alert(callist.length);
- for (i=0;i<callist.length;i++)
- {
- var kk = callist[i].split(';');
- var tttxt='';
- //alert(kk[0]);
- if (kk[4].length!=0)
- {
- // alert(kk[4]);
- tttxt=kk[4];
- }
- else
- {
- // alert(kk[0]);
- tttxt=kk[0];
- }
- if (kk[0].startsWith('000'))
- {
- }else
- {
- doorlist.innerHTML =doorlist.innerHTML+'<div style="margin: 10px 35px 0px -14px;"><button id="doorsin'+i+'" style="line-height:28px;vertical-align: middle; text-align: left;width:80%;border:0px white none;background-color:white;font-family:Roboto_Light;font-size:24px;outline:none;color:#646464;height:28px;" onclick="btnitemback2(\''+i+'\')">'+tttxt+'</button></div><br>';
-
- }
-
- //doorlist.innerHTML =doorlist.innerHTML+ '<div style="margin: 10px 35px 10px -18px;" ><button id="'+i+' style="line-height:40px;vertical-align: middle; text-align: left;width:80%;border:0px white none;background-color:white;font-family:Roboto_Light;font-size:24px;outline:none;color:#646464;height:42px;" onclick="btnGGTT('SingPush.html')">'+tttxt+'</button> </div>";
-
- }
- // var sevobj = JSON.parse( vobj);
- // alert( sevobj.data);
-
- }catch(e)
- {
- //alert(e);
- }
- }
- if (vsn=='001')
- {
- try
- {
- //alert( event.data );
- var ress = event.data;
- isget=true;
- var vobj = JSON.parse( ress);
-
- vdata = "{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}";
- }catch(e)
- {
- alert(e);
- }
- // updateOutput('---------------------------');
- // updateOutput(vdata);
- updateOutput('mqtt send before');
- isget2=false;
- var payload =vdata;
- var message = new Paho.MQTT.Message(payload);
- // message.destinationName = '2501100080027' ;
- message.destinationName = SN ;
- message.qos = 2;
- message.retained = false;
-
- var vivi=0;
- var intervalID = setInterval(() => {
- if (isget2)
- {
- // break;
- }
- else
- {
-
- if (vivi>5)
- {
- clearInterval(intervalID);
- alert('連線異常');
-
- }
- else
- {
- vivi++;
- updateOutput('mqtt send');
- client.send(message);
- }
- // vii++;
- }
- }, 400);
-
-
-
-
-
- }
- // updateOutput('------------xxx------------');
- // updateOutput(event.data);
-
- };
-
- webSocket.onclose = function(event) {
- updateOutput("Connection Closed");
-
- // sendBtn.disabled = true;
- };
- }
-
-
-
-
- function AppToWeb(message) {
-
- if (vsn=='002')
- {
- var ress = message;
- // alert('ress='+ress);
- callist.innerHTML ='';
- try
- {
- var vobj = JSON.parse(ress);
- callist = vobj.data.data.calllist;
-
- for (i=0;i<callist.length;i++)
- {
- var kk = callist[i].split(';');
- var tttxt='';
-
- if (kk[4].length!=0)
- {
-
- tttxt=kk[4];
- }
- else
- {
-
- tttxt=kk[0];
- }
- if (kk[0].startsWith('000'))
- {
- }else
- {
- doorlist.innerHTML =doorlist.innerHTML+'<div style="margin: 10px 35px 0px -14px;"><button id="doorsin'+i+'" style="line-height:28px;vertical-align: middle; text-align: left;width:80%;border:0px white none;background-color:white;font-family:Roboto_Light;font-size:24px;outline:none;color:#646464;height:28px;" onclick="btnitemback2(\''+i+'\')">'+tttxt+'</button></div><br>';
-
- }
-
- }
-
-
- }catch(e)
- {
- alert(e);
- }
- }
- if (vsn=='001')
- {
- try
- {
- isget=true;
- var ress = message;
-
- var vobj = JSON.parse( ress);
-
- vdata = "{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}";
- }catch(e)
- {
- alert(e);
- }
-
- var payload =vdata;
- var message = new Paho.MQTT.Message(payload);
- // message.destinationName = '2501100080027' ;
- message.destinationName = SN ;
- message.qos = 2;
- message.retained = false;
- client.send(message);
-
- }
-
-
- return "Got it"
- }
-
-
-
- function decode() {
- var text = input.value;
- var jsonString = "{\"action\":\"decode\", \"serial\":\"001\",\"data\":\""+text+"\"}";
- // updateOutput(jsonString);
- /// "WebToApp". 為我們和前端開發人員的約定
- if (TYPE=='IOS')
- {
- window.webkit.messageHandlers.AppToWeb.postMessage(jsonString);
- }
- if (TYPE=='ANDROID')
- {
- webSocket.send(jsonString);
- }
- }
-
-
-
- function updateOutput(text) {
- output.innerHTML += "<br/>" + text;
- }
-
-
- </script>
-
- <script type="text/javascript">
- function btnitemback2(i)
- {
- var vk = callist[i].split(';');
- var tttxt='';
- // alert(callist[i]);
- if (vk[4].length!=0)
- {
- // alert(kk[4]);
- tttxt=vk[4];
- }
- else
- {
- // alert(kk[0]);
- tttxt=vk[0];
- }
- //alert(vk[0]+' '+vk[7]);
- document.location = "index2.html?KID="+vk[0]+"&name="+tttxt+"&CID="+CID+"&ID="+vk[0]+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID;
- }
- </script>
- <script>
- var getUrlParameter = function getUrlParameter(sParam) {
- var sPageURL = decodeURIComponent(window.location.search.substring(1)),
- sURLVariables = sPageURL.split('&'),
- sParameterName,
- i;
-
- for (i = 0; i < sURLVariables.length; i++) {
- sParameterName = sURLVariables[i].split('=');
-
- if (sParameterName[0] === sParam) {
- return sParameterName[1] === undefined ? true : sParameterName[1];
- }
- }
- };
-
- Date.prototype.format = function (format) {
- //eg:format="yyyy-MM-dd hh:mm:ss";
-
- if (!format) {
- format = "yyyy-MM-dd hh:mm:ss";
- }
-
- var o = {
- "M+": this.getMonth() + 1, // month
- "d+": this.getDate(), // day
- "H+": this.getHours(), // hour
- "h+": this.getHours(), // hour
- "m+": this.getMinutes(), // minute
- "s+": this.getSeconds(), // second
- "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
- "S": this.getMilliseconds()
- };
-
- if (/(y+)/.test(format)) {
- format = format.replace(RegExp.$1, (this.getFullYear() + "")
- .substr(4 - RegExp.$1.length));
- }
-
- for (var k in o) {
- if (new RegExp("(" + k + ")").test(format)) {
- format = format.replace(RegExp.$1, RegExp.$1.length == 1
- ? o[k]
- : ("00" + o[k]).substr(("" + o[k]).length));
- }
- }
-
- return format;
- };
- </script>
- <br>
- </body>
-
- </html>
|