import storage from './storage' import store from '@/store' import { device } from '@/api/other' /** * 设置请求头信息 */ export function setDevice() { const info = uni.getSystemInfoSync() const { appVersion, deviceId, brand, platform, system } = info let data = { appKey: 'DDH', appVersion, // app版本号 deviceId, // 设备号 deviceBrand: brand, // 品牌名称 sourceChannel: store.state.channel, deviceType: platform, // 设备类型 systemVersion: system, // 系统版本 deviceToken: '', // APP推送标识 iosDeviceToken: '', // iOS推送标识 idfa: '', // 广告标识,iOS必填 mac: '', // mac地址 appPackage: 'com.huahuayoumi.hhym', // APP包名 } if (platform == 'ios') { plus.device.getInfo({ //需要勾选IDFA success: e => { console.log('getInfo:' + JSON.stringify(e)) return data.idfa = e.idfa }, fail: err => { console.log('getDeviceInfo failed: ' + JSON.stringify(err)) }, }) } // 上传 device系统信息 setTimeout(() => { try { device(data).then((res) => { console.log('res', JSON.stringify(res.data)) }) storage.setDeviceData(data) } catch (error) { console.error(error); } }, 300) } // Android mac地址 function getDeviceMac() { //获取本机Mac地址 let deviceMac = '' let net = plus.android.importClass('java.net.NetworkInterface') let wl0 = net.getByName('wlan0') let macByte = wl0.getHardwareAddress() deviceMac = '' for (let i = 0; i < macByte.length; i++) { let tmp = '' let num = macByte[i] if (num < 0) { tmp = (255 + num + 1).toString(16) } else { tmp = num.toString(16) } if (tmp.length == 1) { tmp = '0' + tmp } deviceMac += tmp } return deviceMac }