wifi 二维码生成

小米手机的 wifi 可以生成二维码,通过扫码连接 wifi。当然,凡事都是两面性,好的方面,当然是即使忘记密码,也能让另一台手机连上网络,而且不用手输入密码;而坏的方面是,二维码是可解析的,知道二维码就知道 wifi 的密码。

二维码知识

本节内容来自 二维码知识

二维码格式

类型说明
文本 text直接生成,无需处理
网址 url直接生成,无需处理(如果前缀加上 url: 在微信中不能自动跳转)
名片 mecardMECARD:N: 小明;TEL:13723456789;EMAIL:payonesmile@qq.com;ADR: 广州天河区;ORG:xx 有限公司;URL:http://pro.wwei.cn/;NOTE:QQ:13783821;
电话 teltel:13723456789
邮箱 mailmailto:payonesmile@qq.com
短信 smssmsto:13723456789: 短信内容
无线网络 WIFIWIFI:S:CMCC;P:123456;T:WPA/WPA2;

二维码纠错级别

纠错级别越高,生成图片会越大。

L 水平 7%的字码可被修正

M 水平 15%的字码可被修正

Q 水平 25%的字码可被修正

H 水平 30%的字码可被修正

WIFI 二维码

本节内容来自 https://github.com/zxing/zxing/wiki/Barcode-Contents

We propose a syntax like “MECARD” for specifying wi-fi configuration. Scanning such a code would, after prompting the user, configure the device’s Wi-Fi accordingly. Example:

1
WIFI:T:WPA;S:mynetwork;P:mypass;;
ParameterExampleDescription
TWPAAuthentication type; can be WEP or WPA or WPA2-EAP, or nopass for no password. Or, omit for no password.
SmynetworkNetwork SSID. Required. Enclose in double quotes if it is an ASCII name, but could be interpreted as hex (i.e. “ABCD”)
PmypassPassword, ignored if T is nopass (in which case it may be omitted). Enclose in double quotes if it is an ASCII name, but could be interpreted as hex (i.e. “ABCD”)
HtrueOptional. True if the network SSID is hidden. Note this was mistakenly also used to specify phase 2 method in releases up to 4.7.8 / Barcode Scanner 3.4.0. If not a boolean, it will be interpreted as phase 2 method (see below) for backwards-compatibility
ETTLS(WPA2-EAP only) EAP method, like TTLS or PWD
Aanon(WPA2-EAP only) Anonymous identity
Imyidentity(WPA2-EAP only) Identity
PH2MSCHAPV2(WPA2-EAP only) Phase 2 method, like MSCHAPV2

Order of fields does not matter. Special characters \, ;,, and : should be escaped with a backslash (\) as in MECARD encoding. For example, if an SSID was literally "foo;bar\baz" (with double quotes part of the SSID name itself) then it would be encoded like: WIFI:S:"foo\;bar\\baz";;

实现

这里就不描述如何编写的了,代码在 github 开源,下面演示一下:

生成二维码


wifi 二维码生成
https://bubao.github.io/posts/47df24a0.html
作者
一念
发布于
2021年1月12日
许可协议