Android登录学校正方教务处--CSDN第一次发帖

2023-10-24 16:10

本文主要是介绍Android登录学校正方教务处--CSDN第一次发帖,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近想写一个仅供学校学生使用的福利app,登录验证方式就想到了学校教务系统的验证,没有和老师有任何的沟通,也没有私有接口

======================================================================================================

先说环境吧,燕山大学教务处 http://jwc.ysu.edu.cn/  开发环境为Eclipse+ADT22.3,HAXM加速的Android2.3模拟器

再说软件吧,Firefox + Live Http Header扩展

最后就是测试账号吧,咳咳,是楼主的

=====================================================================================================

demo已共享到github  https://github.com/hailian/ysujwc

======================================================================================================

点击登录到教务系统

然后就跳转,地址栏就变成如下


括号中间的字符串随机出线。。。。

一、得到这些随机字符

打开Firefox,回到http://jwc.ysu.edu.cn/,等待载入完成后,打开Live HTTP headers;

再点击登录镜像系统,把Live HTTP headers滚动条拖到最上面,看到如图选中的,即为地址


下面就是获取这些地址;

try {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://jwc.ysu.edu.cn/zjdxgc/default2.aspx");
//
//
HttpResponse response = client.execute(httpGet);
int responseCode = response.getStatusLine().getStatusCode();
Log.e("responseCode--", "" + responseCode);
//
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
Log.d("header",
header.getName() + ": " + header.getValue());
}
} catch (Exception e) {
e.printStackTrace();
}
}

实验发现GET方式过去,responseCode是200,并不是上图的302,自然得不到Location;

原来是自动重定向,以上代码改为

try {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"http://jwc.ysu.edu.cn/zjdxgc/default2.aspx");
//
//
HttpParams params = new BasicHttpParams();
params.setParameter("http.protocol.handle-redirects", false);
httpGet.setParams(params);
//
HttpResponse response = client.execute(httpGet);
int responseCode = response.getStatusLine().getStatusCode();
Log.e("responseCode--", "" + responseCode);
//
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
Log.d("header",
header.getName() + ": " + header.getValue());
}


