Get the App
SLTechnology News&Howtos  ›  Development  › 

How can Mini Program scan the code and connect with wifi?

Shulou Source: shulou.com Published: 2022-06-01 06:46:04 10月05日 Update

This article mainly explains "how to scan code and even wifi in Mini Program", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to scan code with wifi on Mini Program".

Mini Program disadvantages: android6 version ios11 version

Code:

/ / pages/wifi/wifi.js

Page ({

Data: {

StartError:'', / / initialize error message

WifiListError: false, / / wifi list error display switch

WifiListErrorInfo:'', / / wifi list error details

System:'', / / version number

Platform:'', / / system android

Ssid: 'wifi account', / / wifi account (required)

Pass: 'wifi password', / / Wireless network password (required)

Bssid:'', / / device number is obtained automatically

EndError:''/ / the last hint to connect

}

OnLoad: function () {

Var _ this = this

/ / check the phone model

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) {   _this.setData({ startError: '手机版本暂时不支持' }); return   }   if (res.platform == 'ios' && system < 11) {   _this.setData({ startError: '手机版本暂时不支持' }); return   }   _this.setData({ platform: res.platform });   //初始化 Wi-Fi 模块   _this.startWifi(_this);   }   })   },//初始化 Wi-Fi 模块。   startWifi: function (_this) {   wx.startWifi({   success: function () {   _this.getList(_this);   },   fail: function (res) {   _this.setData({ startError: res.errMsg });   }   })   },   getList: function (_this) {   //安卓执行方法   if (_this.data.platform == 'android') {   //请求获取 Wi-Fi 列表   wx.getWifiList({   success: function (res) {   //安卓执行方法   _this.AndroidList(_this);   },   fail: function (res) {   _this.setData({ wifiListError: true });   _this.setData({ wifiListErrorInfo: res.errMsg });   }   })   }   //IOS执行方法   if (_this.data.platform == 'ios') {   _this.IosList(_this);   }   },   AndroidList: function (_this) {   //监听获取到 Wi-Fi 列表数据   wx.onGetWifiList(function (res) { //获取列表   if (res.wifiList.length) {   // _this.setData({   // wifiList: res.wifiList   // });   //循环找出信号最好的那一个(wifi存在多个)   var ssid = _this.data.ssid;   var signalStrength = 0;   var bssid = '';   for (var i = 0; i < res.wifiList.length; i++) {   if (res.wifiList[i]['SSID'] == ssid && res.wifiList[i]['signalStrength'] >

SignalStrength) {

Bssid = res.wifiList [I] ['BSSID']

SignalStrength = res.wifiList [I] ['signalStrength']

}

}

If (! signalStrength) {

_ this.setData ({wifiListError: true})

_ this.setData ({wifiListErrorInfo: 'the set wifi'} was not found)

Return

}

_ this.setData ({bssid: bssid})

/ / execute the connection method

/ / Connect to wifi

_ this.Connected (_ this)

} else {

_ this.setData ({wifiListError: true})

_ this.setData ({wifiListErrorInfo: 'the set wifi'} was not found)

At this point, I believe that "Mini Program how to achieve scan code even wifi" have a deeper understanding, might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Method version program mobile phone error query content password module Android account learning prompt support practical deeper code signal interest model Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Linux Microsoft Shulou Information