• 小程序一键链接WIFI


    1.小程序一键链接WIFI

    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: this.GetShop.wifi,// wifi名称
    					// BSSID: '10-F6-0A-99-E0-35',
    					password: this.GetShop.wifimima,// wifi密码
    					success: function(res) {
    						wx.showToast({
    							title: 'wifi连接成功'
    						});
    						setTimeout(()=>{
    							this.showWifi();
    						},2000)
    					},
    					fail: function(res) {
    						let errMsg = 'wifi连接失败';
    						if (res.errCode == "12001") errMsg = "wifi连接失败";// 当前系统不支持相关能力
    						if (res.errCode == "12002") errMsg = "wifi连接失败";// 查不到账号,请联系系统管理员
    						if (res.errCode == "12003") errMsg = "wifi连接失败";// 请确认是否在组织Wifi覆盖范围内
    						if (res.errCode == "12004") errMsg = "重复连接Wifi";
    						if (res.errCode == "12005") errMsg = "未打开Wifi开关";
    						if (res.errCode == "12006") errMsg = "未打开GPS定位开关";
    						if (res.errCode == "12007") errMsg = "用户拒绝授权链接Wifi";
    						if (res.errCode == "12008") errMsg = "wifi连接失败";// 查不到账号,请联系系统管理员
    						if (res.errCode == "12009") errMsg = "系统运行商配置拒绝链接Wifi";// 系统运行商配置拒绝链接Wifi
    						if (res.errCode == "12010") errMsg = "wifi连接失败";// 未知错误,请联系系统管理员
    						if (res.errCode == "12011") errMsg = "wifi连接失败";应用在后台无法配置Wifi
    						if (res.errCode == "12013") errMsg = "wifi连接失败";// 查不到账号,请联系系统管理员
    						if (res.errCode == "12014") errMsg = "wifi连接失败";
    						
    						wx.showToast({
    							title: errMsg
    						});
    					}
    				});
    			},
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77

    在这里插入图片描述

  • 相关阅读:
    Linux脚本之监控系统内存使用情况并给予警告
    云原生异常检测
    深入理解强化学习——序列决策(Sequential Decision Making)
    Ant Design Vue设置表格滚动 宽度自适应 不换行
    STM32实现USB转TTL串口工具
    Django REST项目实战:在线中文字符识别
    Web前端 | HTML基本标签、实体符号、表格、超链接、列表
    知识图谱增强的KG-RAG框架
    基于stm32f103系列的简单软件I2C和硬件I2C通讯
    可以提取图像文本的 5 大 Python 库
  • 原文地址:https://blog.csdn.net/weixin_57575133/article/details/136328738