//抽取网络请求到api_service部分
static Future getRequest(String url, {ResponseType type = ResponseType.json}) async {
Dio dio = Dio();
Response response = await dio.get(url, options: Options(responseType: type));
return response;
}
//抽取获取验证码的方法
static Future getVerifyCode(context, setState) async {
print(_pureyzm.toString());
if (!_pureyzm) {
Response response = await ApiService.getRequest('https://nepuback-nepu-restart-xbbhhovrls.cn-beijing.fcapp.run/jwc_login', type: ResponseType.bytes);
print(response.headers.value('Set-Cookie').toString());
//如果分割后的字符串长度为32则为jessonid
for (var item in response.headers
.value('Set-Cookie')
.toString()
.replaceAll('{', '')
.replaceAll('}', '')
.replaceAll("'", '')
.replaceAll(' ', '')
.split(',')) {
if (item.length < 50 && item.length > 10) {
jwc_jsessionid = item;
}
if (item.length > 100) {
jwc_webvpn_key = item;
}
if (item.length > 50 && item.length < 100) {
jwc_webvpn_username = item;
}
if (item.length == 4) {
jwc_verifycode = item;
jwc_verifycodeController.text = item;
}
if (item.length == 5) {
setState(() {});
}
}
try {
await AchievementView(context,
title: '你可以无需验证码登录啦,验证码是',
subTitle: Global.jwc_verifycode,
icon: Icon(
Icons.error,
color: Colors.white,
),
color: Colors.green,
duration: Duration(seconds: 3),
isCircle: true,
listener: (status) {})
..show();
} catch (e) {
print(e);
}
return Image.memory(response.data);
} else {
return Image.asset('assets/jwc_login.jpg');
}
}
//抽取无感知登录的方法
Future No_perception_login() async {
Response response = await ApiService.getRequest('https://nepuback-nepu-restart-xbbhhovrls.cn-beijing.fcapp.run/jwc_login', type: ResponseType.bytes);
//如果分割后的字符串长度为32则为jessonid
for (var item in response.headers
.value('Set-Cookie')
.toString()
.replaceAll('{', '')
.replaceAll('}', '')
.replaceAll("'", '')
.replaceAll(' ', '')
.split(',')) {
if (item.length < 50 && item.length > 10) {
jwc_jsessionid = item;
}
if (item.length > 100) {
jwc_webvpn_key = item;
}
if (item.length > 50 && item.length < 100) {
jwc_webvpn_username = item;
}
if (item.length == 4) {
jwc_verifycode = item;
}
if (item.length == 5) {
No_perception_login();
}
}
Response response1 = await ApiService.getRequest('https://nepu-node-login-nepu-restart-togqejjknk.cn-beijing.fcapp.run/course', queryParameters: {
'account': Global.jwc_xuehao,
'password': Global.jwc_password,
'verifycode': Global.jwc_verifycode,
'JSESSIONID': Global.jwc_jsessionid,
'_webvpn_key': Global.jwc_webvpn_key,
'webvpn_username': Global.jwc_webvpn_username
});
if (response1.data['message'].toString() == '登录成功') {
print('无感登陆成功了');
print(await Global().getLoginInfo());
}
}