B2B网络软件

标题: AIWROK软件平台设备信息全面检测工具例子 [打印本页]

作者: YYPOST群发软件    时间: 昨天 10:03
标题: AIWROK软件平台设备信息全面检测工具例子
AIWROK软件平台设备信息全面检测工具例子
AIWROK软件平台设备信息全面检测工具例子 B2B网络软件

AIWROK软件平台设备信息全面检测工具例子 B2B网络软件

  1. /**
  2. * AIWROK平台设备信息全面检测工具
  3. * //🍎交流QQ群711841924群一,苹果内测群,528816639
  4. * 本工具旨在全面检测和展示Android设备的各项硬件和软件信息
  5. * 包括设备基本信息、屏幕参数、电池状态、存储空间、内存使用情况、网络状态等
  6. * 采用了多层容错机制和友好的可视化展示方式
  7. * 适用于AIWROK自动化平台环境
  8. */

  9. // 安全调用函数,防止方法不存在时报错
  10. function safeCall(methodName, caller, defaultValue) {
  11.     try {
  12.         if (typeof caller[methodName] === 'function') {
  13.             var result = caller[methodName]();
  14.             return result !== undefined && result !== null ? result : (defaultValue || "未知");
  15.         } else {
  16.             return defaultValue || "方法不可用";
  17.         }
  18.     } catch (e) {
  19.         return defaultValue || "调用出错: " + e.message;
  20.     }
  21. }

  22. // 更安全的调用函数,支持传参
  23. function safeCallWithArgs(methodName, caller, args, defaultValue) {
  24.     try {
  25.         if (typeof caller[methodName] === 'function') {
  26.             var result = caller[methodName](args);
  27.             return result !== undefined && result !== null ? result : (defaultValue || "未知");
  28.         } else {
  29.             return defaultValue || "方法不可用";
  30.         }
  31.     } catch (e) {
  32.         return defaultValue || "调用出错: " + e.message;
  33.     }
  34. }

  35. // 格式化存储空间大小
  36. function formatStorageSize(bytes) {
  37.     if (bytes <= 0) return "0 B";
  38.    
  39.     var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
  40.     var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  41.     var size = Math.round(bytes / Math.pow(1024, i) * 100) / 100;
  42.     return size + ' ' + sizes[i];
  43. }

  44. // 获取设备基本信息
  45. function getDeviceInfo() {
  46.     printl("========== 设备基本信息 ==========");
  47.    
  48.     var info = {
  49.         "设备品牌": safeCall("getBrand", device),
  50.         "设备型号": safeCall("getModel", device),
  51.         "系统版本": safeCall("getVersion", device),
  52.         "设备ID": safeCall("getDeviceID", device),
  53.         "设备整数ID": safeCall("getDeviceIntID", device),
  54.         "IMEI": safeCall("getIMEI", device),
  55.         "OAID": safeCall("getOAID", device),
  56.         "IP地址": safeCall("getIP", device)
  57.     };
  58.    
  59.     for (var key in info) {
  60.         printl(key + ": " + info[key]);
  61.     }
  62.    
  63.     return info;
  64. }

  65. // 获取屏幕信息
  66. function getScreenInfo() {
  67.     printl("\n========== 屏幕信息 ==========");
  68.    
  69.     var width = 0, height = 0;
  70.    
  71.     // 尝试使用screen对象获取屏幕信息
  72.     if (typeof screen !== 'undefined') {
  73.         if (typeof screen.getScreenWidth === 'function') {
  74.             try {
  75.                 width = screen.getScreenWidth();
  76.             } catch (e) {
  77.                 printl("通过screen获取宽度失败: " + e.message);
  78.             }
  79.         }
  80.         
  81.         if (typeof screen.getScreenHeight === 'function') {
  82.             try {
  83.                 height = screen.getScreenHeight();
  84.             } catch (e) {
  85.                 printl("通过screen获取高度失败: " + e.message);
  86.             }
  87.         }
  88.     }
  89.    
  90.     // 如果screen对象不可用或获取失败,尝试device对象
  91.     if ((!width || !height) && typeof device !== 'undefined') {
  92.         if (typeof device.getScreenWidth === 'function') {
  93.             try {
  94.                 width = device.getScreenWidth();
  95.             } catch (e) {
  96.                 printl("通过device获取宽度失败: " + e.message);
  97.             }
  98.         }
  99.         
  100.         if (typeof device.getScreenHeight === 'function') {
  101.             try {
  102.                 height = device.getScreenHeight();
  103.             } catch (e) {
  104.                 printl("通过device获取高度失败: " + e.message);
  105.             }
  106.         }
  107.     }
  108.    
  109.     // 如果仍然没有获取到,则尝试使用默认值
  110.     if (!width && typeof device !== 'undefined' && typeof device.width === 'number') {
  111.         width = device.width;
  112.     }
  113.    
  114.     if (!height && typeof device !== 'undefined' && typeof device.height === 'number') {
  115.         height = device.height;
  116.     }
  117.    
  118.     if (width && height) {
  119.         printl("屏幕分辨率: " + width + " × " + height);
  120.         printl("屏幕密度: " + width + " × " + height + " 像素");
  121.     } else {
  122.         printl("屏幕分辨率: 无法获取");
  123.     }
  124.    
  125.     return { width: width, height: height };
  126. }

  127. // 获取电池信息
  128. function getBatteryInfo() {
  129.     printl("\n========== 电池信息 ==========");
  130.    
  131.     var level = "未知";
  132.     var status = "未知";
  133.    
  134.     if (typeof device !== 'undefined') {
  135.         // 尝试多种方式获取电池信息
  136.         if (typeof device.getBatteryLevel === 'function') {
  137.             try {
  138.                 level = device.getBatteryLevel();
  139.                 if (level === null || level === undefined) {
  140.                     level = "未知";
  141.                 }
  142.             } catch (e) {
  143.                 printl("获取电池电量失败: " + e.message);
  144.             }
  145.         }
  146.         
  147.         // 注意:device.getBatteryStatus 方法不存在,因此移除相关代码
  148.     }
  149.    
  150.     // 格式化电池信息显示
  151.     if (level !== "未知" && !isNaN(level)) {
  152.         printl("电池电量: " + level + "%");
  153.         
  154.         // 根据电量显示状态图标
  155.         var batteryIcon = "&#128267;";
  156.         if (level > 80) batteryIcon = "&#128267;";
  157.         else if (level > 50) batteryIcon = "&#128267;";
  158.         else if (level > 20) batteryIcon = "&#128267;";
  159.         else batteryIcon = "&#129707;";
  160.         
  161.         printl("电量状态: " + batteryIcon + " " + level + "%");
  162.     } else {
  163.         printl("电池电量: " + level);
  164.     }
  165.    
  166.     // 移除对不存在方法的调用
  167.     // printl("电池状态: " + status);
  168.    
  169.     return { level: level };
  170. }

  171. // 获取存储信息
  172. function getStorageInfo() {
  173.     printl("\n========== 存储信息 ==========");
  174.    
  175.     // 尝试多种方式获取存储信息
  176.     if (typeof file !== 'undefined') {
  177.         var totalSpace = -1;
  178.         var freeSpace = -1;
  179.         
  180.         // 尝试获取总空间
  181.         if (typeof file.getTotalSpace === 'function') {
  182.             try {
  183.                 totalSpace = file.getTotalSpace("/sdcard/");
  184.                 if (totalSpace <= 0) {
  185.                     // 尝试其他路径
  186.                     totalSpace = file.getTotalSpace("/");
  187.                 }
  188.             } catch (e) {
  189.                 printl("获取总存储空间失败: " + e.message);
  190.             }
  191.         }
  192.         
  193.         // 尝试获取可用空间
  194.         if (typeof file.getFreeSpace === 'function') {
  195.             try {
  196.                 freeSpace = file.getFreeSpace("/sdcard/");
  197.                 if (freeSpace <= 0) {
  198.                     // 尝试其他路径
  199.                     freeSpace = file.getFreeSpace("/");
  200.                 }
  201.             } catch (e) {
  202.                 printl("获取可用存储空间失败: " + e.message);
  203.             }
  204.         }
  205.         
  206.         // 如果通过file对象的方法获取成功
  207.         if (totalSpace > 0 && freeSpace >= 0) {
  208.             var usedSpace = totalSpace - freeSpace;
  209.             var usedPercentage = ((usedSpace / totalSpace) * 100).toFixed(1);
  210.             printl("总存储空间: " + formatStorageSize(totalSpace));
  211.             printl("已使用空间: " + formatStorageSize(usedSpace) + " (" + usedPercentage + "%)");
  212.             printl("可用空间: " + formatStorageSize(freeSpace));
  213.             
  214.             // 显示存储使用情况的进度条
  215.             var progressBarLength = 20;
  216.             var filledLength = Math.round((usedSpace / totalSpace) * progressBarLength);
  217.             var bar = "[" + Array(filledLength + 1).join("█") + Array(progressBarLength - filledLength + 1).join("░") + "]";
  218.             printl("使用情况: " + bar);
  219.             return;
  220.         }
  221.     }
  222.    
  223.     // 尝试通过device对象获取存储信息(只尝试确实存在的方法)
  224.     if (typeof device !== 'undefined') {
  225.         try {
  226.             // 检查是否有获取存储信息的方法(不调用不存在的方法)
  227.             var deviceMethods = [];
  228.             for (var prop in device) {
  229.                 if (typeof device[prop] === 'function' && prop.indexOf('Storage') !== -1) {
  230.                     deviceMethods.push(prop);
  231.                 }
  232.             }
  233.             
  234.             if (deviceMethods.length > 0) {
  235.                 printl("设备存储相关方法: " + deviceMethods.join(', '));
  236.             }
  237.         } catch (e) {
  238.             // 忽略错误
  239.         }
  240.     }
  241.    
  242.     // 尝试通过环境变量获取存储信息
  243.     try {
  244.         if (typeof java !== 'undefined' && java.lang && java.lang.System) {
  245.             var system = java.lang.System;
  246.             if (system) {
  247.                 var properties = system.getProperties();
  248.                 if (properties) {
  249.                     var fileSeparator = properties.get("file.separator") || "/";
  250.                     var sdcardPath = "/sdcard";
  251.                     
  252.                     // 尝试使用Java File类获取存储信息
  253.                     if (java.io && java.io.File) {
  254.                         var File = java.io.File;
  255.                         var sdcardFile = new File(sdcardPath);
  256.                         if (sdcardFile.exists()) {
  257.                             totalSpace = sdcardFile.getTotalSpace();
  258.                             freeSpace = sdcardFile.getFreeSpace();
  259.                            
  260.                             if (totalSpace > 0 && freeSpace >= 0) {
  261.                                 var usedSpace = totalSpace - freeSpace;
  262.                                 var usedPercentage = ((usedSpace / totalSpace) * 100).toFixed(1);
  263.                                 printl("总存储空间: " + formatStorageSize(totalSpace));
  264.                                 printl("已使用空间: " + formatStorageSize(usedSpace) + " (" + usedPercentage + "%)");
  265.                                 printl("可用空间: " + formatStorageSize(freeSpace));
  266.                                 
  267.                                 // 显示存储使用情况的进度条
  268.                                 var progressBarLength = 20;
  269.                                 var filledLength = Math.round((usedSpace / totalSpace) * progressBarLength);
  270.                                 var bar = "[" + Array(filledLength + 1).join("█") + Array(progressBarLength - filledLength + 1).join("░") + "]";
  271.                                 printl("使用情况: " + bar);
  272.                                 return;
  273.                             }
  274.                         }
  275.                     }
  276.                 }
  277.             }
  278.         }
  279.     } catch (e) {
  280.         printl("通过Java API获取存储信息失败: " + e.message);
  281.     }
  282.    
  283.     printl("存储信息: 无法获取");
  284. }

  285. // 获取内存信息
  286. function getMemoryInfo() {
  287.     printl("\n========== 内存信息 ==========");
  288.    
  289.     if (typeof app !== 'undefined') {
  290.         // 尝试使用app.getMemoryPercent()获取内存使用百分比
  291.         if (typeof app.getMemoryPercent === 'function') {
  292.             try {
  293.                 var memoryPercent = app.getMemoryPercent();
  294.                 if (memoryPercent !== null && memoryPercent !== undefined) {
  295.                     printl("内存使用率: " + memoryPercent + "%");
  296.                     
  297.                     // 根据内存使用率显示状态图标
  298.                     var memoryIcon = "&#129504;";
  299.                     if (memoryPercent > 80) memoryIcon = "⚠️";
  300.                     else if (memoryPercent > 60) memoryIcon = "MemoryWarning";
  301.                     printl("内存状态: " + memoryIcon + " " + memoryPercent + "%");
  302.                     return;
  303.                 }
  304.             } catch (e) {
  305.                 printl("获取内存使用率失败: " + e.message);
  306.             }
  307.         }
  308.         
  309.         // 尝试使用app.getMemory()获取内存信息
  310.         if (typeof app.getMemory === 'function') {
  311.             try {
  312.                 var memory = app.getMemory();
  313.                 // getMemory返回的是JSON字符串,需要解析
  314.                 if (typeof memory === 'string' && memory.length > 0) {
  315.                     var memoryObj = JSON.parse(memory);
  316.                     if (memoryObj && memoryObj.used) {
  317.                         printl("当前应用内存占用: " + formatStorageSize(memoryObj.used));
  318.                         if (memoryObj.total) {
  319.                             printl("应用内存总量: " + formatStorageSize(memoryObj.total));
  320.                         }
  321.                         return;
  322.                     }
  323.                 } else if (typeof memory === 'number' && memory > 0) {
  324.                     // 如果直接返回数字
  325.                     printl("当前应用内存占用: " + formatStorageSize(memory));
  326.                     return;
  327.                 }
  328.             } catch (e) {
  329.                 printl("解析内存信息失败: " + e.message);
  330.             }
  331.         }
  332.     }
  333.    
  334.     printl("内存信息: 无法获取");
  335. }

  336. // 获取网络信息
  337. function getNetworkInfo() {
  338.     printl("\n========== 网络信息 ==========");
  339.    
  340.     var hasNetworkInfo = false;
  341.    
  342.     // WiFi信息(更安全的检查方式)
  343.     if (typeof wifi !== 'undefined') {
  344.         if (typeof wifi.isWifiEnabled === 'function') {
  345.             try {
  346.                 var isWifiEnabled = wifi.isWifiEnabled();
  347.                 printl("WiFi状态: " + (isWifiEnabled ? "已启用" : "已禁用"));
  348.                 hasNetworkInfo = true;
  349.                
  350.                 if (isWifiEnabled && typeof wifi.getSSID === 'function') {
  351.                     var ssid = wifi.getSSID();
  352.                     if (ssid) {
  353.                         printl("WiFi名称: " + ssid);
  354.                     }
  355.                 }
  356.             } catch (e) {
  357.                 printl("获取WiFi信息失败: " + e.message);
  358.             }
  359.         } else {
  360.             // 检查wifi对象有哪些可用方法
  361.             var wifiMethods = [];
  362.             for (var prop in wifi) {
  363.                 if (typeof wifi[prop] === 'function') {
  364.                     wifiMethods.push(prop);
  365.                 }
  366.             }
  367.             
  368.             if (wifiMethods.length > 0) {
  369.                 printl("WiFi可用方法: " + wifiMethods.join(', '));
  370.                 hasNetworkInfo = true;
  371.             } else {
  372.                 printl("WiFi功能: 不可用");
  373.             }
  374.         }
  375.     } else {
  376.         printl("WiFi模块: 未找到");
  377.     }
  378.    
  379.     // 尝试通过HTTP请求检查网络连接
  380.     if (typeof okHttp !== 'undefined') {
  381.         try {
  382.             printl("正在测试网络连接...");
  383.             var http = new okHttp();
  384.             var response = http.get("http://www.baidu.com");
  385.             
  386.             if (response && response.length > 0) {
  387.                 printl("网络连接: 可访问百度");
  388.                 hasNetworkInfo = true;
  389.             } else {
  390.                 printl("网络连接: 无法访问百度 (空响应)");
  391.             }
  392.         } catch (e) {
  393.             printl("网络连接测试失败: " + e.message);
  394.             // 即使测试失败,也标记为有网络信息
  395.             hasNetworkInfo = true;
  396.         }
  397.     } else {
  398.         printl("HTTP客户端: 未找到");
  399.     }
  400.    
  401.     // 尝试获取设备网络信息
  402.     if (typeof device !== 'undefined') {
  403.         // 检查是否有获取IP的方法
  404.         if (typeof device.getIP === 'function') {
  405.             try {
  406.                 var ip = device.getIP();
  407.                 if (ip && ip !== "unknown") {
  408.                     printl("设备IP: " + ip);
  409.                     hasNetworkInfo = true;
  410.                 }
  411.             } catch (e) {
  412.                 printl("获取设备IP失败: " + e.message);
  413.             }
  414.         } else {
  415.             // 检查device对象有哪些网络相关方法
  416.             var networkMethods = [];
  417.             for (var prop in device) {
  418.                 if (typeof device[prop] === 'function' && (prop.indexOf('Network') !== -1 || prop.indexOf('IP') !== -1)) {
  419.                     networkMethods.push(prop);
  420.                 }
  421.             }
  422.             
  423.             if (networkMethods.length > 0) {
  424.                 printl("设备网络相关方法: " + networkMethods.join(', '));
  425.                 hasNetworkInfo = true;
  426.             }
  427.         }
  428.     }
  429.    
  430.     if (!hasNetworkInfo) {
  431.         printl("网络信息: 无法获取");
  432.     }
  433. }

  434. // 获取当前运行的应用信息
  435. function getRunningAppInfo() {
  436.     printl("\n========== 应用信息 ==========");
  437.    
  438.     if (typeof app !== 'undefined') {
  439.         var packageName = "未知";
  440.         
  441.         // 尝试多种方式获取包名
  442.         if (typeof app.getTopPackName === 'function') {
  443.             try {
  444.                 packageName = app.getTopPackName();
  445.             } catch (e) {
  446.                 printl("通过getTopPackName获取包名失败: " + e.message);
  447.             }
  448.         }
  449.         
  450.         if ((packageName === "未知" || !packageName) && typeof app.getCurrentPackage === 'function') {
  451.             try {
  452.                 packageName = app.getCurrentPackage();
  453.             } catch (e) {
  454.                 printl("通过getCurrentPackage获取包名失败: " + e.message);
  455.             }
  456.         }
  457.         
  458.         printl("当前应用包名: " + (packageName || "未知"));
  459.         
  460.         if (packageName && packageName !== "未知" && typeof app.getAppName === 'function') {
  461.             try {
  462.                 var appName = app.getAppName(packageName);
  463.                 if (appName) {
  464.                     printl("当前应用名称: " + appName);
  465.                 }
  466.             } catch (e) {
  467.                 printl("获取应用名称失败: " + e.message);
  468.             }
  469.         }
  470.         return;
  471.     }
  472.    
  473.     printl("应用信息: app对象不可用");
  474. }

  475. // 生成设备信息报告
  476. function generateDeviceInfoReport() {
  477.     printl("==============================================");
  478.     printl("           AIWROK 设备信息报告");
  479.     printl("==============================================");
  480.     printl("报告生成时间: " + new Date().toLocaleString());
  481.     printl("");
  482.    
  483.     // 获取各类信息
  484.     getDeviceInfo();
  485.     getScreenInfo();
  486.     getBatteryInfo();
  487.     getStorageInfo();
  488.     getMemoryInfo();
  489.     getNetworkInfo();
  490.     getRunningAppInfo();
  491.    
  492.     printl("\n==============================================");
  493.     printl("              报告结束");
  494.     printl("==============================================");
  495. }

  496. // 主函数
  497. function main() {
  498.     printl("AIWROK实用设备信息示例开始执行...");
  499.     generateDeviceInfoReport();
  500.     printl("\n设备信息获取完成。");
  501. }

  502. // 执行主函数
  503. main();
复制代码







欢迎光临 B2B网络软件 (http://bbs.niubt.cn/) Powered by Discuz! X3.2