wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { isAndroid, uuid } from "/@/cool/utils";
 
// 版本比较
export function compareVersions(v1: string, v2: string) {
    const arr1 = v1.split(".").map(Number);
    const arr2 = v2.split(".").map(Number);
    const maxLength = Math.max(arr1.length, arr2.length);
 
    for (let i = 0; i < maxLength; i++) {
        const num1 = arr1[i] || 0;
        const num2 = arr2[i] || 0;
 
        if (num1 > num2) return 1;
        if (num2 > num1) return -1;
    }
 
    return 0;
}
 
// 获取版本号
export function getVersion(): Promise<string> {
    return new Promise((resolve) => {
        // #ifdef APP
        const packVersion: any = plus.runtime.version;
        const appid: any = plus.runtime.appid;
        plus.runtime.getProperty(appid, function (widgetInfo) {
            resolve(
                String(packVersion) > String(widgetInfo.version) ? packVersion : widgetInfo.version,
            );
        });
        // #endif
 
        // #ifndef APP
        resolve("1.0.0");
        // #endif
    });
}
 
// 获取 deviceId
export function getDeviceId(): string {
    // #ifdef APP
    return plus.device.uuid!;
    // #endif
 
    // #ifndef APP
    return uuid();
    // #endif
}
 
// 获取 oaid
export function getOAID() {
    return new Promise((resolve) => {
        plus.device.getOAID({
            success(res) {
                resolve(res.oaid);
            },
            fail() {
                resolve(0);
            },
        });
    });
}
 
// 获取 androidId
export function getAndroidId() {
    if (isAndroid) {
        const Settings = plus.android.importClass("android.provider.Settings");
        const main = plus.android.runtimeMainActivity();
        // @ts-ignore
        return Settings.Secure.getString(main.getContentResolver(), Settings.Secure.ANDROID_ID);
    }
}
 
// 获取 mac
export function getMac() {
    if (isAndroid) {
        const net = plus.android.importClass("java.net.NetworkInterface");
        // @ts-ignore
        const wl0 = net.getByName("wlan0");
        const macByte = wl0.getHardwareAddress();
        let str = "";
        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;
            }
            str += tmp;
        }
        return str;
    }
}