uniapp使用uni-imei插件獲取手機(jī)的設(shè)備號(hào)
在uniapp中,可以使用uni-imei插件來獲取設(shè)備號(hào)。使用步驟如下:
1. 安裝uni-imei插件,可以在HBuilderX中直接搜索安裝,或者在manifest.json文件中的“App原生插件配置”中添加以下配置:
"plugins": {
"uni-imei": {
"version": "1.1.0",
"provider": "uni-app.plus"
}
}
2. 在需要獲取設(shè)備號(hào)的頁(yè)面中引入uni-imei插件:
import imei from '@/uni_modules/uni-imei/js_sdk/uni-imei.js';
3. 調(diào)用uni-imei插件的getImei方法獲取設(shè)備號(hào):
imei.getImei({
success: function (res) {
console.log(res.imei); // 獲取到的設(shè)備號(hào)
}
});
需要注意的是,獲取設(shè)備號(hào)需要用戶授權(quán),因此在調(diào)用getImei方法之前需要先調(diào)用uni-imei插件的requestPermission方法請(qǐng)求授權(quán)。
補(bǔ)充知識(shí):uniapp獲取手機(jī)唯一標(biāo)識(shí)IMEI、MAC、UUID
// #ifdef APP
// 導(dǎo)入Java類。Networklnterface類表示一個(gè)由名稱和分配給此接口的IP地址列表組成的網(wǎng)絡(luò)接口
const net = plus.android.importClass('java.net.NetworkInterface');
// 搜索具有指定名稱的網(wǎng)絡(luò)接口
const wlan0 = net.getByName('wlan0');
// 獲得網(wǎng)卡的硬件地址
const macByte = wlan0.getHardwareAddress();
let mac = '';
//轉(zhuǎn)換MAC地址的思路來自網(wǎng)上(https://blog.csdn.net/zhangzhen53377562/article/details/109183891)
macByte.forEach(item => {
// .toString(16)數(shù)字以十六進(jìn)制值顯示
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
總結(jié)
到此這篇關(guān)于uniapp使用uni-imei插件獲取手機(jī)的設(shè)備號(hào)的文章就介紹到這了,更多相關(guān)uniapp獲取手機(jī)設(shè)備號(hào)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
javascript 兼容FF的onmouseenter和onmouseleave的代碼
經(jīng)過測(cè)試發(fā)現(xiàn),例子1 在 ff下抖動(dòng)的厲害,ie下稍微有點(diǎn)。 具體原因 其實(shí)就是 mouseout 的冒泡機(jī)制 引起的。2008-07-07
微信小程序wxs日期時(shí)間處理的實(shí)現(xiàn)示例
最近在做一個(gè)列表的時(shí)候,涉及到時(shí)間格式化操作。本文主要介紹了微信小程序wxs日期時(shí)間處理的實(shí)現(xiàn)示例,分享給大家,感興趣的可以了解一下2021-07-07
JavaScript實(shí)現(xiàn)異步獲取表單數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)異步獲取表單數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05
javascript的var與let,const之間的區(qū)別詳解
這篇文章主要為大家介紹了?javascript的var與let,const之間的區(qū)別,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2021-12-12

