點擊一鍵連接按鈕,執行connectWifi 方法;
accountNumber: '', //Wi-Fi 的SSID,即賬號
bssid: '', //Wi-Fi 的ISSID
password: '' //Wi-Fi 的密碼
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: that.data.accountNumber, BSSID: that.data.bssid, password: that.data.password, success: function(res) { wx.showToast({ title: 'wifi連接成功' }); }, fail: function(res) { wx.showToast({ title: 'wifi連接失敗' }); } }); },