Home  >  Article  >  WeChat Applet  >  How to connect the mini program to WIFI

How to connect the mini program to WIFI

angryTom
angryTomOriginal
2020-03-21 12:24:386487browse

This article mainly introduces the WeChat applet to realize the WiFi connection function, and analyzes the module initialization, configuration, connection and other related operation skills of the WeChat applet to operate WiFi connection in the form of examples. Friends in need can refer to the following

How to connect the mini program to WIFI

How to connect to WIFI with a small program

When the wifi account and wifi password are known, the following process is generally used to connect to wifi.

Recommended learning: Small program developmentTutorial

Wi-Fi interface call:

1, Android

 startWifi —> connectWifi —> onWifiConnected

2. iOS (only supported by iOS 11 and above):

startWifi —> connectWifi —> onWifiConnected

The steps are as follows:

1. Get the model number of the phone:

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 == &#39;android&#39; && system < 6) {
                wx.showToast({
                    title: &#39;手机版本不支持&#39;,
                })
                return
            }
            if (res.platform == &#39;ios&#39; && system < 11.2) {
                wx.showToast({
                    title: &#39;手机版本不支持&#39;,
                })
                return
            }
            //2.初始化 Wi-Fi 模块
            that.startWifi();
        }
    })
},
//初始化 Wi-Fi 模块
startWifi: function() {
    var that=this
    wx.startWifi({
        success: function() {
            //请求成功连接Wifi
            that.Connected();
        },
        fail: function(res) {
            this.setData({
                wx.showToast({
                    title: &#39;接口调用失败&#39;,
                })
            });
        }
    })
},

2. Connect to known Wifi

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: &#39;wifi连接成功&#39;,
            })
        },
        fail: function(res) {
            wx.showToast({
                title: &#39;wifi连接失败&#39;,
            })
        }
    })
},
//使用的参数
data:{
    accountNumber: &#39;&#39;,//Wi-Fi 的SSID,即账号
    bssid: &#39;&#39;,//Wi-Fi 的ISSID
    password: &#39;&#39;,//Wi-Fi 的密码
}

3. .wxml connection button

<button bindtap="connectWifi"></button>

PHP Chinese website , a large number of MySQL video tutorials, welcome to learn online for free!

The above is the detailed content of How to connect the mini program to WIFI. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn