feat: 更新代码仓库全部修改
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled
This commit is contained in:
@@ -112,6 +112,7 @@ class HttpUtil {
|
||||
|
||||
// 添加语言请求头
|
||||
map["lang"] = KRLanguageUtils.getCurrentLanguageCode();
|
||||
map['Login-Type'] = 'device';
|
||||
|
||||
// 添加动态UserAgent头
|
||||
map["User-Agent"] = _kr_getUserAgent();
|
||||
@@ -152,7 +153,7 @@ class HttpUtil {
|
||||
var map = <String, dynamic>{};
|
||||
// 判断是否需要加密:根据站点配置的 enable_security 字段
|
||||
final shouldEncrypt = KRSiteConfigService().isDeviceSecurityEnabled();
|
||||
if (shouldEncrypt && path.contains("app")) {
|
||||
if (shouldEncrypt) {
|
||||
KRLogUtil.kr_i('🔐 需要加密请求数据', tag: 'HttpUtil');
|
||||
final plainText = jsonEncode(params);
|
||||
map = KRAesUtil.encryptData(plainText, AppConfig.kr_encryptionKey);
|
||||
@@ -162,9 +163,56 @@ class HttpUtil {
|
||||
|
||||
// 初始化请求头
|
||||
final headers = _initHeader('signature', 'userId', 'token');
|
||||
|
||||
int? _kr_parseUserIdFromToken(String token) {
|
||||
try {
|
||||
// JWT格式: header.payload.signature
|
||||
final parts = token.split('.');
|
||||
if (parts.length != 3) {
|
||||
KRLogUtil.kr_e('JWT token格式错误', tag: 'AppRunData');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 解码payload部分(base64)
|
||||
String payload = parts[1];
|
||||
// 手动添加必要的padding(base64要求长度是4的倍数)
|
||||
switch (payload.length % 4) {
|
||||
case 0:
|
||||
break; // 不需要padding
|
||||
case 2:
|
||||
payload += '==';
|
||||
break;
|
||||
case 3:
|
||||
payload += '=';
|
||||
break;
|
||||
default:
|
||||
KRLogUtil.kr_e('JWT payload长度无效', tag: 'AppRunData');
|
||||
return null;
|
||||
}
|
||||
|
||||
final decodedBytes = base64.decode(payload);
|
||||
final decodedString = utf8.decode(decodedBytes);
|
||||
|
||||
// 解析JSON
|
||||
final Map<String, dynamic> payloadMap = jsonDecode(decodedString);
|
||||
|
||||
// 获取UserId
|
||||
if (payloadMap.containsKey('UserId')) {
|
||||
final userId = payloadMap['UserId'];
|
||||
KRLogUtil.kr_i('从JWT解析出userId: $userId', tag: 'AppRunData');
|
||||
return userId is int ? userId : int.tryParse(userId.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
KRLogUtil.kr_e('解析JWT token失败: $e', tag: 'AppRunData');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
final userId = _kr_parseUserIdFromToken(KRAppRunData().kr_token.toString());
|
||||
// 调试:打印请求头
|
||||
KRLogUtil.kr_i('🔍 请求头: $headers', tag: 'HttpUtil');
|
||||
KRLogUtil.kr_i('🔍 请求userId: $userId', tag: 'HttpUtil');
|
||||
KRLogUtil.kr_i('🔍 请求头map: $map', tag: 'HttpUtil');
|
||||
|
||||
Response<Map<String, dynamic>> responseTemp;
|
||||
if (method == HttpMethod.GET) {
|
||||
@@ -365,7 +413,7 @@ class _KRSimpleHttpInterceptor extends Interceptor {
|
||||
nonce,
|
||||
AppConfig.kr_encryptionKey,
|
||||
);
|
||||
print('🔓 解密后的原始响应数据:');
|
||||
print('🔓 解密后的原始响应数据: ${response.requestOptions.uri}');
|
||||
// 尝试格式化 JSON
|
||||
try {
|
||||
final jsonData = jsonDecode(decrypted);
|
||||
@@ -395,4 +443,4 @@ class _KRSimpleHttpInterceptor extends Interceptor {
|
||||
}
|
||||
handler.next(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user