• 小程序一键链接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

    在这里插入图片描述

  • 相关阅读:
    C语言-自定义类型结构体详细讲解
    Petalinux配置
    【DevOps】Git 图文详解(四):Git 使用入门
    GBase 8s 锁的分类
    SpringCloud——Http客户端Feign
    如何对待工作中的失误
    【软件测试】作为测试人,因工作与开发吵了一架碰撞,该咋办......
    《JavaScript设计模式》笔记 - - - 超全设计模式概览
    C++之if-else基本应用
    莫队 从零基础到入门 超详细
  • 原文地址:https://blog.csdn.net/weixin_57575133/article/details/136328738