小程序一键链接WIFI

1.小程序一键链接WIFI

wx 复制代码
connectWifi: function() {
				var that = this;
				//检测手机型号
				wx.getSystemInfo({
					success: function(res) {
						var system = '';
						if (res.platform == 'android') system = parseInt(res.system.substr(8));
						if (res.platform == 'ios') system = parseInt(res.system.substr(4));
						if (res.platform == 'android' && system < 6) {
							wx.showToast({
								title: '手机版本不支持'
							});
							return;
						}
						if (res.platform == 'ios' && system < 11.2) {
							wx.showToast({
								title: '手机版本不支持'
							});
							return;
						}
						//2.初始化 Wi-Fi 模块
						that.startWifi();
					}
				});
			},
			//初始化 Wi-Fi 模块
			startWifi: function() {
				var that = this;
				wx.startWifi({
					success: function() {
						//请求成功连接Wifi
						that.Connected();
					},
					fail: function(res) {
						wx.showToast({
							title: '接口调用失败'
						});
					}
				});
			},

			Connected: function() {
				var that = this;
				wx.connectWifi({
					SSID: this.GetShop.wifi,// wifi名称
					// BSSID: '10-F6-0A-99-E0-35',
					password: this.GetShop.wifimima,// wifi密码
					success: function(res) {
						wx.showToast({
							title: 'wifi连接成功'
						});
						setTimeout(()=>{
							this.showWifi();
						},2000)
					},
					fail: function(res) {
						let errMsg = 'wifi连接失败';
						if (res.errCode == "12001") errMsg = "wifi连接失败";// 当前系统不支持相关能力
						if (res.errCode == "12002") errMsg = "wifi连接失败";// 查不到账号,请联系系统管理员
						if (res.errCode == "12003") errMsg = "wifi连接失败";// 请确认是否在组织Wifi覆盖范围内
						if (res.errCode == "12004") errMsg = "重复连接Wifi";
						if (res.errCode == "12005") errMsg = "未打开Wifi开关";
						if (res.errCode == "12006") errMsg = "未打开GPS定位开关";
						if (res.errCode == "12007") errMsg = "用户拒绝授权链接Wifi";
						if (res.errCode == "12008") errMsg = "wifi连接失败";// 查不到账号,请联系系统管理员
						if (res.errCode == "12009") errMsg = "系统运行商配置拒绝链接Wifi";// 系统运行商配置拒绝链接Wifi
						if (res.errCode == "12010") errMsg = "wifi连接失败";// 未知错误,请联系系统管理员
						if (res.errCode == "12011") errMsg = "wifi连接失败";应用在后台无法配置Wifi
						if (res.errCode == "12013") errMsg = "wifi连接失败";// 查不到账号,请联系系统管理员
						if (res.errCode == "12014") errMsg = "wifi连接失败";
						
						wx.showToast({
							title: errMsg
						});
					}
				});
			},
相关推荐
汤姆yu2 小时前
基于微信小程序的学校招生系统
微信小程序·小程序·招生小程序
说私域9 小时前
基于开源AI智能名片链动2+1模式的S2B2C商城小程序:门店私域流量与视频号直播融合的生态创新研究
人工智能·小程序·开源
说私域11 小时前
传统微商困境与开源链动2+1模式、AI智能名片及S2B2C商城小程序的转型破局
人工智能·小程序·开源
一渊之隔11 小时前
微信小程序在用户拒绝授权后无法使用wx.opensetting再次获取定位授权
微信小程序·小程序
racerun15 小时前
微信小程序如何实现再多个页面共享数据
微信小程序·小程序
XM-545815 小时前
2025微信小程序wxapkg解包全攻略
linux·运维·小程序
HERR_QQ2 天前
【unify】unify的微信小程序开发学习 (to be continued)
学习·微信小程序·小程序
racerun2 天前
小程序导航设置更多内容的实现方法
小程序
说私域2 天前
基于开源AI智能名片链动2+1模式S2B2C商城小程序的超级文化符号构建路径研究
人工智能·小程序·开源
mg6682 天前
微信小程序入门实例_____快速搭建一个快递查询小程序
微信小程序·小程序