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连接失败'
                        });
                    }
                });
            },
  • 相关阅读:
    HashMap 和 Hashtable 的区别
    提高利用运行(安装)内存
    MyEclipse、Hbuilder、Idea快捷键
    本地安装MySQL详细教程
    MyEclipse/Eclipse相关设置
    MyEclipse 10导入JDK1.7或1.8
    Oracle视图(和Mysq一样l)
    Oracle事务
    MySql综合知识汇总
    Mysql存储过程
  • 原文地址:https://www.cnblogs.com/yeziyou/p/13453848.html
Copyright © 2011-2022 走看看