微信小程序一键链接WiFi


点击一键连接按钮,执行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连接失败'
                    });
                }
            });
        },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM