-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 37a3f5d
Showing
18 changed files
with
745 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
/src/main/resources/config.properties | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Navicat MySQL Data Transfer | ||
Target Server Type : MYSQL | ||
Target Server Version : 50630 | ||
File Encoding : 65001 | ||
Date: 2017-01-12 15:51:28 | ||
*/ | ||
|
||
SET FOREIGN_KEY_CHECKS=0; | ||
|
||
-- ---------------------------- | ||
-- Table structure for user | ||
-- ---------------------------- | ||
DROP TABLE IF EXISTS `user`; | ||
CREATE TABLE `user` ( | ||
`id` int(255) NOT NULL AUTO_INCREMENT, | ||
`username` varchar(255) NOT NULL, | ||
`password` varchar(255) NOT NULL, | ||
`tel` varchar(255) NOT NULL DEFAULT '', | ||
`subject_id` varchar(255) NOT NULL DEFAULT '', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; | ||
SET FOREIGN_KEY_CHECKS=1; |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>cn.zheteng123.hdu</groupId> | ||
<artifactId>score-push</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.squareup.okhttp3</groupId> | ||
<artifactId>okhttp</artifactId> | ||
<version>3.5.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.squareup.okio</groupId> | ||
<artifactId>okio</artifactId> | ||
<version>1.11.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jsoup</groupId> | ||
<artifactId>jsoup</artifactId> | ||
<version>1.8.3</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.38</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.0.2</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cn.zheteng123.hdu.dao; | ||
|
||
import cn.zheteng123.hdu.pojo.User; | ||
import cn.zheteng123.hdu.util.JdbcUtil; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created on 2017/1/11. | ||
*/ | ||
public class UserDao { | ||
|
||
/** | ||
* 查询所有用户信息 | ||
* @return 用户信息列表 | ||
*/ | ||
public List<User> selectUserAll() { | ||
List<User> userList = new ArrayList<User>(); | ||
try { | ||
Connection conn = JdbcUtil.getConnection(); | ||
PreparedStatement stmt = conn.prepareStatement("SELECT id, username, password, num_of_score, tel, subject_id FROM user"); | ||
ResultSet result = stmt.executeQuery(); | ||
while (result.next()) { | ||
User user = new User(); | ||
user.setId(result.getInt("id")); | ||
user.setUsername(result.getString("username")); | ||
user.setPassword(result.getString("password")); | ||
user.setNumOfScore(result.getInt("num_of_score")); | ||
user.setTel(result.getString("tel")); | ||
user.setSubjectId(result.getString("subject_id")); | ||
userList.add(user); | ||
} | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
return userList; | ||
} | ||
|
||
/** | ||
* 更新指定用户的 num_of_score | ||
* @param id 用户id | ||
* @param numOfScore 上一次查询时的成绩数 | ||
* @return 更新记录的条数 | ||
*/ | ||
public int updateNumOfScoreById(int id, int numOfScore) { | ||
try { | ||
Connection conn = JdbcUtil.getConnection(); | ||
PreparedStatement stmt = conn.prepareStatement("UPDATE user SET num_of_score = ? WHERE id=?"); | ||
stmt.setInt(1, id); | ||
return stmt.executeUpdate(); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
return -1; | ||
} | ||
|
||
public int updateSubjectIdById(int id, String subjectId) { | ||
Connection connection = null; | ||
PreparedStatement statement = null; | ||
try { | ||
connection = JdbcUtil.getConnection(); | ||
statement = connection.prepareStatement("UPDATE user SET subject_id = ? WHERE id=?"); | ||
statement.setString(1, subjectId); | ||
statement.setInt(2, id); | ||
return statement.executeUpdate(); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
JdbcUtil.close(null, statement, connection); | ||
} | ||
return -1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cn.zheteng123.hdu.main; | ||
|
||
|
||
import cn.zheteng123.hdu.dao.UserDao; | ||
import cn.zheteng123.hdu.network.Network; | ||
import cn.zheteng123.hdu.pojo.Score; | ||
import cn.zheteng123.hdu.pojo.User; | ||
import cn.zheteng123.hdu.util.MyStringUtil; | ||
import cn.zheteng123.hdu.util.SMSUtil; | ||
import com.taobao.api.ApiException; | ||
import com.taobao.api.DefaultTaobaoClient; | ||
import com.taobao.api.TaobaoClient; | ||
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest; | ||
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
|
||
|
||
/** | ||
* Created on 2016/6/20. | ||
*/ | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
|
||
while (true) { | ||
try { | ||
Thread.sleep(10000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
UserDao userDao = new UserDao(); | ||
List<User> userList = userDao.selectUserAll(); | ||
List<Score> scoreList = null; | ||
for (User user : userList) { | ||
System.out.println("开始查询" + user.getUsername() + "的成绩……"); | ||
|
||
try { | ||
scoreList = Network.getScore(user.getUsername(), user.getPassword()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
if (scoreList != null) { | ||
List<Score> pushScores = MyStringUtil.getNewScore(scoreList, user.getSubjectId()); | ||
|
||
// 推送成绩 | ||
String subjectId = user.getSubjectId(); | ||
for (Score pushScore : pushScores) { | ||
boolean result = SMSUtil.sendSMS(pushScore.getName(), pushScore.getScore(), user.getTel()); | ||
if (!result) { | ||
// TODO: 2017/1/12 以后补上 | ||
} else { | ||
subjectId += pushScore.getSubjectId() + ","; | ||
userDao.updateSubjectIdById(user.getId(), subjectId); | ||
} | ||
} | ||
} | ||
|
||
System.out.println(user.getUsername() + "的成绩推送完毕……"); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package cn.zheteng123.hdu.network; | ||
|
||
import cn.zheteng123.hdu.pojo.Score; | ||
import cn.zheteng123.hdu.util.MyCookieJar; | ||
import com.zhy.http.okhttp.OkHttpUtils; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Response; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Created on 2017/1/11. | ||
*/ | ||
public class Network { | ||
|
||
/** | ||
* 根据用户名密码查询成绩信息 | ||
* @param username 用户名(学号) | ||
* @param password 密码(经过 MD5 加密) | ||
* @return 成绩列表 | ||
*/ | ||
public static List<Score> getScore(String username, String password) throws IOException { | ||
|
||
// 实例化 client,注意实现 cookie 自动管理 | ||
OkHttpClient client = new OkHttpClient | ||
.Builder() | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.cookieJar(new MyCookieJar()) | ||
.build(); | ||
OkHttpUtils.initClient(client); | ||
|
||
|
||
// 登录教务系统 | ||
String dataPostLogin; | ||
|
||
// 清除 cookie | ||
Response resGetLogout = OkHttpUtils.get() | ||
.url("http://jxgl.hdu.edu.cn/logout0.aspx") | ||
.addHeader("Referer", "http://jxgl.hdu.edu.cn/xs_main.aspx?xh=" + username) | ||
.build() | ||
.execute(); | ||
resGetLogout.close(); | ||
|
||
Response resGetLogout2 = OkHttpUtils.get() | ||
.url("http://i.hdu.edu.cn/dcp/logout0.jsp") | ||
.addHeader("Referer", "http://jxgl.hdu.edu.cn/logout0.aspx") | ||
.build() | ||
.execute(); | ||
resGetLogout2.close(); | ||
|
||
|
||
|
||
// Get 访问登录页,获取隐藏表单项 lt | ||
Response resGetLt = OkHttpUtils.get() | ||
.url("http://jxgl.hdu.edu.cn/") | ||
.build() | ||
.execute(); | ||
String dataLt = resGetLt.body().string(); | ||
Document docLt = Jsoup.parse(dataLt); | ||
String lt = docLt.select("input[name=lt]").val(); | ||
System.out.println(lt); | ||
resGetLt.close(); | ||
|
||
|
||
// Post 登录教务系统 | ||
Response resPostLogin = OkHttpUtils.post() | ||
.url("http://cas.hdu.edu.cn/cas/login") | ||
.addParams("username", username) | ||
.addParams("password", password) | ||
.addParams("lt", lt) | ||
.build() | ||
.execute(); | ||
dataPostLogin = resPostLogin.body().string(); | ||
if (dataPostLogin.contains("账号或密码错误")) { | ||
System.out.println("账号或密码错误!"); | ||
return null; | ||
} | ||
resPostLogin.close(); | ||
|
||
|
||
// 进入选课系统 | ||
Response resGetEduAdmin = OkHttpUtils.get() | ||
.url("http://i.hdu.edu.cn/dcp/forward.action?path=dcp/apps/sso/jsp/ssoDcpSelf&appid=1142") | ||
.build() | ||
.execute(); | ||
String dataTemp = resGetEduAdmin.body().string(); | ||
resGetEduAdmin.close(); | ||
// System.out.println(dataTemp); | ||
while (dataTemp.contains("认证转向")) { | ||
Document docUrlJump = Jsoup.parse(dataTemp); | ||
String urlJump = docUrlJump.select("a").get(0).attr("href"); | ||
Response resTemp = OkHttpUtils.get() | ||
.url(urlJump) | ||
.build() | ||
.execute(); | ||
dataTemp = resTemp.body().string(); | ||
resTemp.close(); | ||
} | ||
// System.out.println(dataTemp); | ||
|
||
|
||
// 获取成绩 | ||
System.out.println("获取成绩"); | ||
Response resGetScore = OkHttpUtils.get() | ||
.url("http://jxgl.hdu.edu.cn/xscjcx_dq.aspx?xh=" + username) | ||
.addHeader("Referer", "http://jxgl.hdu.edu.cn/xscjcx_dq.aspx?xh=" + username) | ||
.build() | ||
.execute(); | ||
String dataScore = resGetScore.body().string(); | ||
resGetScore.close(); | ||
Document docScore = Jsoup.parse(dataScore); | ||
Elements trs = docScore.select("#DataGrid1 tr"); | ||
// System.out.println(trs.size()); | ||
trs.remove(0); // 删去表格的第一行表头 | ||
List<Score> scoreList = new ArrayList<Score>(); | ||
for (Element tr : trs) { | ||
Elements tds = tr.select("td"); | ||
Score score = new Score(tds.get(3).text(), tds.get(7).text(), tds.get(2).text()); | ||
scoreList.add(score); | ||
} | ||
|
||
return scoreList; | ||
} | ||
} |
Oops, something went wrong.