yeziyou

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

 

分类:

技术点:

相关文章:

  • 2021-12-18
  • 2021-05-21
  • 2021-10-17
  • 2021-08-20
  • 2022-02-07
  • 2022-01-02
  • 2021-08-08
  • 2022-01-26
猜你喜欢
  • 2022-01-23
  • 2022-02-24
  • 2021-12-15
  • 2021-12-24
  • 2022-12-23
  • 2021-10-17
  • 2021-12-25
相关资源
相似解决方案