n/programu/liuyewen · 2025-10-11
注册 登录
n/program · 2025-10-11 · 476 次浏览
u/liuyewen钻石

写了一个WiFi 二维码生成器

不知道大家有没有同感,每次有朋友来家里,都要手动输一遍又长又复杂的 WiFi 密码,非常麻烦。
所以写了一个WiFi 二维码生成器,有兴趣的朋友可以看看。
网站链接: https://wifi.284628.xyz
只需输入网络名称(SSID)和密码,即可生成一个可直接扫码连接的二维码。
源码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>WiFi 二维码生成器 | 一键生成可扫码连接的 WiFi 二维码</title>

  <meta name="description" content="WiFi 二维码生成器是一款简洁高效的在线工具,支持 WPA/WPA2/WPA3、WEP 和无密码网络。输入 WiFi 名称与密码即可生成二维码,手机扫码即可自动连接网络。">
  <meta name="keywords" content="WiFi 二维码生成器, WiFi QR Code, 在线 WiFi 二维码, 无需手动输入密码, 一键连接 WiFi, WiFi 分享工具, 免费二维码生成, WPA3, WPA2, WEP">

  <meta property="og:title" content="WiFi 二维码生成器">
  <meta property="og:description" content="快速生成可扫码连接的 WiFi 二维码,支持多种加密方式,手机一扫即可上网。">
  <meta property="og:type" content="website">
  <meta property="og:image" content="https://i.284628.xyz/OHnT6DwC.webp">
  <meta property="og:locale" content="zh_CN">

  <link rel="icon" href="https://i.284628.xyz/OHnT6DwC.webp" type="image/png">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
  <style>
    @font-face {
      font-family: "Geist";
      src: url("/fonts/geist-variable.woff2") format("woff2");
      font-display: swap;
    }

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      color: #171717;
      background-color: #ffffff;
      line-height: 1.5;
      -webkit-font-smoothing: antialiased;
    }

    .container {
      max-width: 36rem;
      margin: 0 auto;
      padding: 1rem;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }

    h1 {
      font-size: 1.5rem;
      font-weight: 600;
      margin-bottom: 1rem;
      text-align: center;
    }

    .description {
      color: #555;
      margin-bottom: 1.5rem;
      text-align: center;
    }

    .form-group {
      margin-bottom: 1rem;
    }

    label {
      display: block;
      font-weight: 500;
      margin-bottom: 0.5rem;
      color: #171717;
    }

    input, select {
      width: 100%;
      padding: 0.75rem 1rem;
      border: 1px solid #d4d4d4;
      border-radius: 0.5rem;
      font-family: inherit;
      font-size: 0.9rem;
      background-color: #fff;
      color: #171717;
      transition: all 0.2s ease;
    }

    input:focus, select:focus {
      outline: none;
      border-color: #3b82f6;
      box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
    }

    select {
      appearance: none;
      background-image: url('data:image/svg+xml;utf8,<svg fill="%23666" height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M4 6l4 4 4-4z"/></svg>');
      background-repeat: no-repeat;
      background-position: right 0.75rem center;
      background-size: 0.8rem;
      cursor: pointer;
    }

    select:hover {
      border-color: #999;
    }

    .button-group {
      display: flex;
      gap: 0.75rem;
      margin-top: 1.5rem;
    }

    button {
      flex: 1;
      padding: 0.75rem;
      border: 1px solid #d4d4d4;
      border-radius: 0.5rem;
      font-size: 0.9rem;
      font-weight: 500;
      cursor: pointer;
      background-color: #fff;
      color: #171717;
      transition: all 0.2s ease;
    }

    button:hover {
      background-color: #f3f4f6;
    }

    .qr-container {
      margin-top: 2rem;
      padding: 1.5rem;
      border: 1px solid #e5e5e5;
      border-radius: 0.75rem;
      background-color: #fafafa;
      text-align: center;
      display: none;
    }

    #qrcode {
      display: inline-block;
      padding: 1rem;
      background: white;
      border-radius: 0.5rem;
      margin-bottom: 1rem;
    }

    .qr-info {
      font-size: 0.875rem;
      color: #555;
      margin-bottom: 1rem;
    }

    .download-btn {
      display: inline-flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.75rem 1.5rem;
      background-color: #3b82f6;
      color: white;
      border: none;
      border-radius: 0.5rem;
      font-weight: 500;
      cursor: pointer;
      transition: background-color 0.2s ease;
    }

    .download-btn:hover {
      background-color: #2563eb;
    }
  </style>
