自己做的wiwiz自定義認證頁面代碼,支持Cookie和自動登錄

一直覺得Wiwiz自帶的認證頁面不太方便,尤其是不支持Cookie,這樣每次認證時都需要手動輸入認證信息,會比較麻煩。
我利用自定義認證頁面的定製代碼,加入了記錄和處理Cookie的功能,用Javascript實現的。
這裏分享給大家,誰需要請拿去用吧。

認證頁面效果圖:

認證頁面HTML代碼:

  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  4. <meta http-equiv="Pragma" content="no-cache"> 
  5. <meta http-equiv="Cache-Control" content="no-cache"> 
  6. <meta name="viewport" content="user-scalable=no, width=device-width" />   
  7.   
  8. <!-- 必須引入AuthPageScript.js --> 
  9. <script src="/as/AuthPageScript.js"></script> 
  10. <script> 
  11.  
  12.  
  13. /* 讀寫Cookie的函數 */ 
  14. function SetCookie(name,value) { 
  15.     var Days = 180
  16.     var exp  = new Date(); 
  17.     exp.setTime(exp.getTime() + Days*24*60*60*1000); 
  18.     document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
  19.  
  20. function getCookie(name) { 
  21.     var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); 
  22.     if(arr != null)  
  23.         return unescape(arr[2]);  
  24.     return ""; 
  25.  
  26. /* 用於在認證時記錄Cookie */ 
  27. function recordCookie() { 
  28.     if(document.getElementById("remember").checked == false) 
  29.         return; 
  30.     else { 
  31.         var u = document.getElementById("username").value; 
  32.         var p = document.getElementById("pswd").value; 
  33.          
  34.         SetCookie("wifi-user", u); 
  35.         SetCookie("wifi-pswd", p); 
  36.     } 
  37.  
  38. /* 頁面初始化是讀入Cookie並自動按下認證按鈕 */ 
  39. function doInit() { 
  40.     var u = getCookie("wifi-user"); 
  41.     var p = getCookie("wifi-pswd"); 
  42.      
  43.     if(u != "") { 
  44.         document.getElementById("username").value = u; 
  45.         document.getElementById("pswd").value = p
  46.          
  47.         document.getElementById("login").click(); 
  48.     } 
  49.   
  50. /* 回調函數。“獲取驗證碼”按鈕按下後,將自動調用此函數。可根據code值自行改寫該函數。 */ 
  51. function WiwizSmsVerifyMsg(code) { 
  52.     if      (code == "-1") { 
  53.         alert("手機號碼不可爲空!"); 
  54.     } else if(code == "0") { 
  55.         alert("驗證碼已通過短信發送至您的手機,請注意查收。然後請在認證頁面輸入驗證碼。"); 
  56.     } else if(code == "1") { 
  57.         alert("該熱點不允許進行手機號碼驗證。如有疑問請您聯繫熱點管理員。"); 
  58.     } else if(code == "2") { 
  59.         alert("該熱點不允許進行手機號碼驗證。如有疑問請您聯繫熱點管理員。"); 
  60.     } else if(code == "3") { 
  61.         alert("該手機號碼不允許進行驗證。如有疑問請您聯繫熱點管理員。"); 
  62.     } else if(code == "4") { 
  63.         alert("手機號碼驗證過於頻繁,請稍後再試。"); 
  64.     } else if(code == "5") { 
  65.         alert("該手機號碼進行驗證次數已超過今日上限。"); 
  66.     } else if(code == "6") { 
  67.         alert("熱點認證服務已暫停,不可進行手機驗證。"); 
  68.     } else if(code == "7") { 
  69.         alert("該熱點手機驗證次數已超過配額。請聯繫熱點管理員。"); 
  70.     } else if(code == "8") { 
  71.         alert("請求已超時,請刷新認證頁面。"); 
  72.     } else if(code == "9") { 
  73.         alert("請使用上一次通過短信接收到的驗證碼。"); 
  74.     } else if(code == "99") { 
  75.         alert("驗證短信發送失敗。請檢查手機號碼的有效性,或聯繫熱點管理員。"); 
  76.     } else if(code == "999") { 
  77.         alert("系統異常,驗證短信發送失敗。請聯繫熱點管理員。"); 
  78.     } else { 
  79.         alert("系統異常。請聯繫熱點管理員。"); 
  80.     } 
  81.   
  82. /* 回調函數。“認證”按鈕按下後,如報錯將自動調用此函數。可根據code值自行改寫該函數。 */ 
  83. function WiwizAuthPageError(code) { 
  84.     if       (code == 1) { 
  85.         alert("您無法使用此網絡,除非您認同此協議條款。"); 
  86.     } else if(code == 2) { 
  87.         alert("請輸入用戶名。"); 
  88.     } else if(code == 3) { 
  89.         alert("用戶名或密碼錯誤。"); 
  90.     } else if(code == 4) { 
  91.         alert("電子招待券無效。"); 
  92.     } else if(code == 6) { 
  93.         alert("超過最大在線用戶數。"); 
  94.     } else if(code == 7) { 
  95.         alert("請輸入手機號碼。"); 
  96.     } else if(code == 32) { 
  97.         alert("賬戶存在異常,暫時鎖定中。"); 
  98.     } else if(code == 35) { 
  99.         alert("手機驗證碼錯誤或已超時。"); 
  100.     } else { 
  101.         alert("未知錯誤。錯誤碼:"+ code); 
  102.     } 
  103. </script> 
  104. </head> 
  105. <body onload="doInit();"> 
  106.   
  107. <form name="myform" id="myform" action="" method="post">  
  108.   
  109. <center> 
  110.  
  111. <table width="320" bgcolor="#ffffff"> 
  112. <tr><td align="center"> 
  113. <br> 
  114. <table width="100%" cellspacing="2" cellpadding="2"> 
  115. <tr align="center"><td> 
  116. <font size="+2" color="#000000"><b>Wifi無線網絡 - 10M帶寬 </b> </font> 
  117. </td></tr> 
  118.  
  119. <tr align="center"><td> 
  120. <img src="/as/img/wiwiz.gif"></img> 
  121. </td></tr> 
  122. </table> 
  123.  
  124. <table width="99%" cellspacing="1" cellpadding="2" style="font-size:12px"> 
  125. <tr align="center"> 
  126.     <td width="100%">    
  127.         <table style="font-size:12px" width="98%"> 
  128.         <tr><td> 
  129.         <font color="#ff1111"> 
  130.         本熱點爲計費WiFi熱點。費率爲: 
  131.         3元/日 
  132.         50元/月 
  133.         </font> 
  134.         </td></tr> 
  135.         </table> 
  136.          
  137.  
  138.  
  139.         <table style="font-size:12px" width="100%"> 
  140.         <tr> 
  141.         <td align="center"> 
  142.              
  143.             在使用此網絡之前,請您詳細閱讀使用條款。<br> 
  144.             <textarea readonly rows="4" style="width:87%;font-size:12px">條款內容</textarea> 
  145.             <br> 
  146.             <!-- 參數: agree 代表認同協議 --> 
  147.             <input name="agree" id="agree" type="checkbox" value="1" checked /> 
  148.             <label for="agree">我完全同意此條款的內容。</label> 
  149.         </td> 
  150.         </tr> 
  151.         </table>     
  152.          
  153.     </td> 
  154. </tr> 
  155. </table> 
  156.  
  157. <table width="100%" cellspacing="1" cellpadding="4" style="font-size:12px"> 
  158. <tr align="center"> 
  159.     <td width="100%"> 
  160.      
  161.          
  162.         <table style="font-size:12px"> 
  163.         <tr> 
  164.             <td>用戶名: </td> 
  165.             <td><!-- 參數: username 代表用戶名 --> 
  166.                 <input name="username" id="username" type="text" value="" style="width:140px" /> 
  167.              
  168.             </td> 
  169.         </tr> 
  170.         <tr> 
  171.             <td>密碼: </td> 
  172.             <td><!-- 參數: pswd 代表密碼 --> 
  173.                 <input name="pswd" id="pswd" type="password" style="width:140px" /> 
  174.             </td> 
  175.         </tr> 
  176.         </table> 
  177.          
  178.         <input name="remember" id="remember" type="checkbox" value="1" checked /><label for="remember">下次自動登錄</label> 
  179.         <br><br> 
  180.         <!-- 用於開始觸發認證的按鈕,onclick事件必須調用WiwizStartAuth()函數 --> 
  181.         <!-- recordCookie函數用於處理記錄Cookie -->      
  182.         <input type="button" name="login" id="login" value="   立即開始使用此網絡   " onclick="recordCookie(); WiwizStartAuth();" /> 
  183.          
  184.         <br> 
  185.         <br> 
  186.         <font size="-1"><b><a href="#" onclick="window.open('http://cp.wiwiz.com/as/s/viewhotspot/?gw_id='+ WiwizGetQueryParameter('gw_id')); return false;">更多信息</a></font></b> 
  187.         <br> 
  188.         <br> 
  189.         <font style="font-size:12px"><b> 
  190.         <a href="/as/s/register/" target="_blank">註冊</a> &nbsp; | &nbsp;  
  191.         <a href="/as/s/remindpswd/" target="_blank">忘記密碼?</a> 
  192.         </b></font>  
  193.     </td> 
  194. </tr> 
  195. </table> 
  196.  
  197. </td></tr></table> 
  198.  
  199. <br> 
  200. </center> 
  201.   
  202. </form> 
  203. </body></html> 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章