uni-app于获取手机设备的相关信息(IMEI、IMSI、型号、厂商等)
<p><span style="font-size: 18px"><strong>一些常用基本设备信息:</strong></span></p><p>https://uniapp.dcloud.io/api/system/info</p>
<p><strong><span style="font-size: 18px">5+功能模块:</span></strong></p>
<p><span style="font-size: 15px">Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI、IMSI、型号、厂商等。通过plus.device获取设备信息管理对象。</span></p>
<p><span style="font-size: 16px"><strong>属性:</strong></span></p>
<ul>
<li><span style="font-size: 14px">imei:设备的国际移动设备身份码</span></li>
<li><span style="font-size: 14px">imsi: 设备的国际移动用户识别码</span></li>
<li><span style="font-size: 14px">model:设备的型号</span></li>
<li><span style="font-size: 14px">vendor:设备的生产厂商</span></li>
<li><span style="font-size: 14px">uuid:设备的唯一标识</span></li>
</ul>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取设备的国际移动设备身份码</span>
console.log(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">IMEI: </span><span style="color: rgba(128, 0, 0, 1)">"</span>+<span style="color: rgba(0, 0, 0, 1)">plus.device.imei);
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取设备的国际移动用户识别码</span>
console.log(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">IMSI: </span><span style="color: rgba(128, 0, 0, 1)">"</span> +<span style="color: rgba(0, 0, 0, 1)"> plus.device.imsi);
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取设备的型号</span>
console.log(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Model: </span><span style="color: rgba(128, 0, 0, 1)">"</span> +<span style="color: rgba(0, 0, 0, 1)"> plus.device.model);
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取设备的生产厂商</span>
console.log(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Vendor: </span><span style="color: rgba(128, 0, 0, 1)">"</span> +<span style="color: rgba(0, 0, 0, 1)"> plus.device.vendor);
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取设备的唯一标识号</span>
console.log(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">UUID: </span><span style="color: rgba(128, 0, 0, 1)">"</span>+plus.device.uuid);</pre>
</div>
<p><span style="font-size: 14px">需要注意的一点是,以上方法获取 <span style="color: rgba(255, 102, 0, 1)">IMEI</span> 以及 <span style="color: rgba(255, 102, 0, 1)">IMSI</span> 即将不支持,HBuilderX2.0.0以后版本使用<span style="color: rgba(255, 102, 0, 1)"> plus.device.getInfo</span> 方法<br></span></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 获取设备信息</span>
<span style="color: rgba(0, 0, 0, 1)">plus.device.getInfo({
success:</span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(e){
console.log(</span>'getDeviceInfo success: '+<span style="color: rgba(0, 0, 0, 1)">JSON.stringify(e));
},
fail:</span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(e){
console.log(</span>'getDeviceInfo failed: '+<span style="color: rgba(0, 0, 0, 1)">JSON.stringify(e));
}
});</span></pre>
</div>
<p>(以上:获取失败将返回空字符串)</p><br><br>
来源:https://www.cnblogs.com/angenstern/p/13071246.html
頁:
[1]