</head>
<body>
  <div class="container">
    <main>
      <h1>WiFi 二维码生成器</h1>
      <p class="description">
        这是一款简单易用的 WiFi 二维码生成工具。只需输入网络名称(SSID)和密码,即可生成一个可直接扫码连接的二维码。支持 WPA/WPA2/WPA3、WEP 以及无密码网络,适合家庭、咖啡厅、公司访客等场景。
      </p>

      <div class="form-group">
        <label for="ssid">网络名称 (SSID)</label>
        <input type="text" id="ssid" placeholder="请输入 WiFi 名称" autocomplete="off">
      </div>

      <div class="form-group">
        <label for="password">密码</label>
        <input type="text" id="password" placeholder="请输入 WiFi 密码" autocomplete="off">
      </div>

      <div class="form-group">
        <label for="encryption">加密类型</label>
        <select id="encryption">
          <option value="WPA">WPA/WPA2/WPA3</option>
          <option value="WEP">WEP</option>
          <option value="nopass">无密码</option>
        </select>
      </div>

      <div class="button-group">
        <button id="generate-btn">生成二维码</button>
        <button id="reset-btn">重置</button>
      </div>

      <div class="qr-container" id="qr-container">
        <div id="qrcode"></div>
        <p class="qr-info">扫描二维码即可连接到 WiFi 网络</p>
        <button class="download-btn" id="download-btn">
          下载二维码
        </button>
      </div>
    </main>
  </div>

  <script>
    let qrcode = null;

    function generateQRCode() {
      const ssid = document.getElementById("ssid").value.trim();
      const password = document.getElementById("password").value;
      const encryption = document.getElementById("encryption").value;

      if (!ssid) {
        alert("请输入网络名称");
        return;
      }

      if (encryption !== "nopass" && !password) {
        alert("请输入密码");
        return;
      }

      const qrContainer = document.getElementById("qr-container");
      const qrcodeDiv = document.getElementById("qrcode");
      qrcodeDiv.innerHTML = "";

      const wifiString = encryption === "nopass"
        ? `WIFI:T:nopass;S:${ssid};;`
        : `WIFI:T:${encryption};S:${ssid};P:${password};H:false;;`;

      qrcode = new QRCode(qrcodeDiv, {
        text: wifiString,
        width: 256,
        height: 256,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
      });

      qrContainer.style.display = "block";
      qrContainer.scrollIntoView({ behavior: "smooth", block: "nearest" });
    }

    function resetForm() {
      document.getElementById("ssid").value = "";
      document.getElementById("password").value = "";
      document.getElementById("encryption").value = "WPA";
      document.getElementById("qr-container").style.display = "none";
      qrcode = null;
    }

    function downloadQRCode() {
      const canvas = document.querySelector("#qrcode canvas");
      if (!canvas) return;

      const padding = 32;
      const newCanvas = document.createElement("canvas");
      const ctx = newCanvas.getContext("2d");
      newCanvas.width = canvas.width + padding * 2;
      newCanvas.height = canvas.height + padding * 2;

      ctx.fillStyle = "#ffffff";
      ctx.fillRect(0, 0, newCanvas.width, newCanvas.height);
      ctx.drawImage(canvas, padding, padding);

      const link = document.createElement("a");
      link.download = `wifi-qrcode-${document.getElementById("ssid").value}.png`;
      link.href = newCanvas.toDataURL("image/png");
      link.click();
    }

    document.getElementById("generate-btn").addEventListener("click", generateQRCode);
    document.getElementById("reset-btn").addEventListener("click", resetForm);
    document.getElementById("download-btn").addEventListener("click", downloadQRCode);
  </script>
</body>
</html>
4
27
登录后参与讨论。
u/deleted 广告
海外原生IP VPS,稳定访问全球网络