if (responseCode == 302) {
Header locationHeader = response
.getFirstHeader("Location");
if (locationHeader != null) {
url_location = "http://jwc.ysu.edu.cn"
+ locationHeader.getValue();
Log.i("url_location---", url_location);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

这样就获得了地址




二、获取Post键值对,和验证码

再验证码输入0000,再次打开Live HTTP headers ,然后点击网页上登录,弹出验证码不正确;


切换到HTTP headers 页面,拖到最上,点击Replay... 


其中txtUserName为学号,TextBox2为密码,txtSecretCode为验证码,这是显而易见的;

但是__VIEWSTATE和RadioButtonList1是什么意思,还有转码。。。

想了想,我认为RadioButtonList1的转码是输入验证码时,其下面的“学生”,后来证明了我的想法;

但是这个__VIEWSTATE是不是与ip有关呢?我去隔壁宿舍登了一下,证明无关,那我就写死吧。。

后来证明错了。。__VIEWSTATE是一个与时间有关的字符串。


查看网页源代码,发现第78行有这个字符串



想到了读取输入流,转换成字符串再解析,但由于上一个是禁止自动重定向,这次新建一个;解析是用String.split()方法

try {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"http://jwc.ysu.edu.cn/zjdxgc/default2.aspx");
//
HttpGet httpGet2 = new HttpGet(
"http://jwc.ysu.edu.cn/zjdxgc/default2.aspx");
//
//
HttpParams params = new BasicHttpParams();
params.setParameter(
"http.protocol.handle-redirects", false);
httpGet.setParams(params);
//
HttpResponse response = client.execute(httpGet);
HttpResponse response2 = client.execute(httpGet2);
int responseCode = response.getStatusLine()
.getStatusCode();
int responseCode2 = response2.getStatusLine()
.getStatusCode();
Log.e("responseCode--", "" + responseCode);
Log.e("responseCode2--", "" + responseCode2);
//
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
Log.d("header", header.getName() + ": "
+ header.getValue());
}


if (responseCode == 302 && responseCode2 == 200) {
String[] html = EntityUtils.toString(
response2.getEntity()).split("\n");
String[] inCodeStr = html[77].split("\"");
String key = inCodeStr[5];
Log.i("", key);
Header locationHeader = response
.getFirstHeader("Location");
if (locationHeader != null) {
String location = "http://jwc.ysu.edu.cn"
+ locationHeader.getValue();
Log.i("url_location---", location);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

然后log显示的为

验证码,就简单的用GET流生成Bitmap

HttpURLConnection h;
try {
h = (HttpURLConnection) new URL(url_yzm).openConnection();
h.setReadTimeout(5000);
h.setDoInput(true);
h.connect();
Bitmap bm = BitmapFactory.decodeStream(h.getInputStream());
//
h.getInputStream().close();
// img_yzm.setImageBitmap(bm);
Message msg = new Message();
msg.what = HANDLER_IMG_SUCCEED;
msg.obj = bm;
handler.sendMessage(msg);
Log.i("yzm---", "yzm success");
} catch (MalformedURLException e) {
Log.e("MalformedURLException", e.toString());
Log.i("yzm---", "yzm fail1");
} catch (IOException e) {
Log.e("MalformedURLException", e.toString());
Log.i("yzm---", "yzm fail2");
}

三、post吧

直接上代码

try {
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("__VIEWSTATE", key));
// "dDwyODE2NTM0OTg7Oz6EIvBWZGpFetygfIX+qirD5BTcnA=="));
// params.add(new BasicNameValuePair("__VIEWSTATE",
// "dDwyODE2NTM0OTg7Oz7vFIof%2Bc6rGXD5W9puRFp5VKKG%2FQ%3D%"));
params.add(new BasicNameValuePair("txtUserName", ed_id
.getText().toString()));
params.add(new BasicNameValuePair("TextBox2", ed_pwd
.getText().toString()));
params.add(new BasicNameValuePair("txtSecretCode",
ed_yzm.getText().toString()));
params.add(new BasicNameValuePair("RadioButtonList1",
"学生"));
// params.add(new BasicNameValuePair("RadioButtonList1",
// "%D1%A7%C9%FA"));
params.add(new BasicNameValuePair("Button1", ""));
params.add(new BasicNameValuePair("lbLanguage", ""));
params.add(new BasicNameValuePair("hidPdrs", ""));
params.add(new BasicNameValuePair("hidsc", ""));
//


httpPost.setEntity(new UrlEncodedFormEntity(params,
HTTP.ISO_8859_1));


HttpResponse response = client.execute(httpPost);
int responseCode = response.getStatusLine()
.getStatusCode();
Log.e("responseCode--", "" + responseCode);
//
if (responseCode == 200) {
String[] result = EntityUtils.toString(
response.getEntity()).split("\n");
String loginState = result[4].substring(9,
result[4].length() - 9);
Log.d(TAG, loginState);
if (loginState.equals("正方教务管理系统")) {
Log.v("loginState--", loginState);
Log.v("namelist--88", result[88]);
Log.v("namelist--89", result[89]);
Log.v("namelist--90", result[90]);
Log.v("namelist--91", result[91]);
Log.v("namelist--92", result[92]);
String[] namelist = result[88].split("<");
String[] names = namelist[1].split(">");
String name = names[1];
Log.i(TAG, name);

} else {
Log.e(TAG, "login fail");
Message msg = new Message();
msg.what = HANDLER_LOGIN_FAIL;
handler.sendMessage(msg);
}


}


} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

图片



这篇关于Android登录学校正方教务处--CSDN第一次发帖的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/276319

相关文章

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

Spring Security 单点登录与自动登录机制的实现原理

《SpringSecurity单点登录与自动登录机制的实现原理》本文探讨SpringSecurity实现单点登录(SSO)与自动登录机制,涵盖JWT跨系统认证、RememberMe持久化Token... 目录一、核心概念解析1.1 单点登录(SSO)1.2 自动登录(Remember Me)二、代码分析三、

Ubuntu 24.04启用root图形登录的操作流程

《Ubuntu24.04启用root图形登录的操作流程》Ubuntu默认禁用root账户的图形与SSH登录,这是为了安全,但在某些场景你可能需要直接用root登录GNOME桌面,本文以Ubuntu2... 目录一、前言二、准备工作三、设置 root 密码四、启用图形界面 root 登录1. 修改 GDM 配

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

Android ClassLoader加载机制详解

《AndroidClassLoader加载机制详解》Android的ClassLoader负责加载.dex文件,基于双亲委派模型,支持热修复和插件化,需注意类冲突、内存泄漏和兼容性问题,本文给大家介... 目录一、ClassLoader概述1.1 类加载的基本概念1.2 android与Java Class

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

Android DataBinding 与 MVVM使用详解

《AndroidDataBinding与MVVM使用详解》本文介绍AndroidDataBinding库,其通过绑定UI组件与数据源实现自动更新,支持双向绑定和逻辑运算,减少模板代码,结合MV... 目录一、DataBinding 核心概念二、配置与基础使用1. 启用 DataBinding 2. 基础布局

Android ViewBinding使用流程

《AndroidViewBinding使用流程》AndroidViewBinding是Jetpack组件,替代findViewById,提供类型安全、空安全和编译时检查,代码简洁且性能优化,相比Da... 目录一、核心概念二、ViewBinding优点三、使用流程1. 启用 ViewBinding (模块级

Java中的登录技术保姆级详细教程

《Java中的登录技术保姆级详细教程》:本文主要介绍Java中登录技术保姆级详细教程的相关资料,在Java中我们可以使用各种技术和框架来实现这些功能,文中通过代码介绍的非常详细,需要的朋友可以参考... 目录1.登录思路2.登录标记1.会话技术2.会话跟踪1.Cookie技术2.Session技术3.令牌技