startWifi: function (ssid, password) {
var that = this;
console.log("startWifi方法调用成功")
wx.startWifi({
success: function (res) {
wx.getSystemInfo({
success: (res)=> {
console.log('wx.getSystemInfo调用成功',res.platform)
if (res.platform == "ios") {
console.log('IOS');
}
if (res.platform == "android ") {
console.log('android')
}
}
})
wx.connectWifi({
SSID: ssid,
password: password,
success: function (res) {
console.log('connectWifi成功', JSON.stringify(res));
wx.getConnectedWifi({
success: function (res) {
if(ssid == res.wifi.SSID ){
that.setData({
statue:'已连接无线网络:'+that.data.name
})
}
},
})
},
fail: function (res) {
console.log('errCode===='+res.errCode+'errMsg===='+res.errMsg);
that.setData({
statue:that.errorStr(res.errCode)
})
}
})
},
fail: function (res) {
wx.showToast({
title: res.errMsg,
icon: 'none',
duration: 5000
})
}
})
},
errorStr: function (msg) {
if (msg == "12001") return "当前系统不支持相关能力";
if (msg == "12002") return "查不到账号,请联系系统管理员";
if (msg == "12003") return "请确认是否在组织Wifi覆盖范围内";
if (msg == "12004") return "重复连接Wifi";
if (msg == "12005") return "未打开Wifi开关";
if (msg == "12006") return "未打开GPS定位开关";
if (msg == "12007") return "用户拒绝授权链接Wifi";
if (msg == "12008") return "查不到账号,请联系系统管理员";
if (msg == "12009") return "系统运行商配置拒绝链接Wifi";
if (msg == "12010") return "未知错误,请联系系统管理员";
if (msg == "12011") return "应用在后台无法配置Wifi";
if (msg == "12013") return "查不到账号,请联系系统管理员";
if (msg == "12014") return "";
},
微信小程序链接wifi
最新推荐文章于 2023-10-18 13:59:34 发布