預約系統 IOS / Android Windows

index.html 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  5. <meta name="description" content="">
  6. <meta name="author" content="">
  7. <script src="js/mqttws31.min.js" type="text/javascript"></script>
  8. <script src="js/jquery-3.5.1.min.js"></script>
  9. <script type="text/javascript">
  10. window.addEventListener( "pageshow",function ( event ) {
  11. var historyTraversal = event.persisted ||
  12. ( typeof window.performance != "undefined" &&
  13. window.performance.navigation.type === 2 );
  14. if ( historyTraversal ) {
  15. // Handle page restore.
  16. window.location.reload();
  17. }
  18. });
  19. </script>
  20. <script type="text/javascript">
  21. var CID = '';
  22. var ID = '';
  23. var PW = '';
  24. var TYPE = '';
  25. var vobj;
  26. var client;
  27. var vmqtt='';
  28. var SN='';
  29. var SubID='';
  30. var myclientid='';
  31. var callist = '';
  32. var isget = false;
  33. var webSocket;
  34. var isget2=false;
  35. var vsn='';
  36. //var vii=1;
  37. var message2;
  38. var message3;
  39. var datenow;
  40. function init()
  41. {
  42. try
  43. {
  44. //alert('test version 2023-5-17 001 ');
  45. datenow = new Date().toLocaleString();
  46. updateOutput('init '+ datenow);
  47. CID = getUrlParameter('CID');
  48. ID = getUrlParameter('ID');
  49. PW= getUrlParameter('PW');
  50. TYPE= getUrlParameter('TYPE');
  51. SN = getUrlParameter('SN');
  52. vmqtt = getUrlParameter('MQTT');
  53. SubID = getUrlParameter('SubID');
  54. //alert(SubID);
  55. /*
  56. CID = '886999000230';
  57. ID = '00000000';
  58. PW= 'CMM87krWqj8Ltt00';
  59. TYPE='IOS';
  60. SN='2501100080027';
  61. MQTT='aws.gigatech.tw';
  62. */
  63. // updateOutput('CID='+CID);
  64. // updateOutput('ID='+ID);
  65. // updateOutput('PW='+PW);
  66. //updateOutput('TYPE='+TYPE);
  67. //myclientid="Giga8869990002301";
  68. //myclientid="Giga"+CID+"1";
  69. //myclientid="Giga"+CID+"1-"+ parseInt(Math.random() * 100000000, 10);
  70. myclientid="Giga"+CID+"1-"+ SubID;
  71. client = new Paho.MQTT.Client(vmqtt, Number(8083), myclientid);
  72. //client = new Paho.MQTT.Client("aws.gigatech.tw", Number(8083), myclientid);
  73. client.onMessageArrived = onMessageArrived;
  74. client.onConnectionLost = onConnectionLost;
  75. // client.connect( {onSuccess: onConnect, onFailure : onFailedConnect,timeout: 3,keepAliveInterval: 35,cleanSession : true});
  76. if (TYPE=='ANDROID')
  77. {
  78. client.connect( {onSuccess: onConnect});
  79. var intervalID423 = setInterval(() => {
  80. clearInterval(intervalID423);
  81. }, 1500);
  82. connect();
  83. }
  84. if (TYPE=='IOS')
  85. {
  86. client.connect( {onSuccess: onConnect, onFailure : onFailedConnect});
  87. var vivi = 0;
  88. var intervalID4 = setInterval(() => {
  89. if (isget)
  90. {
  91. // break;
  92. clearInterval(intervalID4);
  93. }
  94. else
  95. {
  96. if (vivi>2)
  97. {
  98. clearInterval(intervalID4);
  99. alert('連線異常');
  100. }
  101. else
  102. {
  103. vivi++;
  104. getdoorlist() ;
  105. }
  106. // vii++;
  107. }
  108. }, 300);
  109. }
  110. }catch(e)
  111. {
  112. alert(e);
  113. }
  114. }
  115. function onConnectionLost(message)
  116. {
  117. client.connect( {onSuccess: onConnect, onFailure : onFailedConnect});
  118. }
  119. function onMessageArrived(message)
  120. {
  121. //alert(message.payloadString);
  122. var errda = message.payloadString;
  123. //isget=true;
  124. isget2=true;
  125. vobj = JSON.parse( errda);
  126. var jsonString = "{\"action\":\"decode\", \"serial\":\"002\",\"data\":\""+vobj.data+"\"}";
  127. // updateOutput('onMessageArrived');
  128. // updateOutput('----------------------------------------------');
  129. // updateOutput(jsonString);
  130. vsn='002';
  131. /// "WebToApp". 為我們和前端開發人員的約定
  132. if (TYPE=='IOS')
  133. {
  134. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  135. }
  136. if (TYPE=='ANDROID')
  137. {
  138. webSocket.send(jsonString);
  139. }
  140. }
  141. function onFailedConnect()
  142. {
  143. //alert('連線異常');
  144. updateOutput('onFailedConnect '+datenow);
  145. }
  146. function onConnect()
  147. {
  148. datenow = new Date().toLocaleString();
  149. updateOutput('onConnect '+datenow);
  150. //client.subscribe('Reserve8869990002301');
  151. client.subscribe('Reserve'+CID+'1-'+SubID);
  152. //alert('c');
  153. }
  154. </script>
  155. <title>預約 QR Code</title>
  156. <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  157. </head>
  158. <body class="text-center" onload="init()" >
  159. <div id="cardadmin" class="card" style="box-shadow: 0px 0px 1px 1px rgba(0,0,0,0.1);margin: 21px 20px 0;">
  160. <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>
  161. <div style="width: 100%;">
  162. <button id="addneworder" style="border-color: #dcdcdc;border-width: 1px;width: 95%;
  163. height: 56px;
  164. margin: 10px 0px 10px 0px ;
  165. padding: 11px 0 22px;
  166. border-radius: 3px;
  167. font-family:Roboto_Light;font-size:24px;color:#646464;
  168. background-color: #e6e6e6;" onclick="Addpay99()" >
  169. 電腦密碼設定 <img src="image/TwoPerson.png" width="40" height="40" style=" margin: -8px 0px 0px 10px ;" alt=""/></button></div>
  170. <div id="doorlist" >
  171. </div>
  172. </div>
  173. <div>
  174. </div>
  175. <div>
  176. <div>
  177. V.231222-3
  178. </div>
  179. <div id="output" style="display:none">
  180. <h2>Output</h2>
  181. </div>
  182. <script type="text/javascript">
  183. function Addpay99()
  184. {
  185. document.location = "index5.html?CID="+CID+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID;
  186. }
  187. function getdoorlist()
  188. {
  189. datenow = new Date().toLocaleString();
  190. updateOutput('getdoorlist in '+datenow);
  191. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
  192. //var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord=CMM87krWqj8Ltt00\",\"SerialNo\":\"Reserve8869990002301\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  193. // var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord=CMM87krWqj8Ltt00\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  194. var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord="+PW+"\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  195. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+edata+"}";
  196. vsn='001';
  197. // updateOutput(jsonString);
  198. if (TYPE=='IOS')
  199. {
  200. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  201. }
  202. if (TYPE=='ANDROID')
  203. {
  204. datenow = new Date().toLocaleString();
  205. updateOutput('webSocket send '+datenow);
  206. webSocket.send(jsonString);
  207. /*
  208. isget=false;
  209. setTimeout(() => {
  210. if (isget)
  211. {
  212. }else
  213. {
  214. }
  215. }, 500);
  216. */
  217. }
  218. }
  219. </script>
  220. <script type="text/javascript">
  221. var input = document.getElementById("input")
  222. var output = document.getElementById("output");
  223. var vdata="";
  224. var isok=true;
  225. //var wsUrl = "ws://localhost:2980/";
  226. // var wsUrl = "ws://192.168.0.25:2980/";
  227. var wsUrl = "ws://127.0.0.1:2980/";
  228. function connect() {
  229. datenow = new Date().toLocaleString();
  230. updateOutput('call connect '+datenow);
  231. // open the connection if one does not exist
  232. if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) {
  233. return;
  234. }
  235. // updateOutput("Trying to establish a WebSocket connection to <code>" + wsUrl + "</code>");
  236. // Create a websocket
  237. webSocket = new WebSocket(wsUrl);
  238. webSocket.onopen = function(event) {
  239. // updateOutput("Connected!");
  240. getdoorlist() ;
  241. //isget=false;
  242. /*
  243. var vivi = 0;
  244. var intervalID7 = setInterval(() => {
  245. if (isget)
  246. {
  247. clearInterval(intervalID7);
  248. }
  249. else
  250. {
  251. if (vivi>2)
  252. {
  253. clearInterval(intervalID7);
  254. alert('連線異常');
  255. }
  256. else
  257. {
  258. vivi++;
  259. }
  260. }
  261. }, 300);
  262. */
  263. };
  264. webSocket.onmessage = function(event)
  265. {
  266. // alert(event.data);
  267. if (vsn=='002')
  268. {
  269. datenow = new Date().toLocaleString();
  270. updateOutput('webSocket rece decode '+datenow);
  271. var ress = event.data;
  272. //alert('ress='+ress);
  273. // ress=ress.replace(/[^a-z0-9\s]/gi, 'a').replace(/[_\s]/g, '-');
  274. // ress=ress+"}";
  275. // alert('webSocket finish');
  276. // alert('retry'+vii);
  277. // ress= ress.substring(1300,ress.length);
  278. //alert( ress.substring(1300,ress.length));
  279. // alert( event.data.trim().substring(1300,event.data.length) );
  280. callist.innerHTML ='';
  281. try
  282. {
  283. vobj = JSON.parse(ress);
  284. callist = vobj.data.data.calllist;
  285. //alert(callist.length);
  286. for (i=0;i<callist.length;i++)
  287. {
  288. var kk = callist[i].split(';');
  289. var tttxt='';
  290. //alert(kk[0]);
  291. if (kk[4].length!=0)
  292. {
  293. // alert(kk[4]);
  294. tttxt=kk[4];
  295. }
  296. else
  297. {
  298. // alert(kk[0]);
  299. tttxt=kk[0];
  300. }
  301. if (kk[0].startsWith('000'))
  302. {
  303. }else
  304. {
  305. 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>';
  306. }
  307. //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>";
  308. }
  309. // var sevobj = JSON.parse( vobj);
  310. // alert( sevobj.data);
  311. }catch(e)
  312. {
  313. //alert(e);
  314. }
  315. }
  316. if (vsn=='001')
  317. {
  318. isget=true;
  319. try
  320. {
  321. //alert( event.data );
  322. datenow = new Date().toLocaleString();
  323. updateOutput('webSocket rece encode '+datenow);
  324. var ress = event.data;
  325. vobj = JSON.parse( ress);
  326. vdata = "{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}";
  327. }catch(e)
  328. {
  329. alert(e);
  330. }
  331. // updateOutput('---------------------------');
  332. // updateOutput(vdata);
  333. var payload =vdata;
  334. message2 = new Paho.MQTT.Message(payload);
  335. // message.destinationName = '2501100080027' ;
  336. message2.destinationName = SN ;
  337. message2.qos = 1;
  338. message2.retained = false;
  339. var vivi=0;
  340. var intervalID9 = setInterval(() => {
  341. if (isget2)
  342. {
  343. // break;
  344. datenow = new Date().toLocaleString();
  345. updateOutput('isget2 '+datenow);
  346. clearInterval(intervalID9);
  347. }
  348. else
  349. {
  350. if (vivi>5)
  351. {
  352. clearInterval(intervalID9);
  353. alert('連線異常');
  354. }
  355. else
  356. {
  357. vivi++;
  358. client.send(message2);
  359. }
  360. // vii++;
  361. }
  362. }, 1000);
  363. }
  364. // updateOutput('------------xxx------------');
  365. // updateOutput(event.data);
  366. };
  367. webSocket.onclose = function(event) {
  368. // updateOutput("Connection Closed");
  369. // sendBtn.disabled = true;
  370. };
  371. }
  372. function AppToWeb(message) {
  373. if (vsn=='002')
  374. {
  375. var ress = message;
  376. // alert('ress='+ress);
  377. callist.innerHTML ='';
  378. try
  379. {
  380. vobj = JSON.parse(ress);
  381. callist = vobj.data.data.calllist;
  382. for (i=0;i<callist.length;i++)
  383. {
  384. var kk = callist[i].split(';');
  385. var tttxt='';
  386. if (kk[4].length!=0)
  387. {
  388. tttxt=kk[4];
  389. }
  390. else
  391. {
  392. tttxt=kk[0];
  393. }
  394. if (kk[0].startsWith('000'))
  395. {
  396. }else
  397. {
  398. 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>';
  399. }
  400. }
  401. }catch(e)
  402. {
  403. alert(e);
  404. }
  405. }
  406. if (vsn=='001')
  407. {
  408. try
  409. {
  410. isget=true;
  411. var ress = message;
  412. vobj = JSON.parse( ress);
  413. vdata = "{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}";
  414. }catch(e)
  415. {
  416. alert(e);
  417. }
  418. var payload =vdata;
  419. message3 = new Paho.MQTT.Message(payload);
  420. // message.destinationName = '2501100080027' ;
  421. message3.destinationName = SN ;
  422. message3.qos = 1;
  423. message3.retained = false;
  424. var vivi=0;
  425. var intervalID = setInterval(() => {
  426. if (isget2)
  427. {
  428. clearInterval(intervalID);
  429. // break;
  430. }
  431. else
  432. {
  433. if (vivi>2)
  434. {
  435. clearInterval(intervalID);
  436. alert('連線異常');
  437. }
  438. else
  439. {
  440. vivi++;
  441. client.send(message3);
  442. }
  443. // vii++;
  444. }
  445. }, 300);
  446. }
  447. return "Got it"
  448. }
  449. function decode() {
  450. var text = input.value;
  451. var jsonString = "{\"action\":\"decode\", \"serial\":\"001\",\"data\":\""+text+"\"}";
  452. // updateOutput(jsonString);
  453. /// "WebToApp". 為我們和前端開發人員的約定
  454. if (TYPE=='IOS')
  455. {
  456. window.webkit.messageHandlers.AppToWeb.postMessage(jsonString);
  457. }
  458. if (TYPE=='ANDROID')
  459. {
  460. webSocket.send(jsonString);
  461. }
  462. }
  463. function updateOutput(text) {
  464. output.innerHTML += "<br/>" + text;
  465. }
  466. </script>
  467. <script type="text/javascript">
  468. function btnitemback2(i)
  469. {
  470. var vk = callist[i].split(';');
  471. var tttxt='';
  472. // alert(callist[i]);
  473. if (vk[4].length!=0)
  474. {
  475. // alert(kk[4]);
  476. tttxt=vk[4];
  477. }
  478. else
  479. {
  480. // alert(kk[0]);
  481. tttxt=vk[0];
  482. }
  483. //alert(vk[0]+' '+vk[7]);
  484. document.location = "index2.html?KID="+vk[0]+"&name="+tttxt+"&CID="+CID+"&ID="+vk[0]+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID;
  485. }
  486. </script>
  487. <script>
  488. var getUrlParameter = function getUrlParameter(sParam) {
  489. var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  490. sURLVariables = sPageURL.split('&'),
  491. sParameterName,
  492. i;
  493. for (i = 0; i < sURLVariables.length; i++) {
  494. sParameterName = sURLVariables[i].split('=');
  495. if (sParameterName[0] === sParam) {
  496. return sParameterName[1] === undefined ? true : sParameterName[1];
  497. }
  498. }
  499. };
  500. Date.prototype.format = function (format) {
  501. //eg:format="yyyy-MM-dd hh:mm:ss";
  502. if (!format) {
  503. format = "yyyy-MM-dd hh:mm:ss";
  504. }
  505. var o = {
  506. "M+": this.getMonth() + 1, // month
  507. "d+": this.getDate(), // day
  508. "H+": this.getHours(), // hour
  509. "h+": this.getHours(), // hour
  510. "m+": this.getMinutes(), // minute
  511. "s+": this.getSeconds(), // second
  512. "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
  513. "S": this.getMilliseconds()
  514. };
  515. if (/(y+)/.test(format)) {
  516. format = format.replace(RegExp.$1, (this.getFullYear() + "")
  517. .substr(4 - RegExp.$1.length));
  518. }
  519. for (var k in o) {
  520. if (new RegExp("(" + k + ")").test(format)) {
  521. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  522. ? o[k]
  523. : ("00" + o[k]).substr(("" + o[k]).length));
  524. }
  525. }
  526. return format;
  527. };
  528. </script>
  529. <br>
  530. </body>
  531. </html>