zoukankan      html  css  js  c++  java
  • 微信小程序一键链接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连接失败'
                        });
                    }
                });
            },
  • 相关阅读:
    TOP 100 SOFTWARE VENDORS (ZZ)
    数列总结函数——取余分析
    科克曼女生问题
    约瑟夫问题(猴子选王)——多种解法
    乒乓球与羽毛球不同发球规则下选手的胜率——概率论+程序分析
    Codeblocks快捷键
    常用陌生快捷键
    Dev使用技巧
    vueDemo补充
    vueDemo
  • 原文地址:https://www.cnblogs.com/yeziyou/p/13453848.html
Copyright © 2011-2022 走看看