Skip to content

Commit

Permalink
[fea] 增加了UA的内容 更加拟真
Browse files Browse the repository at this point in the history
  • Loading branch information
steven12138 committed May 8, 2024
1 parent 37c3e6b commit 9c8db13
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:we_pei_yang_flutter/auth/model/banner_pic.dart';
import 'package:we_pei_yang_flutter/commons/network/cas_service.dart';
import 'package:we_pei_yang_flutter/commons/network/wpy_dio.dart';
import 'package:we_pei_yang_flutter/commons/util/logger.dart';

Expand Down Expand Up @@ -40,4 +41,15 @@ class SplashService with AsyncTimer {
return [];
}
}

static Future<KeyPair?> getKeyPair() async {
try {
var response = await splashDio.get("keypair");
var result = response.data['result'];
return KeyPair.fromJson(result);
} catch (e, stack) {
Logger.reportError(e, stack);
return null;
}
}
}
51 changes: 51 additions & 0 deletions lib/commons/network/cas_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:typed_data';

import 'package:convert/convert.dart';
import 'package:pointycastle/export.dart';
import 'package:we_pei_yang_flutter/auth/network/splash_service.dart';
import 'package:we_pei_yang_flutter/commons/network/wpy_dio.dart';
import 'package:xml/xml.dart';

Expand Down Expand Up @@ -40,14 +41,63 @@ class DesService {
}
}

class KeyPair {
CasService({
String? key,
String? iv,
}) {
_key = key;
_iv = iv;
}

KeyPair.fromJson(dynamic json) {
_key = json['key'];
_iv = json['iv'];
}

String? _key;
String? _iv;

KeyPair copyWith({
String? key,
String? iv,
}) =>
CasService(
key: key ?? _key,
iv: iv ?? _iv,
);

String? get key => _key;

String? get iv => _iv;

Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['key'] = _key;
map['iv'] = _iv;
return map;
}
}

class EncryptedPathInterceptor extends InterceptorsWrapper {
static final headerMap = {
"Content-Type": "application/json;charset=UTF-8",
"Accept": "application/json;charset=UTF-8",
"Host": "f.tju.edu.cn",
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip",
"User-Agent": "okhttp/3.12.0",
};

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
options.headers["User-Agent"] =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3";
final source_string = "method=${options.path}"
"&${options.queryParameters.entries.map((e) => "${e.key}=${e.value}").join("&")}";

options.headers.addAll(headerMap);

options.path = getEncryptedString(source_string);
options.queryParameters = {};
print("encrypted_path: ${options.path}");
Expand Down Expand Up @@ -110,4 +160,5 @@ class CasService {
);
return response.data["message"];
}

}
2 changes: 1 addition & 1 deletion lib/home/view/dialogs/activity_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:we_pei_yang_flutter/auth/model/banner_pic.dart';
import 'package:we_pei_yang_flutter/auth/network/theme_service.dart';
import 'package:we_pei_yang_flutter/auth/network/splash_service.dart';
import 'package:we_pei_yang_flutter/commons/preferences/common_prefs.dart';
import 'package:we_pei_yang_flutter/commons/themes/template/wpy_theme_data.dart';
import 'package:we_pei_yang_flutter/commons/themes/wpy_theme.dart';
Expand Down

0 comments on commit 9c8db13

Please sign in to comment.