預約系統 IOS / Android Windows

index5.html 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  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 src="js/teacrypt.js" type="text/javascript"></script>
  10. <script type="text/javascript">
  11. var message999;
  12. var message0 ;
  13. var message4 ;
  14. var message9 ;
  15. var message6;
  16. var message7 ;
  17. var message2 ;
  18. var issame=false;
  19. var vvqrcd= '';
  20. var orgcycle='';
  21. var fincycle='';
  22. var orgtimestamp='';
  23. var isconn = false;
  24. var CID = '';
  25. var ID = '';
  26. var PW = '';
  27. var TYPE = '';
  28. var client;
  29. var kname='';
  30. var myclientid='';
  31. var tt = '';
  32. var st = '';
  33. var et = '';
  34. var idx = '';
  35. var cy='';
  36. var vtype='';
  37. var vtttt='';
  38. var isget = false;
  39. var isget2 = false;
  40. var isget3 = false;
  41. var vtstpqr='';
  42. var vcyd='';
  43. var vmqtt='';
  44. var SN='';
  45. var SubID='';
  46. var vsn='';
  47. var vobj;
  48. var vvvi;
  49. var ooodata='';
  50. var is2='';
  51. var account='';
  52. function init()
  53. {
  54. try
  55. {
  56. CID = getUrlParameter('CID');
  57. ID = getUrlParameter('ID');
  58. PW= getUrlParameter('PW');
  59. TYPE= getUrlParameter('TYPE');
  60. SN = getUrlParameter('SN');
  61. vmqtt = getUrlParameter('MQTT');
  62. SubID = getUrlParameter('SubID');
  63. vvvi= getUrlParameter('idx');
  64. kkid= getUrlParameter('ID');
  65. //Cname= getUrlParameter('CNAME');
  66. // var sstitle =Cname+'(#'+SubID+') ';
  67. // vvqrcd= vobj.data.data.CardID;
  68. vvqrcd= getUrlParameter('qrcd');
  69. account=CID+'_'+SubID;
  70. document.getElementById("btn100").innerHTML ='帳號 : '+account;
  71. document.getElementById("btn900").innerHTML ='密碼需為英數字 8-16 碼 ';
  72. //vvqrcd=vvqrcd.replaceAll('-','=');
  73. //updateOutput('init');
  74. /*
  75. CID = getUrlParameter('CID');
  76. ID = getUrlParameter('ID');
  77. PW= getUrlParameter('PW');
  78. TYPE= getUrlParameter('TYPE');
  79. */
  80. //myclientid="Giga"+CID+"1-"+ parseInt(Math.random() * 100000000, 10);
  81. myclientid="Giga"+CID+"1-"+SubID;
  82. client = new Paho.MQTT.Client(vmqtt, Number(8083), myclientid);
  83. client.onMessageArrived = onMessageArrived;
  84. client.onConnectionLost = onConnectionLost;
  85. // client.connect( {onSuccess: onConnect});
  86. // client.connect( {onSuccess: onConnect, onFailure : onFailedConnect,timeout: 3,keepAliveInterval: 35,cleanSession : false});
  87. client.connect( {onSuccess: onConnect, onFailure : onFailedConnect});
  88. //alert(orgcycle);
  89. //updateOutput('CID='+CID);
  90. //updateOutput('ID='+ID);
  91. //updateOutput('PW='+PW);
  92. //updateOutput('TYPE='+TYPE);
  93. if (TYPE=='ANDROID')
  94. {
  95. connect();
  96. }
  97. vsn='';
  98. }catch(e)
  99. {
  100. alert(e);
  101. }
  102. }
  103. function onConnectionLost(message)
  104. {
  105. client.connect( {onSuccess: onConnect, onFailure : onFailedConnect});
  106. }
  107. function onMessageArrived(message)
  108. {
  109. var vres = message.payloadString;
  110. var vobj = JSON.parse( vres);
  111. is2='002';
  112. var jsonString = "{\"action\":\"decode\", \"serial\":\"002\",\"data\":\""+vobj.data+"\"}";
  113. if (TYPE=='IOS')
  114. {
  115. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  116. }
  117. if (TYPE=='ANDROID')
  118. {
  119. webSocket.send(jsonString);
  120. }
  121. if (TYPE=='PC')
  122. {
  123. vres = teaDecrypt(vobj.data,'75$095huOQ77kKv!');
  124. //alert(vres);
  125. var vobj2 = JSON.parse( vres);
  126. //alert(vobj2.success);
  127. if (vobj2.success===true)
  128. {
  129. alert('OK');
  130. }
  131. else
  132. {
  133. alert('失敗');
  134. }
  135. is2='';
  136. }
  137. }
  138. function onFailedConnect()
  139. {
  140. //alert('連線異常');
  141. }
  142. function onConnect()
  143. {
  144. isconn=true;
  145. client.subscribe('Reserve'+CID+'1-'+SubID);
  146. try
  147. {
  148. }
  149. catch(e)
  150. {
  151. alert(e);
  152. }
  153. //alert('c');
  154. }
  155. </script>
  156. <title>預約 QR Code</title>
  157. <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  158. </head>
  159. <body class="text-center" onload="init()">
  160. <div>
  161. <div class="card" style="box-shadow: 0px 0px 1px 1px rgba(0,0,0,0.1);margin: 21px 20px 0;background-color:#FFFFFF;">
  162. <div style="margin: 16px 0 0px 4px;background-color:#FFFFFF;" >
  163. <button id="btn100" style="margin: 2px 0px 0px 0px;outline:none;line-height:40px;vertical-align: middle; text-align: left;width:100%;border:0px white none;background-color:#FFFFFF;font-family:Roboto_Light;font-size:24px;color:#646464;height:42px;"></button>
  164. <button id="btn900" style="margin: 2px 0px 0px 0px;outline:none;line-height:40px;vertical-align: middle; text-align: left;width:100%;border:0px white none;background-color:#FFFFFF;font-family:Roboto_Light;font-size:24px;color:#646464;height:42px;"></button>
  165. </div>
  166. <div style="text-align:center">
  167. <!-- <h1 class="h3 mb-3 font-weight-normal">預收貨款</h1> -->
  168. <!-- <form class="form-signin" id="senddocument"> -->
  169. <br>
  170. <div style="margin: 3px 9px 3px 9px;text-align:left;">
  171. <label style="margin: 5px 0px 5px 0px;font-family:Roboto_Light;font-size:24px;color:#646464;border:none;width: 100px;">密碼&nbsp:&nbsp </label><input type="password" id="ItemNOSer" style="height:40px;box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);margin: 5px 0px 5px 0px;font-family:Roboto_Light;font-size:20px;color:#646464;border:none;width:calc(99% - 100px);" placeholder="" required></div>
  172. <div style="margin: 3px 9px 3px 9px;text-align:left;">
  173. </br>
  174. <table style="width: 100%">
  175. <tbody>
  176. <tr>
  177. <td style="width: 33.3%"><button type="button" style="border-color: #dcdcdc;border-width: 1px;border-color: #dcdcdc;border-width: 1px;margin: 0px 0px 20px 0px;color:#787878;font-family: Roboto_Light; font-size: 24px;width: 110px; height: 60px; background-color: rgba(255, 0, 20, 0.2);width:100%;" onclick="btndddel()" hidden>刪除</button></td><td style="width: 33.3%"><button type="button" style="border-color: #dcdcdc;border-width: 1px;border-color: #dcdcdc;border-width: 1px;margin: 0px 0px 20px 0px;color:#787878;font-family: Roboto_Light; font-size: 24px;width: 110px; height: 60px; background-color: #cce8fc;width:100%;" onclick="ok123()">儲存</button> </td><td style="width: 33.3%"><button type="button" style="border-color: #dcdcdc;border-width: 1px;border-color: #dcdcdc;border-width: 1px;margin: 0px 0px 20px 0px;color:#FFFFFF;font-family: Roboto_Light; font-size: 24px;width: 110px; height: 60px; background-color: #64c800;width:100%;" onclick="btnSaveqr()" hidden>預約</button></td>
  178. </tr>
  179. </tbody>
  180. </table>
  181. </div>
  182. </div>
  183. <div id="output" style="display:none">
  184. <h2>Output</h2>
  185. </div>
  186. <script type="text/javascript">
  187. function ok123()
  188. {
  189. const isValidPasswordChar = str => {
  190. const regex =/^[A-Za-z0-9_.]+$/;
  191. return regex.test(str)
  192. };
  193. try
  194. {
  195. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss");
  196. var vwpw= document.getElementById("ItemNOSer").value;
  197. // alert(vwpw);
  198. if (isValidPasswordChar(vwpw))
  199. {
  200. }else
  201. {
  202. alert('密碼需為英數字');
  203. return;
  204. }
  205. if( (vwpw.length>16)||(vwpw.length<8))
  206. {
  207. alert('密碼長度需介於8~16之間');
  208. return;
  209. }
  210. var message="{\"action\":\"mqttregisterRemoteKeyAccount\",\"data\":{\"Command\":\"User="+SubID+"&Account="+CID+"_"+SubID+"&PassWord="+PW+"&&WebPassWord="+vwpw+"\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  211. is2='001';
  212. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+message+"}";
  213. if (TYPE=='IOS')
  214. {
  215. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  216. }
  217. if (TYPE=='ANDROID')
  218. {
  219. //alert('001 websocket sent');
  220. webSocket.send(jsonString);
  221. }
  222. if (TYPE=='PC')
  223. {
  224. message = teaEncrypt(message,'75$095huOQ77kKv!');
  225. var ress = message;
  226. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  227. message4.destinationName = SN ;
  228. message4.retained = false;
  229. message4.qos = 0;
  230. client.send(message4);
  231. }
  232. }catch(e)
  233. {
  234. alert(e);
  235. }
  236. }
  237. function btnSaveTmp()
  238. {
  239. try
  240. {
  241. issame=false;
  242. //alert(idx);
  243. var vvee1='';
  244. var vvee2='';
  245. var vvee3='';
  246. var cycy='';
  247. var st1 = '0000' ;
  248. var et1= '0000' ;
  249. var st2 = '0000' ;
  250. var et2= '0000' ;
  251. var st3 = '0000' ;
  252. var et3= '0000' ;
  253. //12345
  254. var vItemNOSer=document.getElementById("ItemNOSer").value;
  255. if (vItemNOSer.length<1)
  256. {
  257. alert('請輸入密碼');
  258. return;
  259. }
  260. if((document.getElementById("sd").value<1) || (document.getElementById("ed").value<1) ||(document.getElementById("sdt1").value<1) || (document.getElementById("sdt2").value<1))
  261. {
  262. alert('請輸入開始與結束日期時間');
  263. return;
  264. }
  265. var vsdsd=document.getElementById("sd").value+'T'+document.getElementById("sdt1").value;
  266. //alert(vsdsd);
  267. //return;
  268. var veded =document.getElementById("ed").value+'T'+document.getElementById("sdt2").value;
  269. //alert(veded);
  270. if ((vsdsd.length<2)|| (veded.length<2))
  271. {
  272. alert('請輸入開始與結束日期時間');
  273. return;
  274. }
  275. //alert('pass');
  276. if (vsdsd.length>16)
  277. {
  278. vsdsd=vsdsd.substring(0,16);
  279. }
  280. if (veded.length>16)
  281. {
  282. veded=veded.substring(0,16);
  283. }
  284. vsdsd=vsdsd.replace('T','_');
  285. vsdsd=vsdsd.replace('-','/');
  286. vsdsd=vsdsd.replace('-','/');
  287. veded=veded.replace('T','_');
  288. veded=veded.replace('-','/');
  289. veded=veded.replace('-','/');
  290. vsdsd=vsdsd.substring(2,vsdsd.length);
  291. veded=veded.substring(2,veded.length);
  292. //alert(vsdsd);
  293. //alert(veded);
  294. var vtstp=vsdsd+','+veded;
  295. //alert(vtstp);
  296. //return;
  297. //if (document.getElementById("d11").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png')
  298. if (document.getElementById("d11").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  299. {
  300. vvee1='1';
  301. //alert('bgreen');
  302. }else
  303. {
  304. vvee1='0';
  305. //alert('bgrey');
  306. }
  307. if (document.getElementById("d12").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  308. {
  309. vvee1=vvee1+'1';
  310. }else
  311. {
  312. vvee1=vvee1+'0';
  313. }
  314. if (document.getElementById("d13").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  315. {
  316. vvee1=vvee1+'1';
  317. }else
  318. {
  319. vvee1=vvee1+'0';
  320. }
  321. if (document.getElementById("d14").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  322. {
  323. vvee1=vvee1+'1';
  324. }else
  325. {
  326. vvee1=vvee1+'0';
  327. }
  328. if (document.getElementById("d15").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  329. {
  330. vvee1=vvee1+'1';
  331. }else
  332. {
  333. vvee1=vvee1+'0';
  334. }
  335. if (document.getElementById("d16").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  336. {
  337. vvee1=vvee1+'1';
  338. }else
  339. {
  340. vvee1=vvee1+'0';
  341. }
  342. if (document.getElementById("d17").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  343. {
  344. vvee1=vvee1+'1';
  345. }else
  346. {
  347. vvee1=vvee1+'0';
  348. }
  349. //alert(vvee1);
  350. if (document.getElementById("d21").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  351. {
  352. vvee2='1';
  353. //alert('bgreen');
  354. }else
  355. {
  356. vvee2='0';
  357. //alert('bgrey');
  358. }
  359. if (document.getElementById("d22").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  360. {
  361. vvee2=vvee2+'1';
  362. }else
  363. {
  364. vvee2=vvee2+'0';
  365. }
  366. if (document.getElementById("d23").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  367. {
  368. vvee2=vvee2+'1';
  369. }else
  370. {
  371. vvee2=vvee2+'0';
  372. }
  373. if (document.getElementById("d24").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  374. {
  375. vvee2=vvee2+'1';
  376. }else
  377. {
  378. vvee2=vvee2+'0';
  379. }
  380. if (document.getElementById("d25").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  381. {
  382. vvee2=vvee2+'1';
  383. }else
  384. {
  385. vvee2=vvee2+'0';
  386. }
  387. if (document.getElementById("d26").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  388. {
  389. vvee2=vvee2+'1';
  390. }else
  391. {
  392. vvee2=vvee2+'0';
  393. }
  394. if (document.getElementById("d27").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  395. {
  396. vvee2=vvee2+'1';
  397. }else
  398. {
  399. vvee2=vvee2+'0';
  400. }
  401. // alert(vvee2);
  402. if (document.getElementById("d31").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  403. {
  404. vvee3='1';
  405. //alert('bgreen');
  406. }else
  407. {
  408. vvee3='0';
  409. //alert('bgrey');
  410. }
  411. if (document.getElementById("d32").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  412. {
  413. vvee3=vvee3+'1';
  414. }else
  415. {
  416. vvee3=vvee3+'0';
  417. }
  418. if (document.getElementById("d33").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  419. {
  420. vvee3=vvee3+'1';
  421. }else
  422. {
  423. vvee3=vvee3+'0';
  424. }
  425. if (document.getElementById("d34").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  426. {
  427. vvee3=vvee3+'1';
  428. }else
  429. {
  430. vvee3=vvee3+'0';
  431. }
  432. if (document.getElementById("d35").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  433. {
  434. vvee3=vvee3+'1';
  435. }else
  436. {
  437. vvee3=vvee3+'0';
  438. }
  439. if (document.getElementById("d36").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  440. {
  441. vvee3=vvee3+'1';
  442. }else
  443. {
  444. vvee3=vvee3+'0';
  445. }
  446. if (document.getElementById("d37").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  447. {
  448. vvee3=vvee3+'1';
  449. }else
  450. {
  451. vvee3=vvee3+'0';
  452. }
  453. //alert(vvee3);
  454. var ktype = '1';
  455. if (vvee1=='0000000')
  456. {
  457. }else
  458. {
  459. ktype='2';
  460. st1 = document.getElementById("st1").value.replace(':','') ;
  461. et1= document.getElementById("et1").value.replace(':','') ;
  462. if (st1.length==0 || et1.length==0)
  463. {
  464. alert('請選擇時段1的起始與結束時間');
  465. return;
  466. }
  467. }
  468. if (vvee2=='0000000')
  469. {
  470. }else
  471. {
  472. ktype='2';
  473. st2 = document.getElementById("st2").value.replace(':','') ;
  474. et2= document.getElementById("et2").value.replace(':','') ;
  475. if (st2.length==0 || et2.length==0)
  476. {
  477. alert('請選擇時段2的起始與結束時間');
  478. return;
  479. }
  480. }
  481. if (vvee3=='0000000')
  482. {
  483. }else
  484. {
  485. ktype='2';
  486. st3 = document.getElementById("st3").value.replace(':','') ;
  487. et3= document.getElementById("et3").value.replace(':','') ;
  488. //alert(st3.length)
  489. if (st3.length==0 || et3.length==0)
  490. {
  491. alert('請選擇時段3的起始與結束時間');
  492. return;
  493. }
  494. }
  495. //alert(ktype);
  496. if (ktype=='2')
  497. {
  498. cycy=vvee1+','+st1 +','+ et1+','+ vvee2+','+st2+','+et2+','+vvee3+','+st3+','+et3;
  499. }
  500. else
  501. {
  502. //cycy='';
  503. }
  504. // alert(ktype);
  505. //updateOutput('cycy='+cycy);
  506. //alert(cycy);
  507. fincycle='';
  508. fincycle= document.getElementById("ItemNOSer").value+';';
  509. fincycle=fincycle+ vtstp+';';
  510. fincycle=fincycle+cycy+';';
  511. //alert(cycy);
  512. // alert(fincycle);
  513. if (orgcycle==fincycle)
  514. {
  515. issame=true;
  516. // alert('相同');
  517. }
  518. if (issame)
  519. {
  520. alert('OK');
  521. window.history.go(-1);
  522. }
  523. else
  524. {
  525. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss");
  526. //alert(document.getElementById("ItemNOSer").value);
  527. vtttt = document.getElementById("ItemNOSer").value;
  528. // alert(ktype);
  529. // return;
  530. var edata ="{\"action\":\"mqttupdateRemoteKey\",\"data\":{\"Command\":\"PassWord="+PW+"&ReGenerate=1&Stat=0&Type="+ktype+"&IndexID="+idx+"&TimeStamp="+vtstp+"&Cycle="+cycy+"&UserID="+ID+"&Title="+vtttt+"\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  531. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+edata+"}";
  532. vsn='001';
  533. isget2=false;
  534. // updateOutput(jsonString);
  535. //alert(jsonString
  536. if (TYPE=='IOS')
  537. {
  538. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  539. }
  540. if (TYPE=='ANDROID')
  541. {
  542. webSocket.send(jsonString);
  543. }
  544. if (TYPE=='PC')
  545. {
  546. //alert(edata);
  547. selfendecode(edata);
  548. }
  549. }
  550. }catch(e)
  551. {
  552. alert(e);
  553. }
  554. }
  555. function senttoother()
  556. {
  557. try
  558. {
  559. message999 = new Paho.MQTT.Message( "modify,"+idx+","+SubID+","+kname );
  560. // alert('send to other = '+ "modify,"+idx+","+SubID+","+kname );
  561. message999.qos = 0;
  562. message999.retained = false;
  563. for (var iii = 1; iii < 9; iii++)
  564. {
  565. if ( iii.toString() !=SubID.toString())
  566. {
  567. message999.destinationName = 'Reserve'+CID+'1-'+iii.toString() ;
  568. client.send(message999);
  569. }
  570. }
  571. }
  572. catch(e)
  573. {
  574. alert(e);
  575. }
  576. }
  577. function btnSaveqr()
  578. {
  579. issame=false;
  580. //alert(idx);
  581. var vvee1='';
  582. var vvee2='';
  583. var vvee3='';
  584. var cycy='';
  585. var st1 = '0000' ;
  586. var et1= '0000' ;
  587. var st2 = '0000' ;
  588. var et2= '0000' ;
  589. var st3 = '0000' ;
  590. var et3= '0000' ;
  591. //var vsdsd=document.getElementById("sd").value;
  592. //var veded =document.getElementById("ed").value;
  593. var vsdsd=document.getElementById("sd").value+'T'+document.getElementById("sdt1").value;
  594. //alert(vsdsd);
  595. //return;
  596. var veded =document.getElementById("ed").value+'T'+document.getElementById("sdt2").value;
  597. if (vsdsd.length>16)
  598. {
  599. vsdsd=vsdsd.substring(0,16);
  600. }
  601. if (veded.length>16)
  602. {
  603. veded=veded.substring(0,16);
  604. }
  605. //var vsdsd=document.getElementById("sd").value.format("yyyy/MM/dd_HH:mm");
  606. //vsdsd=vsdsd.substring(0,16);
  607. //alert(vsdsd);
  608. //return;
  609. //12345
  610. var vItemNOSer=document.getElementById("ItemNOSer").value;
  611. if (vItemNOSer.length<1)
  612. {
  613. alert('請輸入預約人');
  614. return;
  615. }
  616. if((document.getElementById("sd").value<1) || (document.getElementById("ed").value<1) ||(document.getElementById("sdt1").value<1) || (document.getElementById("sdt2").value<1))
  617. {
  618. alert('請輸入開始與結束日期時間');
  619. return;
  620. }
  621. var vsdsd=document.getElementById("sd").value+'T'+document.getElementById("sdt1").value;
  622. //alert(vsdsd);
  623. //return;
  624. var veded =document.getElementById("ed").value+'T'+document.getElementById("sdt2").value;
  625. //alert(veded);
  626. if ((vsdsd.length<2)|| (veded.length<2))
  627. {
  628. alert('請輸入開始與結束日期時間');
  629. return;
  630. }
  631. vsdsd=vsdsd.replace('T','_');
  632. vsdsd=vsdsd.replace('-','/');
  633. vsdsd=vsdsd.replace('-','/');
  634. veded=veded.replace('T','_');
  635. veded=veded.replace('-','/');
  636. veded=veded.replace('-','/');
  637. vsdsd=vsdsd.substring(2,vsdsd.length);
  638. veded=veded.substring(2,veded.length);
  639. //alert(vsdsd);
  640. //alert(veded);
  641. var vtstp=vsdsd+','+veded;
  642. vtstpqr=vtstp;
  643. vtstpqr=vtstpqr.replace('_',' ');
  644. vtstpqr=vtstpqr.replace('_',' ');
  645. vtstpqr=vtstpqr.replace(',','~');
  646. //alert(vtstp);
  647. //return;
  648. if (document.getElementById("d11").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  649. {
  650. vvee1='1';
  651. //alert('bgreen');
  652. }else
  653. {
  654. vvee1='0';
  655. //alert('bgrey');
  656. }
  657. if (document.getElementById("d12").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  658. {
  659. vvee1=vvee1+'1';
  660. }else
  661. {
  662. vvee1=vvee1+'0';
  663. }
  664. if (document.getElementById("d13").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  665. {
  666. vvee1=vvee1+'1';
  667. }else
  668. {
  669. vvee1=vvee1+'0';
  670. }
  671. if (document.getElementById("d14").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  672. {
  673. vvee1=vvee1+'1';
  674. }else
  675. {
  676. vvee1=vvee1+'0';
  677. }
  678. if (document.getElementById("d15").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  679. {
  680. vvee1=vvee1+'1';
  681. }else
  682. {
  683. vvee1=vvee1+'0';
  684. }
  685. if (document.getElementById("d16").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  686. {
  687. vvee1=vvee1+'1';
  688. }else
  689. {
  690. vvee1=vvee1+'0';
  691. }
  692. if (document.getElementById("d17").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  693. {
  694. vvee1=vvee1+'1';
  695. }else
  696. {
  697. vvee1=vvee1+'0';
  698. }
  699. //alert(vvee1);
  700. if (document.getElementById("d21").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  701. {
  702. vvee2='1';
  703. //alert('bgreen');
  704. }else
  705. {
  706. vvee2='0';
  707. //alert('bgrey');
  708. }
  709. if (document.getElementById("d22").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  710. {
  711. vvee2=vvee2+'1';
  712. }else
  713. {
  714. vvee2=vvee2+'0';
  715. }
  716. if (document.getElementById("d23").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  717. {
  718. vvee2=vvee2+'1';
  719. }else
  720. {
  721. vvee2=vvee2+'0';
  722. }
  723. if (document.getElementById("d24").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  724. {
  725. vvee2=vvee2+'1';
  726. }else
  727. {
  728. vvee2=vvee2+'0';
  729. }
  730. if (document.getElementById("d25").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  731. {
  732. vvee2=vvee2+'1';
  733. }else
  734. {
  735. vvee2=vvee2+'0';
  736. }
  737. if (document.getElementById("d26").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  738. {
  739. vvee2=vvee2+'1';
  740. }else
  741. {
  742. vvee2=vvee2+'0';
  743. }
  744. if (document.getElementById("d27").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  745. {
  746. vvee2=vvee2+'1';
  747. }else
  748. {
  749. vvee2=vvee2+'0';
  750. }
  751. // alert(vvee2);
  752. if (document.getElementById("d31").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  753. {
  754. vvee3='1';
  755. //alert('bgreen');
  756. }else
  757. {
  758. vvee3='0';
  759. //alert('bgrey');
  760. }
  761. if (document.getElementById("d32").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  762. {
  763. vvee3=vvee3+'1';
  764. }else
  765. {
  766. vvee3=vvee3+'0';
  767. }
  768. if (document.getElementById("d33").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  769. {
  770. vvee3=vvee3+'1';
  771. }else
  772. {
  773. vvee3=vvee3+'0';
  774. }
  775. if (document.getElementById("d34").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  776. {
  777. vvee3=vvee3+'1';
  778. }else
  779. {
  780. vvee3=vvee3+'0';
  781. }
  782. if (document.getElementById("d35").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  783. {
  784. vvee3=vvee3+'1';
  785. }else
  786. {
  787. vvee3=vvee3+'0';
  788. }
  789. if (document.getElementById("d36").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  790. {
  791. vvee3=vvee3+'1';
  792. }else
  793. {
  794. vvee3=vvee3+'0';
  795. }
  796. if (document.getElementById("d37").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  797. {
  798. vvee3=vvee3+'1';
  799. }else
  800. {
  801. vvee3=vvee3+'0';
  802. }
  803. //alert(vvee3);
  804. var ktype = '1';
  805. if (vvee1=='0000000')
  806. {
  807. }else
  808. {
  809. ktype='2';
  810. st1 = document.getElementById("st1").value.replace(':','') ;
  811. et1= document.getElementById("et1").value.replace(':','') ;
  812. if (st1.length==0 || et1.length==0)
  813. {
  814. alert('請選擇時段1的起始與結束時間');
  815. return;
  816. }
  817. }
  818. if (vvee2=='0000000')
  819. {
  820. }else
  821. {
  822. ktype='2';
  823. st2 = document.getElementById("st2").value.replace(':','') ;
  824. et2= document.getElementById("et2").value.replace(':','') ;
  825. if (st2.length==0 || et2.length==0)
  826. {
  827. alert('請選擇時段2的起始與結束時間');
  828. return;
  829. }
  830. }
  831. if (vvee3=='0000000')
  832. {
  833. }else
  834. {
  835. ktype='2';
  836. st3 = document.getElementById("st3").value.replace(':','') ;
  837. et3= document.getElementById("et3").value.replace(':','') ;
  838. //alert(st3.length)
  839. if (st3.length==0 || et3.length==0)
  840. {
  841. alert('請選擇時段3的起始與結束時間');
  842. return;
  843. }
  844. }
  845. if (ktype=='2')
  846. {
  847. cycy=vvee1+','+st1 +','+ et1+','+ vvee2+','+st2+','+et2+','+vvee3+','+st3+','+et3;
  848. vcyd='';
  849. var vcy = cycy.split(',');
  850. let days=[];
  851. if (vcy[0]=='0000000')
  852. {
  853. }else
  854. {
  855. if (vcy[0].substring(0,1)=='1')
  856. days.push('日');
  857. if (vcy[0].substring(1,2)=='1')
  858. days.push('一');
  859. if (vcy[0].substring(2,3)=='1')
  860. days.push('二');
  861. if (vcy[0].substring(3,4)=='1')
  862. days.push('三');
  863. if (vcy[0].substring(4,5)=='1')
  864. days.push('四');
  865. if (vcy[0].substring(5,6)=='1')
  866. days.push('五');
  867. if (vcy[0].substring(6,7)=='1')
  868. days.push('六');
  869. vcy[1]=vcy[1].substring(0,2)+':'+vcy[1].substring(2,4);
  870. vcy[2]=vcy[2].substring(0,2)+':'+vcy[2].substring(2,4);
  871. vcyd=vcyd+'#1.'+vcy[1]+'~'+vcy[2]+' '+' '+days.join(',');
  872. }
  873. days=[];
  874. if (vcy[3]=='0000000')
  875. {
  876. }else
  877. {
  878. if (vcy[3].substring(0,1)=='1')
  879. days.push('日');
  880. if (vcy[3].substring(1,2)=='1')
  881. days.push('一');
  882. if (vcy[3].substring(2,3)=='1')
  883. days.push('二');
  884. if (vcy[3].substring(3,4)=='1')
  885. days.push('三');
  886. if (vcy[3].substring(4,5)=='1')
  887. days.push('四');
  888. if (vcy[3].substring(5,6)=='1')
  889. days.push('五');
  890. if (vcy[3].substring(6,7)=='1')
  891. days.push('六');
  892. vcy[4]=vcy[4].substring(0,2)+':'+vcy[4].substring(2,4);
  893. vcy[5]=vcy[5].substring(0,2)+':'+vcy[5].substring(2,4);
  894. vcyd=vcyd+'#2.'+vcy[4]+'~'+vcy[5]+' '+' '+days.join(',');
  895. }
  896. days=[];
  897. if (vcy[6]=='0000000')
  898. {
  899. }else
  900. {
  901. if (vcy[6].substring(0,1)=='1')
  902. days.push('日');
  903. if (vcy[6].substring(1,2)=='1')
  904. days.push('一');
  905. if (vcy[6].substring(2,3)=='1')
  906. days.push('二');
  907. if (vcy[6].substring(3,4)=='1')
  908. days.push('三');
  909. if (vcy[6].substring(4,5)=='1')
  910. days.push('四');
  911. if (vcy[6].substring(5,6)=='1')
  912. days.push('五');
  913. if (vcy[6].substring(6,7)=='1')
  914. days.push('六');
  915. vcy[7]=vcy[7].substring(0,2)+':'+vcy[7].substring(2,4);
  916. vcy[8]=vcy[8].substring(0,2)+':'+vcy[8].substring(2,4);
  917. vcyd=vcyd+'#3.'+vcy[7]+'~'+vcy[8]+' '+' '+days.join(',');
  918. }
  919. }
  920. else
  921. {
  922. //cycy='';
  923. }
  924. fincycle='';
  925. fincycle= document.getElementById("ItemNOSer").value+';';
  926. fincycle=fincycle+ vtstp+';';
  927. fincycle=fincycle+cycy+';';
  928. //alert(cycy);
  929. // alert(fincycle);
  930. if (orgcycle==fincycle)
  931. {
  932. issame=true;
  933. // alert('相同');
  934. }
  935. vtttt = document.getElementById("ItemNOSer").value;
  936. if (issame)
  937. {
  938. vsn='';
  939. try
  940. {
  941. vtttt = document.getElementById("ItemNOSer").value;
  942. var jsonString = "{\"action\":\"shareQr\", \"serial\":\"001\",\"data\":{\"name\":\""+kname+"\",\"note\":\""+vtttt+"\",\"QRCode\":\""+vvqrcd+"\",\"time\":\""+vtstpqr+"\",\"cycle\":\""+vcyd+"\"}}";
  943. if (TYPE=='IOS')
  944. {
  945. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  946. }
  947. if (TYPE=='ANDROID')
  948. {
  949. webSocket.send(jsonString);
  950. }
  951. if (TYPE=='PC')
  952. {
  953. shareQrPC(jsonString);
  954. }
  955. }catch(e)
  956. {
  957. //alert(e);
  958. alert('連線異常');
  959. }
  960. }
  961. else
  962. {
  963. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
  964. // alert(document.getElementById("ItemNOSer").value);
  965. vtttt = document.getElementById("ItemNOSer").value;
  966. // alert(ktype);
  967. // return;
  968. var edata456 ="{\"action\":\"mqttupdateRemoteKey\",\"data\":{\"Command\":\"PassWord="+PW+"&ReGenerate=1&Stat=1&Type="+ktype+"&IndexID="+idx+"&TimeStamp="+vtstp+"&Cycle="+cycy+"&UserID="+ID+"&Title="+vtttt+"\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  969. var jsonString333 = "{\"action\":\"encode\", \"serial\":\"003\",\"data\":"+edata456+"}";
  970. vsn='003';
  971. //updateOutput(jsonString);
  972. //alert(jsonString);
  973. //return;
  974. if (TYPE=='IOS')
  975. {
  976. window.webkit.messageHandlers.WebToApp.postMessage(jsonString333);
  977. }
  978. if (TYPE=='ANDROID')
  979. {
  980. webSocket.send(jsonString333);
  981. }
  982. if (TYPE=='PC')
  983. {
  984. selfendecode(edata456);
  985. }
  986. }
  987. }
  988. function btnitemback(vid)
  989. {
  990. try
  991. {
  992. //alert(vid);
  993. // alert(document.getElementById(vid).style.backgroundImage.slice(4, -1).replace(/"/g, ""));
  994. if (document.getElementById(vid).style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  995. {
  996. document.getElementById(vid).style.background="url('image/bgrey.png') no-repeat center/100%";
  997. }else
  998. {
  999. document.getElementById(vid).style.background="url('image/bgreen.png') no-repeat center/100%";
  1000. }
  1001. }catch(e)
  1002. {
  1003. alert(e);
  1004. }
  1005. }
  1006. function btndddel()
  1007. {
  1008. var yes = confirm('確定刪除?');
  1009. if (yes) {
  1010. try
  1011. {
  1012. //alert('ue');
  1013. //return;
  1014. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
  1015. // alert(document.getElementById("ItemNOSer").value);
  1016. vtttt = document.getElementById("ItemNOSer").value;
  1017. // alert(ktype);
  1018. // return;
  1019. var edata3 ="";
  1020. edata3 ="{\"action\":\"mqttdeleteRemoteKey\",\"data\":{\"Command\":\"PassWord="+PW+"&IndexID="+idx+"&UserID="+ID+"\",\"SerialNo\":\"Reserve"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  1021. // alert(edata);
  1022. var jsonString4 ="";
  1023. jsonString4 = "{\"action\":\"encode\", \"serial\":\"101\",\"data\":"+edata3+"}";
  1024. vsn='101';
  1025. // updateOutput(jsonString);
  1026. //alert(jsonString);
  1027. //return;
  1028. if (TYPE=='IOS')
  1029. {
  1030. window.webkit.messageHandlers.WebToApp.postMessage(jsonString4);
  1031. }
  1032. if (TYPE=='ANDROID')
  1033. {
  1034. webSocket.send(jsonString4);
  1035. }
  1036. if (TYPE=='PC')
  1037. {
  1038. selfendecode(edata3);
  1039. }
  1040. }
  1041. catch(e)
  1042. {
  1043. alert('連線異常');
  1044. }
  1045. } else {
  1046. }
  1047. }
  1048. function getdoorlist()
  1049. {
  1050. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
  1051. var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord="+PW+"\",\"SerialNo\":\"Reserve"+CID+"1\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  1052. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+edata+"}";
  1053. vsn='001';
  1054. // updateOutput(jsonString);
  1055. isget2=false;
  1056. if (TYPE=='IOS')
  1057. {
  1058. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1059. }
  1060. if (TYPE=='ANDROID')
  1061. {
  1062. webSocket.send(jsonString);
  1063. }
  1064. if (TYPE=='PC')
  1065. {
  1066. selfendecode(edata);
  1067. }
  1068. }
  1069. </script>
  1070. <script type="text/javascript">
  1071. var webSocket;
  1072. var input = document.getElementById("input")
  1073. var output = document.getElementById("output");
  1074. var vdata="";
  1075. var isok=true;
  1076. var webSocket;
  1077. //var connectBtn = document.getElementById("connectBtn");
  1078. //var wsUrl = "ws://localhost:2980/";
  1079. // var wsUrl = "ws://192.168.0.27:2980/";
  1080. // var wsUrl = "ws://192.168.0.30:2980/";
  1081. var wsUrl = "ws://127.0.0.1:2980/";
  1082. //var wsUrl = "ws://192.168.0.25:2980/";
  1083. function connect()
  1084. {
  1085. // open the connection if one does not exist
  1086. if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED)
  1087. {
  1088. return;
  1089. }
  1090. // updateOutput("Trying to establish a WebSocket connection to <code>" + wsUrl + "</code>");
  1091. // Create a websocket
  1092. webSocket = new WebSocket(wsUrl);
  1093. webSocket.onopen = function(event) {
  1094. };
  1095. webSocket.onmessage = function(event)
  1096. {
  1097. var ress = event.data;
  1098. if (is2=='001' )
  1099. {
  1100. var vobj = JSON.parse( ress);
  1101. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}");
  1102. message4.destinationName = SN ;
  1103. message4.retained = false;
  1104. message4.qos = 0;
  1105. client.send(message4);
  1106. is2='002';
  1107. }
  1108. if (is2=='002' )
  1109. {
  1110. var vobj = JSON.parse(ress);
  1111. if (vobj.success===true)
  1112. {
  1113. alert('OK');
  1114. }
  1115. else
  1116. {
  1117. alert('失敗');
  1118. }
  1119. is2='';
  1120. }
  1121. };
  1122. webSocket.onclose = function(event) {
  1123. // updateOutput("Connection Closed");
  1124. //connectBtn.disabled = false;
  1125. //sendBtn.disabled = true;
  1126. };
  1127. }
  1128. function shareQr() {
  1129. var text = input.value;
  1130. var jsonString = "{\"action\":\"shareQr\", \"serial\":\"001\",\"data\":\""+text+"\"}";
  1131. //updateOutput(jsonString);
  1132. /// "WebToApp". 為我們和前端開發人員的約定
  1133. if (TYPE=='IOS')
  1134. {
  1135. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1136. }
  1137. if (TYPE=='ANDROID')
  1138. {
  1139. webSocket.send(jsonString);
  1140. }
  1141. }
  1142. function shareQrPC(message) {
  1143. message=message.replaceAll('=','-');
  1144. message=message.replaceAll('#','*');
  1145. // alert('shareQrPC '+message);
  1146. //alert("index4.html?idx="+vvvi+"&tt="+"&qrcd=&cy="+"&name="+kname+"&st="+"&et="+"&tp=1"+"&CID="+CID+"&ID="+kkid+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID);
  1147. document.location = "index4.html?idx="+vvvi+"&tt="+"&qrcd=&cy="+"&name="+kname+"&st="+"&et="+"&tp=1"+"&CID="+CID+"&ID="+kkid+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID+"&sqr="+message;
  1148. }
  1149. //self start
  1150. function selfendecode(message) {
  1151. if (vsn=='002'||vsn=='103')
  1152. {
  1153. isget=true;
  1154. // alert(vsn);
  1155. message = teaDecrypt(message,'75$095huOQ77kKv!');
  1156. // alert('002 or 103 '+message);
  1157. var ress = message;
  1158. vsn='104';
  1159. try
  1160. {
  1161. // var vobj = JSON.parse( ress);
  1162. //alert( vobj.data);
  1163. //var sevobj = JSON.parse( vobj);
  1164. // alert('de'+ ress);
  1165. senttoother();
  1166. alert('OK');
  1167. //23456
  1168. window.history.go(-1);
  1169. //document.location = "index2.html?KID="+ID +"&name="+ kname;
  1170. }catch(e)
  1171. {
  1172. alert(e);
  1173. }
  1174. }
  1175. if (vsn=='004')
  1176. {
  1177. //alert('004');
  1178. vsn='';
  1179. message = teaDecrypt(message,'75$095huOQ77kKv!');
  1180. isget3 = true;
  1181. var ress = message;
  1182. try
  1183. {
  1184. // alert('de'+ ress);
  1185. vobj = JSON.parse( ress);
  1186. var qrcd= vobj.data.CardID;
  1187. alert('004 '+message);
  1188. // var qrcd= vobj.data.data.CardID;
  1189. // alert( qrcd);
  1190. //var sevobj = JSON.parse( vobj);
  1191. // alert('de'+ ress);
  1192. //alert('OK');
  1193. //window.history.go(-1);
  1194. //document.location = "index2.html?KID="+ID +"&name="+ kname;
  1195. //"name":"健身房","note":"王大明09123456789","QRCode":"KaiZvhWz5dcUqkkuvAK0q6T/iw4dbE7CpGKDozTFL2LkH6g1YRdayW=="
  1196. // alert(vtttt);
  1197. //vcyd
  1198. var jsonString = "{\"action\":\"shareQr\", \"serial\":\"001\",\"data\":{\"name\":\""+kname+"\",\"note\":\""+vtttt+"\",\"QRCode\":\""+qrcd+"\",\"time\":\""+vtstpqr+"\",\"cycle\":\""+vcyd+"\"}}";
  1199. // alert(jsonString);
  1200. // updateOutput(jsonString);
  1201. /// "WebToApp". 為我們和前端開發人員的約定
  1202. orgcycle=fincycle;
  1203. vvqrcd=qrcd;
  1204. senttoother();
  1205. if (TYPE=='IOS')
  1206. {
  1207. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1208. }
  1209. if (TYPE=='ANDROID')
  1210. {
  1211. webSocket.send(jsonString);
  1212. }
  1213. if (TYPE=='PC')
  1214. {
  1215. shareQrPC(jsonString);
  1216. }
  1217. }catch(e)
  1218. {
  1219. alert(e);
  1220. }
  1221. }
  1222. if (vsn=='001')
  1223. {
  1224. try
  1225. {
  1226. // alert( '001');
  1227. message = teaEncrypt(message,'75$095huOQ77kKv!');
  1228. var ress = message;
  1229. // alert( ress);
  1230. isget2=true;
  1231. // vobj = JSON.parse( ress);
  1232. isget=false;
  1233. // vdata = "{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}";
  1234. }catch(e)
  1235. {
  1236. alert(e);
  1237. }
  1238. //updateOutput('---------------------------');
  1239. // updateOutput(vdata);
  1240. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  1241. message4.destinationName = SN ;
  1242. message4.retained = false;
  1243. message4.qos = 0;
  1244. var vivi = 0;
  1245. // client.send(message);
  1246. var intervalID = setInterval(() => {
  1247. if (isget)
  1248. {
  1249. }
  1250. else
  1251. {
  1252. if (vivi>15)
  1253. {
  1254. clearInterval(intervalID);
  1255. alert('連線異常');
  1256. }else
  1257. {
  1258. vivi++;
  1259. if (isconn)
  1260. {
  1261. client.send(message4);
  1262. }
  1263. }
  1264. }
  1265. }, 400);
  1266. }
  1267. if (vsn=='101')
  1268. {
  1269. try
  1270. {
  1271. vsn='102';
  1272. // alert( '102');
  1273. message = teaEncrypt(message,'75$095huOQ77kKv!');
  1274. var ress = message;
  1275. // alert( ress);
  1276. // vobj = JSON.parse( ress);
  1277. isget=false;
  1278. // vdata = "{\"encrypt\":\"1\",\"data\":\""+message+"\"}";
  1279. //updateOutput('---------------------------');
  1280. // updateOutput(vdata);
  1281. message9 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  1282. message9.destinationName = SN ;
  1283. message9.retained = false;
  1284. message9.qos = 0;
  1285. var vivi = 0;
  1286. // client.send(message);
  1287. var intervalID = setInterval(() => {
  1288. if (isget)
  1289. {
  1290. }
  1291. else
  1292. {
  1293. if (vivi>15)
  1294. {
  1295. clearInterval(intervalID);
  1296. alert('連線異常');
  1297. }else
  1298. {
  1299. if (isconn)
  1300. {
  1301. client.send(message9);
  1302. }
  1303. vivi++;
  1304. }
  1305. }
  1306. }, 400);
  1307. }catch(e)
  1308. {
  1309. alert(e);
  1310. }
  1311. }
  1312. if (vsn=='003')
  1313. {
  1314. try
  1315. {
  1316. // alert( '003');
  1317. message = teaEncrypt(message,'75$095huOQ77kKv!');
  1318. var ress = message;
  1319. // alert( ress);
  1320. // vobj = JSON.parse( ress);
  1321. isget3=false;
  1322. // vdata = "{\"encrypt\":\"1\",\"data\":\""+message+"\"}";
  1323. }catch(e)
  1324. {
  1325. alert(e);
  1326. }
  1327. //updateOutput('---------------------------');
  1328. // updateOutput(vdata);
  1329. message6= new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  1330. message6.destinationName = SN ;
  1331. message6.retained = false;
  1332. message6.qos = 0;
  1333. //setTimeout(() => {
  1334. var vivi = 0;
  1335. var intervalID = setInterval(() => {
  1336. if (isget3)
  1337. {
  1338. }
  1339. else
  1340. {
  1341. if (vivi>15)
  1342. {
  1343. alert('連線異常');
  1344. clearInterval(intervalID);
  1345. }else
  1346. {
  1347. vivi++;
  1348. if (isconn)
  1349. {
  1350. client.send(message6);
  1351. }
  1352. }
  1353. }
  1354. }, 400);
  1355. }
  1356. // updateOutput(message);
  1357. }
  1358. //self end
  1359. function AppToWeb(message)
  1360. {
  1361. if (is2=='001' )
  1362. {
  1363. var vobj = JSON.parse( message);
  1364. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}");
  1365. message4.destinationName = SN ;
  1366. message4.retained = false;
  1367. message4.qos = 0;
  1368. client.send(message4);
  1369. is2='002';
  1370. }
  1371. else
  1372. {
  1373. var ress = message;
  1374. var vobj = JSON.parse(ress);
  1375. if (vobj.success===true)
  1376. {
  1377. alert('OK');
  1378. }
  1379. else
  1380. {
  1381. alert('失敗');
  1382. }
  1383. is2='';
  1384. }
  1385. }
  1386. function endode() {
  1387. var text = input.value;
  1388. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+text+"}";
  1389. // updateOutput(jsonString);
  1390. /// "WebToApp". 為我們和前端開發人員的約定
  1391. if (TYPE=='IOS')
  1392. {
  1393. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1394. }
  1395. if (TYPE=='ANDROID')
  1396. {
  1397. webSocket.send(jsonString);
  1398. }
  1399. }
  1400. function decode() {
  1401. var text = input.value;
  1402. var jsonString = "{\"action\":\"decode\", \"serial\":\"001\",\"data\":\""+text+"\"}";
  1403. //updateOutput(jsonString);
  1404. /// "WebToApp". 為我們和前端開發人員的約定
  1405. if (TYPE=='IOS')
  1406. {
  1407. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1408. }
  1409. if (TYPE=='ANDROID')
  1410. {
  1411. webSocket.send(jsonString);
  1412. }
  1413. }
  1414. function updateOutput(text) {
  1415. output.innerHTML += "<br/>" + text;
  1416. }
  1417. </script>
  1418. <script>
  1419. var getUrlParameter = function getUrlParameter(sParam) {
  1420. var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  1421. sURLVariables = sPageURL.split('&'),
  1422. sParameterName,
  1423. i;
  1424. for (i = 0; i < sURLVariables.length; i++) {
  1425. sParameterName = sURLVariables[i].split('=');
  1426. if (sParameterName[0] === sParam) {
  1427. return sParameterName[1] === undefined ? true : sParameterName[1];
  1428. }
  1429. }
  1430. };
  1431. Date.prototype.format = function (format) {
  1432. //eg:format="yyyy-MM-dd hh:mm:ss";
  1433. if (!format) {
  1434. format = "yyyy-MM-dd hh:mm:ss";
  1435. }
  1436. var o = {
  1437. "M+": this.getMonth() + 1, // month
  1438. "d+": this.getDate(), // day
  1439. "H+": this.getHours(), // hour
  1440. "h+": this.getHours(), // hour
  1441. "m+": this.getMinutes(), // minute
  1442. "s+": this.getSeconds(), // second
  1443. "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
  1444. "S": this.getMilliseconds()
  1445. };
  1446. if (/(y+)/.test(format)) {
  1447. format = format.replace(RegExp.$1, (this.getFullYear() + "")
  1448. .substr(4 - RegExp.$1.length));
  1449. }
  1450. for (var k in o) {
  1451. if (new RegExp("(" + k + ")").test(format)) {
  1452. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  1453. ? o[k]
  1454. : ("00" + o[k]).substr(("" + o[k]).length));
  1455. }
  1456. }
  1457. return format;
  1458. };
  1459. </script>
  1460. <br>
  1461. </body>
  1462. </html>