<view class="li" bindtap="connectWifi">
  <image src="/images/wifi.png"></image>
  <text>连接WIFI</text>
</view>
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: '',wifi名
      BSSID: '',
      password: '',wifi密码
      success: function (res) {
        wx.showToast({
          title: 'wifi连接成功',
        })
      },
      fail: function (res) {
        wx.showToast({
          title: 'wifi连接失败',
        })
      }
    })
  },
作者 铁血 汉子 2020年5月4日
2024/04/20/04:16:18am 2020/5/4/1:58:07
0 1500