The business logic

Recently, I have been developing the function of UNI-Appwifi punch card. In android terminal, I intend to obtain the unique MAC address of the wifi list, so as to add the company’s wifi information into the database. Later, when employees turn on wifi, they will obtain whether the MAC address of the wifi is the company’s wifi, if so, it will be within the punch card range. You can punch in. If the MAC address of the machine is not the MAC address of the wifIF of the company, it means that it is not connected to the company wifi, so you cannot punch in. It belongs to the field punch in.

Problems encountered in the actual process

There is an API about wifi in the API document of UNI-App, but it is not standardized and easy to understand, so I copied the first code and found that some states were output that I could not understand, but the wifi list was not output, so I continued to go down and copied the second code and found that there was output. But only output is the SSID that is wifi name without MAC address, look can not be used. So in the plug-in market to find, in addition to an Android wifi mobile phone assistant plug-in for free other charges, so the decision to download this case, look, one operation, the page out, click the initialization button and then click the wifi list, ha ha something, wifi name and MAC address have that can achieve business logic, But I will punch again after turn off wifi wifi found that can’t get wifi list and then tried various are the same, then to the plugin author five-star high praise, thought that the author add my qq, so these bugs pointed out to him, but the author has told me that he didn’t try other mobile phone, just simple tried on his mobile phone, Feel no problem, finally he told me to let me debug android source code, a face meng force, as a front-end small migrant workers, not Android so this plug-in can only be abandoned.

The ultimate solution

Finally, my boss asked me to implement this function, and I searched a lot of materials and blogs, but found nothing. Finally, I thought about it and started from the uni-app document. Then I came to the idea that it was only the code of output SSID, since it could output SSID, it must output MAC address, so I followed this clue. Finally, I found a native Android method in a blog post. The function getBSSID() was used to get the MAC address, so the problem was solved.

code

loadWifiInfo(){

let MainActivity = plus.android.runtimeMainActivity(); ImportClass (' android.content.context '); / / import WIFI management and WIFI class information plus. Android. The importClass (" android.net.wifi.WifiManager "); plus.android.importClass("android.net.wifi.WifiInfo"); plus.android.importClass("android.net.wifi.ScanResult"); plus.android.importClass("java.util.ArrayList"); / / to get WIFI management instance let wifiManager = MainActivity. GetSystemService (Context. WIFI_SERVICE); wifiManager.setWifiEnabled(true); / / open the wifi, false wifi to shut down / / get the current connection information let info. = wifiManager getConnectionInfo () / / check has been connected to the wifi information, In the Android SDK provides us with an object, called WifiInfo. This object can be through the WifiManager getConnectionInfo () to obtain. WifiInfo contains information about the current connection. //getBSSID() obtains BSSID properties //getDetailedStateOf() obtains client connectivity //getHiddenSSID() obtains whether the SSID is hidden //getIpAddress() obtains the IP address GetLinkSpeed () obtain the speed of the connection //getMacAddress() obtain the Mac address //getRssi() obtain the signal of 802.11n //getSSID() obtain the SSID //getSupplicanState() Get specific client status information // Get current WIFI connection SSID(WIFI name) // let SSID = info.getssid () let MAC = info.getBssid () if(this.attendanceInformationObj.clockManage.wifi.length>0){ let stateIndex = this.attendanceInformationObj.clockManage.wifi.findIndex(ites=>ites.mac===mac) if(stateIndex! ==-1){ this.clockState = true } } },Copy the code