2025-10-20 10:16:44 +08:00
|
|
|
|
package com.xscm.moduleutil.utils;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
|
|
|
|
|
|
import com.blankj.utilcode.util.AppUtils;
|
|
|
|
|
|
import com.blankj.utilcode.util.MetaDataUtils;
|
|
|
|
|
|
import com.chad.library.BuildConfig;
|
|
|
|
|
|
import com.xscm.moduleutil.base.CommonAppContext;
|
|
|
|
|
|
import com.xscm.moduleutil.utils.config.ConfigUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
public class SystemUtils {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取当前手机系统语言。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 返回当前系统语言。例如:当前设置的是“中文-中国”,则返回“zh-CN”
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getSystemLanguage() {
|
|
|
|
|
|
return Locale.getDefault().getLanguage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取当前手机系统版本号
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 系统版本号
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getSystemVersion() {
|
|
|
|
|
|
return Build.VERSION.RELEASE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取手机型号
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 手机型号
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getSystemModel() {
|
|
|
|
|
|
return Build.MODEL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取手机厂商
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 手机厂商
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getDeviceBrand() {
|
|
|
|
|
|
return Build.BRAND;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getClientID(String channel) {
|
|
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
|
|
sb.append(channel);
|
|
|
|
|
|
sb.append(Build.SERIAL);
|
|
|
|
|
|
sb.append(Build.BOARD.length() % 10);
|
|
|
|
|
|
sb.append(Build.BRAND.length() % 10);
|
|
|
|
|
|
sb.append(Build.CPU_ABI.length() % 10);
|
|
|
|
|
|
sb.append(Build.DEVICE.length() % 10);
|
|
|
|
|
|
sb.append(Build.DISPLAY.length() % 10);
|
|
|
|
|
|
sb.append(Build.HOST.length() % 10);
|
|
|
|
|
|
sb.append(Build.ID.length() % 10);
|
|
|
|
|
|
sb.append(Build.MANUFACTURER.length() % 10);
|
|
|
|
|
|
sb.append(Build.MODEL.length() % 10);
|
|
|
|
|
|
sb.append(Build.PRODUCT.length() % 10);
|
|
|
|
|
|
sb.append(Build.TAGS.length() % 10);
|
|
|
|
|
|
sb.append(Build.TYPE.length() % 10);
|
|
|
|
|
|
sb.append(Build.USER.length() % 10);
|
|
|
|
|
|
|
|
|
|
|
|
return Md5Utils.get(sb.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getShortClientID(Context context, String channel) {
|
|
|
|
|
|
String cid = getClientID(channel);
|
|
|
|
|
|
return Md5Utils.get(cid + getUUID(context));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getShortClientID(Context context) {
|
|
|
|
|
|
String cid = getClientID("xqipaoandroid");
|
|
|
|
|
|
return Md5Utils.get(cid + getUUID(context));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 得到全局唯一UUID
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getUUID(Context context) {
|
|
|
|
|
|
String system_uuid_key = "system_uuid";
|
|
|
|
|
|
ConfigUtils configUtils = ConfigUtils.getInstance(context);
|
|
|
|
|
|
configUtils.setConfigName(system_uuid_key);
|
|
|
|
|
|
String system_config_uuid = configUtils.findStringByKey(system_uuid_key);
|
2025-12-31 03:31:31 +08:00
|
|
|
|
if (system_config_uuid == null || system_config_uuid.isEmpty()) {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
// system_config_uuid = DeviceUtils.getUniqueDeviceId();
|
|
|
|
|
|
configUtils.addOrUpdateText(system_uuid_key, system_config_uuid);
|
|
|
|
|
|
}
|
|
|
|
|
|
return system_config_uuid;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 系统参数
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static Map<String, String> getSystemParams() {
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
|
|
|
headers.put("deviceId", SystemUtils.getShortClientID(CommonAppContext.getInstance()));
|
|
|
|
|
|
headers.put("appVersion", BuildConfig.VERSION_NAME + "." + BuildConfig.VERSION_CODE);
|
|
|
|
|
|
headers.put("versionName", BuildConfig.VERSION_NAME);
|
|
|
|
|
|
headers.put("versionCode", String.valueOf(BuildConfig.VERSION_CODE));
|
|
|
|
|
|
headers.put("system", "android");
|
|
|
|
|
|
headers.put("emulator", CommonAppContext.getInstance().emulator);
|
|
|
|
|
|
headers.put("deviceName", SystemUtils.getDeviceBrand() + SystemUtils.getSystemModel() + SystemUtils.getSystemVersion());
|
|
|
|
|
|
try {
|
|
|
|
|
|
String channelId = MetaDataUtils.getMetaDataInApp("TD_CHANNEL_ID");
|
|
|
|
|
|
headers.put("CHANNELID", channelId);
|
|
|
|
|
|
headers.put("appName", encodeHeadInfo(AppUtils.getAppName()));
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
return headers;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
private static String encodeHeadInfo(String headInfo) {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
|
|
for (int i = 0, length = headInfo.length(); i < length; i++) {
|
|
|
|
|
|
char c = headInfo.charAt(i);
|
|
|
|
|
|
if (c <= '\u001f' || c >= '\u007f') {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
stringBuffer.append(String.format("\\u%04x", (int) c));
|
2025-10-20 10:16:44 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
stringBuffer.append(c);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return stringBuffer.toString();
|
|
|
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
|
|
|
|
|
|
|
public static int getWidth(int value) {
|
|
|
|
|
|
// 获取屏幕宽度
|
|
|
|
|
|
int screenWidth = com.blankj.utilcode.util.ScreenUtils.getScreenWidth();
|
|
|
|
|
|
// 按照公式计算:value / 375 * screenWidth
|
|
|
|
|
|
return (int) ((value / 375.0) * screenWidth);
|
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|