uniapp获取设备mac地址

const net = plus.android.importClass('java.net.NetworkInterface');
 const wlan0 = net.getByName('wlan0');
 const macByte = wlan0.getHardwareAddress();
 let macStr = '';
 macByte.forEach(item => {
     // .toString(16)数字以十六进制值显示
     let temp = '';
     if (item < 0) temp = (256 + item).toString(16);
     else temp = item.toString(16);
     if (temp.length == 1) temp = `0${temp}`;
     macStr += temp;
 });
 let mac = macStr.toUpperCase();
 for (let i = 2; i < mac.length; i += 3) mac = mac.slice(0, i) + ':' + mac.slice(i);
 that.deviceInfo.macId = mac;
 that.deviceInfo.deviceIdentifier = mac;
 that.deviceInfo.deviceName = plus.device.vendor + '_' + plus.device.model;
 that.deviceInfo.deviceId = plus.device.uuid;

你可能感兴趣的:(uni-app,macos)