在这里插入图片描述
在这里插入图片描述

// #ifdef APP
// 导入Java类。Networklnterface类表示一个由名称和分配给此接口的IP地址列表组成的网络接口
const net = plus.android.importClass('java.net.NetworkInterface');
// 搜索具有指定名称的网络接口
const wlan0 = net.getByName('wlan0');
// 获得网卡的硬件地址
const macByte = wlan0.getHardwareAddress();
let mac = '';
//转换MAC地址的思路来自网上(https://blog.csdn.net/zhangzhen53377562/article/details/109183891)
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}`;
	mac += temp;
});
mac = mac.toUpperCase();
let mac2 = mac;
for (let i = 2; i < mac2.length; i += 3) mac2 = mac2.slice(0, i) + ':' + mac2.slice(i);
console.log('MAC: ' + mac);
console.log('MAC2: ' + mac2);
console.log('IMEI: ' + plus.device.imei);
plus.device.getInfo({
	success: function(e) {
		console.log('getDeviceInfo success: ' + JSON.stringify(e));
	},
	fail: function(e) {
		console.log('getDeviceInfo failed: ' + JSON.stringify(e));
	}
});
// #endif
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