這周在溝通產(chǎn)品需求時笔宿,客戶告知需要一個功能犁钟,讓他的到店客戶可以通過小程序一鍵鏈接他門店wifi,不需要輸入密碼泼橘,wifi名涝动。之前沒有做過這個功能,于是了解了一下炬灭,實現(xiàn)代碼如下醋粟。
<button bindtap="connectWifi">wifi</button>
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: '接口調(diào)用失敗',
})
}
})
},
Connected: function () {
var that = this
wx.connectWifi({
SSID: '',wifi名
BSSID: '',
password: '',wifi密碼
success: function (res) {
wx.showToast({
title: 'wifi連接成功',
})
},
fail: function (res) {
wx.showToast({
title: 'wifi連接失敗',
})
}
})
},