还在为IP不纯、平台风控、频繁验证而烦恼? 丽萨主机海外原生IP VPS,双ISP住宅IP,覆盖美国、香港、日本、新加坡、台湾、德国、越南、英国等热门地区,适合跨境电商、社媒运营、AI工具、流媒体及海外业务使用。

lisahost.com 了解更多

27 条回复

排序
  1. Arvin_Leung 荣耀 3 YEARS 2025-10-11

    谢谢分享。
    访客是访客段,自己在家里用是另外一个段。访客不用密码省事

    1
  2. liuyewen 钻石 楼主 传奇 2025-10-11

    家里没有高级的路由器 :xhj17:

    0
  3. Arvin_Leung 荣耀 3 YEARS 2025-10-11

    手机也可以分享WIFI密码的哦

    0
  4. liuyewen 钻石 楼主 传奇 2025-10-11

    是的哇,写完才发现 :xhj17:

    0
  5. user68 💬 铂金 3 YEARS 2025-10-11

    感谢分享,楼主厉害

    0
  6. trial 钻石 钻石会员 2025-10-11

    自己动手,丰衣足食😄

    0
  7. cs9u 钻石 钻石会员 2025-10-11

    支持中文热点和中文密码。 :xhj001:

    0
  8. liuyewen 钻石 楼主 传奇 2025-10-11

    中文还没做

    0
  9. Speeeed 📚 铂金 2 YEARS 2025-10-12

    这个不错不错!

    0
  10. LOsEE 钻石 伯乐 2025-10-12

    感谢分享

    0
  11. imluckyboy 铂金 3 YEARS 2025-10-12

    有没有觉得ssid比密码还复杂,你输入ssid和密码再去生成岂不是更麻烦一点,不过二维码只需要生成一次即可长期使用。

    0
  12. liuyewen 钻石 楼主 传奇 2025-10-12

    是的啊,但主要还是想折腾 :xhj20:

    0
  13. Speeeed 📚 铂金 2 YEARS 2025-10-12

    liuyewen:
    https://wifi.284628.xyz

    我用这个站生成了我家里的wifi二维码,用啥扫描都是一串字符串,并不能自动连接。

    0
  14. liuyewen 钻石 楼主 传奇 2025-10-12

    可以哇,微信扫一扫和中文不支持,需要支付宝或者相机

    0
  15. azhaoyihao 荣耀 水王 2025-10-12

    这感觉还不如一样 还是要输入密码

    0
  16. liuyewen 钻石 楼主 传奇 2025-10-12

    折腾! :xhj20:

    0
  17. iqicq 黄金 2025-10-12

    密码简单点,12345678就行了,现在谁家还没个宽带,不怕蹭网,就算有些人蹭的太厉害了,直接禁了他的mac不就得了

    0
  18. saas 黄金 2025-10-12

    wifi生成二维码一直都有,主要是能不能上微信,大多数人会用微信来扫二维码,你这个能识别并跳转吗?

    0
  19. Hoog2025 💬 钻石 2025-10-12

    和自带的有什么区别

    0
  20. Sapphirecho8 黄金 2025-10-13

    这个不错!

    0
  21. daryenr 黄金 2025-10-13

    历害

    0
  22. unpack 黄金 2 YEARS 2025-10-13

    涨知识了,原来好多不行的是不支持微信

    0
  23. lbj 铂金 3 YEARS 2025-10-13

    为你的折腾精神点赞

    0
  24. marvinli001 富可敌国 黄金 不离不弃 2025-10-13

    这个我记得多少年前我还在初中的时候草料二维码就可以生成wifi二维码了,今夕是何年

    0
  25. marvinli001 富可敌国 黄金 不离不弃 2025-10-13

    其实我觉得做一个nfc的生成wifi更好点,访客tab就自动链接加入

    0
  26. marvinli001 富可敌国 黄金 不离不弃 2025-10-13

    可能不是草料当年手机上有一个免费的AppStore工具可以生成任意类型的二维码

    0
  27. wjx355 黄金 2025-10-13

    感谢分享,听说二维码是小日本发明得是不?

    0