不知道大家有没有同感,每次有朋友来家里,都要手动输一遍又长又复杂的 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


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