帮我把下面的代码抽取出公共部分并且把网络请求抽取到api_service部分使用Dio插件获取验证码图片并返回图片 static FutureWidget getVerifyCodecontext setState async print_pureyzmtoString; if !_pureyzm Dio dio = Dio; print下载了; R
//api_service.dart class ApiService { static Dio dio = Dio();
static Future
static Future
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) {
await noPerceptionLogin();
}
}
Response response1 = await dio.get(
"https://nepu-node-login-nepu-restart-togqejjknk.cn-beijing.fcapp.run/course",
options: Options(),
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
});
return response1;
} }
//原始代码中的部分
static Future
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
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) { await ApiService.noPerceptionLogin(); } }
原文地址: https://www.cveoy.top/t/topic/fD2F 著作权归作者所有。请勿转载和采集!