package top.yvyan.guettable.service.fetch;
import static java.lang.Math.max;
import android.content.Context;
import android.content.res.Resources;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import top.yvyan.guettable.Http.Get;
import top.yvyan.guettable.Http.HttpConnectionAndCode;
import top.yvyan.guettable.Http.Post;
import top.yvyan.guettable.R;
import top.yvyan.guettable.util.AESUtil;
import top.yvyan.guettable.util.RegularUtil;
import top.yvyan.guettable.util.VPNUrlUtil;
public class Net {
/**
* 测试连接
*
* @return 200 -- 内网
* else -- 外网
*/
public static int testNet(Context context) {
Resources resources = context.getResources();
HttpConnectionAndCode drcomLogin = Get.get(
resources.getString(R.string.url_network_login),
null,
resources.getString(R.string.user_agent),
resources.getString(R.string.SSO_referer),
null,
null,
resources.getString(R.string.cookie_delimiter),
null,
null,
true,
200,
100,
null);
return drcomLogin.resp_code;
}
/**
* 获取CAS 登录令牌
*
* @param context context
* @param account 学号
* @param password 密码
* @param TGTToken CAS-TGT
* @param MFACookie 2FA二次验证Cookie
* @return CAS-TGT;
*/
public static HttpConnectionAndCode getCASToken(Context context, String account, String password, String captcha, String TGTToken, String MFACookie, String SessionCookie) {
StringBuilder cookie_builder = new StringBuilder();
String AuthCookie = (TGTToken!=null && TGTToken.isEmpty() ? "" : TGTToken + "; ") + (MFACookie!=null && MFACookie.isEmpty() ? "" : MFACookie + "; ") + (SessionCookie != null && SessionCookie.isEmpty() ? "" : SessionCookie + "; ");
AuthCookie = AuthCookie.substring(0, max(0, AuthCookie.length() - 2));
if(SessionCookie != null && !SessionCookie.isEmpty()) {
cookie_builder.append(SessionCookie+"; ");
}
try {
Resources resources = context.getResources();
HttpConnectionAndCode loginParams = Get.get(
resources.getString(R.string.url_Authserver),
null,
resources.getString(R.string.user_agent),
resources.getString(R.string.SSO_referer),
!AuthCookie.equals("") ? AuthCookie : null,
null,
resources.getString(R.string.cookie_delimiter),
null,
null,
false,
null,
10000,
null);
if (loginParams.code != 0) {
if (loginParams.code == -7) {
// 已登录或多因子登录验证失效
return new HttpConnectionAndCode(loginParams.c, 1, loginParams.content, loginParams.cookie, loginParams.resp_code);
}
return new HttpConnectionAndCode(-5);
}
if(!loginParams.cookie.isEmpty()) {
cookie_builder.append(loginParams.cookie+"; ");
}
ArrayList<String> listExp = RegularUtil.getAllSatisfyStr(loginParams.content, "(?<=id=\"pwdEncryptSalt\" value=\")(\\w+)(?=\")");
String AESKey = listExp.get(0);
listExp = RegularUtil.getAllSatisfyStr(loginParams.content, "(?<=name=\"execution\" value=\")(.*?)(?=\")");
String execution = listExp.get(0);
String body = "username=" + account + "&password=" + URLEncoder.encode(AESUtil.CASEncryption(password, AESKey), "UTF-8") + "&captcha=" + captcha + "&rememberMe=true&_eventId=submit&cllt=userNameLogin&dllt=generalLogin<=&execution=" + URLEncoder.encode(execution, "UTF-8");
HttpConnectionAndCode LoginRequest = Post.post(
resources.getString(R.string.url_Authserver),
null,
resources.getString(R.string.user_agent),
resources.getString(R.string.SSO_referer),
body,
cookie_builder + "; " + MFACookie,
"}",
resources.getString(R.string.cookie_delimiter),
null,
null,
false,
resources.getString(R.string.SSO_context_type));
if (LoginRequest.resp_code == 401) {
return new HttpConnectionAndCode(-8); //密码错误
}
if (LoginRequest.code == -7) {
List<String> cookies = LoginRequest.c.getHeaderFields().get("Set-Cookie");
if (cookies != null) {
for (String cookie_resp : cookies) {
cookie_builder.append(cookie_resp.substring(0, cookie_resp.indexOf(";") + 1)).append(" ");
}
}
LoginRequest.cookie = cookie_builder.substring(0, max(0, cookie_builder.length() - 2));
LoginRequest.code = 0;
return LoginRequest;
}
return LoginRequest;
} catch (Exception ignored) {
}
return new HttpConnectionAndCode(-5);
}
/**
* 获取手机验证码
*
* @param context context
* @param CASCookie CAS Cookie
* @param account account
* @return Response
*/
public static HttpConnectionAndCode reAuth_sendSMSCode(Context context, String account, String CASCookie) {
Resources resources = context.getResources();
return Post.post(
resources.getString(R.string.url_SendSMSCode),
null,
resources.getString(R.string.user_agent),
resources.getString(R.string.SSO_referer),
"userName=" + account + "&authCodeTypeName=reAuthDynamicCodeType",
CASCookie,
null,
resources.getString(R.string.cookie_delimiter),
null,
null,
false,
resources.getString(R.string.SSO_context_type));
}
/**
* 认证手机验证码
*
* @param context context
* @param CASCookie CAS Cookie
* @param OTP OTP
* @return Response
*/
public static HttpConnectionAndCode reAuth_SMSCode(Context context, String OTP, String CASCookie) {
Resources resources = context.getResources();
return Post.post(
resources.getString(R.string.url_ReAuth),
null,
resources.getString(R.string.user_agent),
resources.getString(R.string.SSO_referer),
"service=&reAuthType=3&isMultifactor=true&password=&dynamicCode=" + OTP + "&uuid=&answer1=&answer2=&otpCode=&skipTmpReAuth=true",
CASCookie,
null,
resources.getString(R.string.cookie_delimiter),
null,
null,
false,
resources.getString(R.string.SSO_context_type));
}
/**
* 使用 SSO 服务器认证服务
*
* @param service 要认证的服务
* @param CASCookie CAS Cookie
* @return Response
*/
public static HttpConnectionAndCode loginServerBySSO(Context context, String service, String CASCookie) {
Resources resources = context.getResources();
try {
return Get.get(
"https://cas.guet.edu.cn/authserver/login?service=" + URLEncoder.encode(service, "utf-8"),
null,
resources.getString(R.string.user_agent),
没有合适的资源?快使用搜索试试~ 我知道了~
Guet桂电课程表-课程考试资源
共285个文件
xml:120个
java:107个
png:44个
需积分: 1 0 下载量 200 浏览量
2024-11-14
06:02:48
上传
评论
收藏 1.41MB ZIP 举报
温馨提示
Guet桂电课程表-课程考试资源
资源推荐
资源详情
资源评论
收起资源包目录
Guet桂电课程表-课程考试资源 (285个子文件)
gradlew.bat 2KB
.gitignore 226B
.gitignore 6B
build.gradle 3KB
build.gradle 1KB
settings.gradle 45B
gradlew 5KB
gradle-wrapper.jar 53KB
Net.java 23KB
TokenData.java 20KB
StaticService.java 19KB
CommFunc.java 18KB
PersonalizedActivity.java 16KB
DayClassAdapter.java 16KB
CourseTableFragment.java 15KB
ClassDetailAdapter.java 14KB
GradesBean.java 14KB
DayClassFragment.java 13KB
WebViewActivity.java 12KB
PersonFragment.java 10KB
LoginActivity.java 10KB
CourseBean.java 10KB
AutoUpdate.java 9KB
AddCourseActivity.java 9KB
SetTermActivity.java 9KB
Get.java 9KB
GuetTableAppWidget.java 8KB
MainActivity.java 8KB
GradesAdapter.java 8KB
ExamBean.java 8KB
Post.java 8KB
LibAdapter.java 8KB
MoreFragment.java 7KB
SingleSettingData.java 7KB
GeneralData.java 7KB
ExamAdapter.java 7KB
Notification.java 7KB
DialogUtil.java 6KB
WidgetServiceFactory.java 6KB
GradesActivity.java 5KB
LaunchActivity.java 5KB
DetailActivity.java 5KB
BaseFuncActivity.java 5KB
ExamActivity.java 5KB
TimeUtil.java 5KB
ClassTableNew.java 5KB
ScheduleData.java 4KB
SettingActivity.java 4KB
AppUtil.java 4KB
FirstLoad.java 4KB
WidgetActivity.java 4KB
SelectedCourseAdapter.java 4KB
AboutActivity.java 4KB
LabTableNew.java 4KB
PlannedCoursesActivity.java 4KB
ExamScoreBean.java 4KB
BackgroundUtil.java 3KB
SelectedCourseActivity.java 3KB
ExamScoreNewAdapter.java 3KB
MoreUrlActivity.java 3KB
MoreData.java 3KB
CourseUtil.java 3KB
ExamScoreAdapter.java 3KB
CETBean.java 3KB
LibActivity.java 3KB
ExperimentScoreBean.java 2KB
WidgetService.java 2KB
ExamInfoNew.java 2KB
ExamScore.java 2KB
PlannedCourseAdapter.java 2KB
SelectedCourseBean.java 2KB
ProgramModel.java 2KB
MoreFunService.java 2KB
ApiResult.java 2KB
ExamScoreNewActivity.java 2KB
ResitBean.java 2KB
AccountData.java 2KB
VPNUrlUtil.java 2KB
PlannedCourseBean.java 2KB
DateBuildAdapter.java 2KB
AESUtil.java 2KB
SerializeUtil.java 2KB
MyOperator.java 2KB
TipInfo.java 1KB
SettingData.java 1KB
SSLUtils.java 1KB
TermBean.java 1KB
ExperimentScore.java 1KB
WidgetUtil.java 1KB
CET.java 1KB
UpdateApp.java 1KB
Semester.java 1KB
ClassList.java 993B
BaseData.java 960B
ExamScoreNew.java 949B
HttpConnectionAndCode.java 924B
ToastUtil.java 918B
RegularUtil.java 903B
SelectedCourse.java 695B
WebviewCookieData.java 686B
共 285 条
- 1
- 2
- 3
资源评论
xyq2024
- 粉丝: 2451
- 资源: 5460
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功